Rio Project 4.2 API Documentation



org.rioproject.core
Class ClassBundle

java.lang.Object
  extended by org.rioproject.core.ClassBundle
All Implemented Interfaces:
Serializable

public class ClassBundle
extends Object
implements Serializable

ClassBundle provides a mechanism to define the resources needed to load and instantiate a class.

Author:
Dennis Reedy
See Also:
Serialized Form

Constructor Summary
ClassBundle()
          Create a new ClassBundle
ClassBundle(String className)
          Create a new ClassBundle
ClassBundle(String className, String[] jarNames, Map<String,String[]> shComponents, String codebase)
          Create a new ClassBundle
 
Method Summary
 void addJAR(String jar)
          Add a JAR to the Collection of JAR resources.
 void addJARs(String... jars)
          Add JARs to the ClassBundle.
 void addMethod(String methodName, Object[] parameters)
          Add a method name and the parameters to use for when reflecting on specified public member method of the class or interface represented by this ClassBundle object.
 void addSharedComponents(Map<String,String[]> m)
          Add a Map of shared components
 boolean equals(Object obj)
          Override equals
 String getArtifact()
          Get the artifact associated with the className
 String getClassName()
          Get the className
 String getCodebase()
          Get the codebase used to load the class.
 String[] getJARNames()
          Get the JAR names.
 URL[] getJARs()
          Get the JAR resources
 Class[] getMethodClasses(String methodName)
          Get the corresponding Class[] parameters to reflect on a method
 String[] getMethodNames()
          Get all method names to reflect on
 Object[] getMethodObjects(String methodName)
          Get the corresponding Class[] parameters to reflect on a method
 String getRawCodebase()
          Get the codebase without any translation
 Map<String,String[]> getRawSharedComponents()
          Get raw shared component information
 Map<String,URL[]> getSharedComponents()
          Get shared component information
 int hashCode()
          Override hashCode
 Class loadClass()
          Load the class using the provided JAR resources.
 Class loadClass(ClassLoader parent)
          Load the class using the provided JAR resources.
static ClassBundle merge(ClassBundle... bundles)
          Merge two ClassBundles
 void runKnownMethods(Object object)
          Utility method to reflect on all added methods using an object instantiated from the Class loaded by the ClassBundle
 void setArtifact(String artifact)
          Set the artifact
 void setClassName(String className)
          Set the className
 void setCodebase(String codebase)
          Set the codebase used to load the class.
 void setJARs(String... jars)
          Set JARs to the ClassBundle.
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ClassBundle

public ClassBundle()
Create a new ClassBundle


ClassBundle

public ClassBundle(String className)
Create a new ClassBundle

Parameters:
className - The className

ClassBundle

public ClassBundle(String className,
                   String[] jarNames,
                   Map<String,String[]> shComponents,
                   String codebase)
Create a new ClassBundle

Parameters:
className - The className
jarNames - Array of Strings identifyng resource names used to load the className
shComponents - Map of class names and jar names to load the class from. A shared component will be loaded by the common loader for all services making it (and the resources it uses) available to all services
codebase - The URL path used to load the class. The path will be applied to all JARs in this ClassBundle
Method Detail

setCodebase

public void setCodebase(String codebase)
Set the codebase used to load the class. The path will be applied to all JARs in this ClassBundle

Parameters:
codebase - The codebase to set

getCodebase

public String getCodebase()
Get the codebase used to load the class.

Returns:
The codebase that has been set. If the codebase has properties declared (in the form $[property]), return a formatted string with the properties expanded. If there are no property elements declared, return the original string.

getRawCodebase

public String getRawCodebase()
Get the codebase without any translation

Returns:
The codebase that has been set

setClassName

public void setClassName(String className)
Set the className

Parameters:
className - The className, suitable for use with Class.forName()

getClassName

public String getClassName()
Get the className

Returns:
The className, suitable for use with Class.forName()

getArtifact

public String getArtifact()
Get the artifact associated with the className

Returns:
The artifact associated with the className

setArtifact

public void setArtifact(String artifact)
Set the artifact

Parameters:
artifact - The artifact associated with the className

setJARs

public void setJARs(String... jars)
Set JARs to the ClassBundle.

Parameters:
jars - Jar names to add

addJARs

public void addJARs(String... jars)
Add JARs to the ClassBundle.

Parameters:
jars - Jar names to add.

addJAR

