org.zkoss.util.resource
Class ClassLocator

java.lang.Object
  extended by org.zkoss.util.resource.ClassLocator
All Implemented Interfaces:
Locator, XMLResourcesLocator

public class ClassLocator
extends java.lang.Object
implements XMLResourcesLocator

The locator searches the current thread's context class loader, and then this class's class loader.

It is important to use this locator if you want to load something in other jar files.

Since this locator is used frequently, Locators.getDefault() is provided to return an instance of this class,

Author:
tomyeh

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.zkoss.util.resource.XMLResourcesLocator
XMLResourcesLocator.Resource
 
Constructor Summary
ClassLocator()
           
 
Method Summary
 boolean equals(java.lang.Object o)
           
 java.util.List<XMLResourcesLocator.Resource> getDependentXMLResources(java.lang.String name, java.lang.String elName, java.lang.String elDepends)
          Returns a list of resources (XMLResourcesLocator.Resource) after resolving the dependence.
 java.lang.String getDirectory()
          Always returns null.
 java.net.URL getResource(java.lang.String name)
          Finds the resource with the given name.
 java.io.InputStream getResourceAsStream(java.lang.String name)
          Returns an input stream for reading the specified resource.
 java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
          Returns an enumeration of resources.
 int hashCode()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ClassLocator

public ClassLocator()
Method Detail

getResources

public java.util.Enumeration<java.net.URL> getResources(java.lang.String name)
                                                 throws java.io.IOException
Description copied from interface: XMLResourcesLocator
Returns an enumeration of resources. Unlike XMLResourcesLocator.getDependentXMLResources(java.lang.String, java.lang.String, java.lang.String), it doesn't resolve the dependence among the resouces.

Specified by:
getResources in interface XMLResourcesLocator
Parameters:
name - the resouce name, such as "metainfo/config.xml".
Throws:
java.io.IOException

getDependentXMLResources

public java.util.List<XMLResourcesLocator.Resource> getDependentXMLResources(java.lang.String name,
                                                                             java.lang.String elName,
                                                                             java.lang.String elDepends)
                                                                      throws java.io.IOException
Description copied from interface: XMLResourcesLocator
Returns a list of resources (XMLResourcesLocator.Resource) after resolving the dependence. The resource is returned in the format of XMLResourcesLocator.Resource

To resolve the dependence, it assumes each resource has two element whose name is identified by elName and elDepends. The elName element specifies the unique name of each resource. The elDepends element specifies a list of names of resources that this resource depends on. If not found, it assumes it could be loaded first.

Specified by:
getDependentXMLResources in interface XMLResourcesLocator
Parameters:
name - the resouce name, such as "metainfo/config.xml".
elName - the element used to specify the name.
elDepends - the element used to specify the dependence.
Returns:
a list of XMLResourcesLocator.Resource of the specified name.
Throws:
java.io.IOException

getDirectory

public java.lang.String getDirectory()
Always returns null.

Specified by:
getDirectory in interface Locator

getResource

public java.net.URL getResource(java.lang.String name)
Description copied from interface: Locator
Finds the resource with the given name. A resource is some data (images, audio, text, etc) that can be accessed by class code in a way that is independent of the location of the code.

Specified by:
getResource in interface Locator
Returns:
a URL for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource

getResourceAsStream

public java.io.InputStream getResourceAsStream(java.lang.String name)
Description copied from interface: Locator
Returns an input stream for reading the specified resource.

Specified by:
getResourceAsStream in interface Locator
Returns:
an input stream for reading the resource, or null if the resource could not be found or the caller doesn't have adequate privileges to get the resource

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo