Agent System POND 1.2 (28.2.2002)

PkgAgentSystem
Class ResourcePackage

java.lang.Object
  |
  +--PkgAgentSystem.ResourcePackage

class ResourcePackage
extends Object

Used to find resources on a searchpath. Each classloader (and therefore each agent) has its own resource package.
The searchpath consists of a number of files or directories separated by a semicolon. Files must be either directly a resource or a jar- or zip-file (which will be searched). Directories are searched for the resource directly (if the resource is contained in a package, all '.' are replaced by '/' or '\' to reach the correct subdirectory). Also in directories all contained zip- and jar-files are searched for the resource.

Version:
1.0, 1.7.2000
Author:
Michael Sonntag
See Also:
AgentClassLoader

Field Summary
protected  String codeOrigin
          From where the code is loaded.
 
Constructor Summary
ResourcePackage(AgentData data)
          Creates a new resource package for a certain agent.
 
Method Summary
protected  void EnumerateJarFile(Hashtable res, String file, String name)
          Searches a JAR-file for all resource with a specific name.
 CertificateWrapper[] getCodeCertificates()
          Returns all code certificates which were used to sign this package.
protected  URL getFromPackedFile(String file, String name)
          Searches a JAR- or ZIP-file for a specific resource and loads it.
 Manifest getManifest()
          Returns the manifest for this code package.
 byte[] getManifestSource()
          Returns the original bytes of the manifest for this code package.
 String getPackage()
          Returns the name of a file, where the code for this resource package can be found.
 Enumeration getResources(String name)
          Returns an enumeration of all LOCAL resource with this name from the codeOrigin of this object.
 URL getResourceURL(String name)
          Returns an URL to the resource with the provided name.
protected  String getSearchPath()
          Returns the complete searchpath.
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

codeOrigin

protected String codeOrigin
From where the code is loaded. Duplicate of data.codeOrigin
Constructor Detail

ResourcePackage

public ResourcePackage(AgentData data)
Creates a new resource package for a certain agent.
Parameters:
data - the management data of the agent for which to load classes
Method Detail

getSearchPath

protected String getSearchPath()
Returns the complete searchpath. Searching will be done from the front to the back, so previous entries will be used if a resource with the same name appears again behind.
Construction: Classpath ; library path of the agent system ; and either the code origin (directory or file) or, if this is not set, the agent classpath (from where agents are loaded)
Returns:
string of directories and files separated by ';'

getResourceURL

public URL getResourceURL(String name)
Returns an URL to the resource with the provided name. Searches only the searchpath.
Returns:
an URL to the resource
See Also:
getSearchPath(), URL.openStream(), URL.openConnection(), URLConnection

getResources

public Enumeration getResources(String name)
Returns an enumeration of all LOCAL resource with this name from the codeOrigin of this object. When Searching for test.gif, 'img/test.gif' will be included, but not 'mytest.gif'.
Parameters:
name - the name of the resources
Returns:
an enumeration of all resources with this name

getManifest

public Manifest getManifest()
Returns the manifest for this code package.
Returns:
the manifest or null if not contained or not applicable (zip, directory)

getManifestSource

public byte[] getManifestSource()
Returns the original bytes of the manifest for this code package.
Returns:
the manifest bytes or null if not contained or not applicable (zip, directory)

getCodeCertificates

public CertificateWrapper[] getCodeCertificates()
Returns all code certificates which were used to sign this package. Only those will be returned, where the verification was always successful and which were used for signing ALL files in the package.
Returns:
array or certificates (not ordered)

getPackage

public String getPackage()
Returns the name of a file, where the code for this resource package can be found. If the source is not a jar or zip-file itself but a directory, the content of this directory (including subdirectories) is packed into a temporary file and the name of this file returned.
Returns:
name of the file with the complete code (and possibly other resources) for this resource package

getFromPackedFile

protected URL getFromPackedFile(String file,
                                String name)
Searches a JAR- or ZIP-file for a specific resource and loads it. Any errors will be ignored: The resource will not be created then. When Searching for test.gif, 'img/test.gif' will be included but not 'mytest.gif'.
Parameters:
file - filename to search (must be a JAR- or ZIP-file; will not be checked)
name - the name of the resource to find

EnumerateJarFile

protected void EnumerateJarFile(Hashtable res,
                                String file,
                                String name)
Searches a JAR-file for all resource with a specific name. Any errors will be ignored: The resource will not be listed. When Searching for test.gif, 'img/test.gif' will be included but not 'mytest.gif'.
Parameters:
res - Hashtable where the found resource will be stored (URL with URL as key)
file - filename to search (must be a JAR-file; will not be checked)
name - the name of the resource to find

Agent System POND 1.2 (28.2.2002)

Submit a bug

Copyright 2001,2002 Michael Sonntag & Institute for Information Processing and Microprocessor Technology (FIM), Johannes-Kepler-University Linz, Altenbergerstr. 69, A-4040 Linz, Austria.