public void addJAR(String jar)
Add a JAR to the Collection of JAR resources.

Parameters:
jar - Name of the JAR to add

addSharedComponents

public void addSharedComponents(Map<String,String[]> m)
Add a Map of shared components

Parameters:
m - Map of shared components to add

loadClass

public Class loadClass()
                throws ClassNotFoundException,
                       MalformedURLException
Load the class using the provided JAR resources. If there are no JARs resources for the class the curremt contxt ClassLoader will be used to load the class. If there are JAR resources, a new ClassLoader will be created each time this method is invoked, setting the delegating ClassLoader to the contextClassLoader

Returns:
A new Class instance each time this method is invoked
Throws:
ClassNotFoundException - If the class cannot be loaded
MalformedURLException - If URLs cannot be created

loadClass

public Class loadClass(ClassLoader parent)
                throws ClassNotFoundException,
                       MalformedURLException
Load the class using the provided JAR resources. If there are no JARs resources for the class the parent ClassLoader will be used to load the class. If there are JAR resources, a new ClassLoader will be created each time this method is invoked.

Parameters:
parent - Parent Classloader to use for delegation.
Returns:
A new Class instance each time this method is invoked
Throws:
ClassNotFoundException - If the class cannot be loaded
MalformedURLException - If URLs cannot be created

getJARNames

public String[] getJARNames()
Get the JAR names.

Returns:
A String array of the JAR names. This method will return a new array each time. If there are no JAR names, this method will return an empty array

getJARs

public URL[] getJARs()
              throws MalformedURLException
Get the JAR resources

Returns:
An URL array of the JARs that can be used as a classpath to load the class. This method will return a new array each time. If there are no JARs configured, this method will return an empty array.
Throws:
MalformedURLException - if the codebase has not been set, or if the provided codebase contains an invalid protocol

getSharedComponents

public Map<String,URL[]> getSharedComponents()
                                      throws MalformedURLException
Get shared component information

Returns:
A Map of the shared component information, transforming configured string urls to URLs. This method will return a new Map each time. If there are no shared components, this method will return an empty Map
Throws:
MalformedURLException - If URLs cannot be created

getRawSharedComponents

public Map<String,String[]> getRawSharedComponents()
Get raw shared component information

Returns:
A Map of the shared component information, not performing the transformation from string urls to URLs. This method will return a new Map each time. If there are no shared components, this method will return an empty Map

addMethod

public void addMethod(String methodName,
                      Object[] parameters)
Add a method name and the parameters to use for when reflecting on specified public member method of the class or interface represented by this ClassBundle object. The array of parameter types will be determined by the Class object for the Object types provided

Parameters:
methodName - The public member method of the Class or interface represented by this ClassBundle
parameters - Array of Object parameters for use when reflecting on the method

getMethodNames

public String[] getMethodNames()
Get all method names to reflect on

Returns:
Array of String method names to reflect on. If there are no method names to reflect on this method will return an empty array

getMethodClasses

public Class[] getMethodClasses(String methodName)
Get the corresponding Class[] parameters to reflect on a method

Parameters:
methodName - The name of the public method to reflect on
Returns:
Array of Class objects to use when reflecting on the public method

getMethodObjects

public Object[] getMethodObjects(String methodName)
Get the corresponding Class[] parameters to reflect on a method

Parameters:
methodName - The name of the public method to reflect on
Returns:
Array of Object objects to use when reflecting on the public method

runKnownMethods

public void runKnownMethods(Object object)
                     throws Exception
Utility method to reflect on all added methods using an object instantiated from the Class loaded by the ClassBundle

Parameters:
object - An instantiated Object from the Class loaded by the ClassBundle
Throws:
Exception - If there are errors running the known methods

hashCode

public int hashCode()
Override hashCode

Overrides:
hashCode in class Object

equals

public boolean equals(Object obj)
Override equals

Overrides:
equals in class Object

toString

public String toString()
Overrides:
toString in class Object

merge

public static ClassBundle merge(ClassBundle... bundles)
Merge two ClassBundles

Parameters:
bundles - ClassBundle instances to merge
Returns:
A merged ClassBundle.
Throws:
IllegalArgumentException - For all ClassBundles that have a non-null classname, that classname must be equal. If this is not the case then an IllegalArgumentException is thrown.

Copyright © Rio Project.

Copyright © 2006-2011 Rio Project. All Rights Reserved.