org.globus.wsrf.impl
Class ReflectionResource

java.lang.Object
  extended byorg.globus.wsrf.impl.ReflectionResource
All Implemented Interfaces:
Resource, ResourceIdentifier, ResourceLifetime, ResourceProperties
Direct Known Subclasses:
PersistentReflectionResource

public class ReflectionResource
extends Object
implements Resource, ResourceProperties, ResourceIdentifier, ResourceLifetime

An implementation of ResourceProperties and ResourceIdentifier which frees the developer from having to write a getter and possibly a setter to implement every resource property (RP).

This class uses an Axis-generated JavaBean class based on the Schema definition of the RP set used by the service port type in WSDL. Since the generated class contain a JavaBean property as well as QName and Schema type metadata (such as occurence cardinality) for each RP, it is possible to automatically create ReflectionResourceProperty objects to provide an implementation of the RPs. This is what ReflectionResource does.

Advantages of using this class:

Usage:

The specialized resource home class should do the following when creating a resource:

  1. create an object corresponding to the Schema type or element of the resource property set.
  2. initialize the object by calling its setters.
  3. construct the specialized ReflectionResource-based resource object.
  4. call initialize on the resource, passing it the implementation bean created in 1).

Reuse approach:

Typical goals when extending the class:

Extending ReflectionResource:

Classes directly or indirectly extending ReflectionResource property must be allow instanciation without parameter. If a parameterless constructor is present it must not do any initialization whatsoever. The reason is to decouple object creation from initialization so as to match the requirements of Resource Home classes such as ResourceHomeImpl, which, when materializing a previously stored persistent resource, creates the resource object first using a parameterless constructor, and then initializes the object. Code that creates the key of the resource automatically (for instance a UUID) - in domain-specific cases where it makes sense - should not be put inside a parameterless constructor but in an a overriding version of the initialize() method, or inside the Resource Home class. In this way a Persistent Resource object can be brought back from a passivated state and be given the ID it used to have in activated mode, as opposed to a newly generated ID.

Known limitations:

This class does not provide a getter to the implementation JavaBean, because it is good practice to access the value of a resource property by obtaining the ResourceProperty object first, as opposed to calling the getters and setters of its implementation Bean.

In fact:


Field Summary
private  Method getTerminationTimeMethod
           
private static org.globus.util.I18n i18n
           
private  Object ID
           
private static org.apache.commons.logging.Log logger
           
private static MethodCache methodCache
           
private  Object resourceBean
           
private  ResourcePropertySet resourcePropertySet
           
private static Class[] SET_TERM_TIME_PARAM
           
private  Method setTerminationTimeMethod
           
 
Constructor Summary
ReflectionResource()
           
 
Method Summary
protected  ResourceProperty createNewResourceProperty(QName rpQName, Object resourceBean)
          Warning: this is not a callback (but maybe it should be).
protected  ResourceProperty createNewResourceProperty(ResourcePropertyMetaData metaData, Object resourceBean)
          Override this callback method to specialize the implementation of the resource property value accessors on a per resource property basis.
 Calendar getCurrentTime()
          Get the current time
 Object getID()
          See ResourceIdentifier.
 Object getResourceBean()
           
 ResourcePropertySet getResourcePropertySet()
          See ResourceProperties.
 Calendar getTerminationTime()
          Get the termination time
 void initialize(Object resourceBean, QName resourceElementQName, Object key)
          This should be called before any other resource property addition is made as it will create resource properties object based on the resource properties defined in the schema.
private  void initializeResourceProperties(Object resourceBean, QName resourceElementQName)
           
 void setTerminationTime(Calendar time)
          Set the termination time
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static org.apache.commons.logging.Log logger

i18n

private static org.globus.util.I18n i18n

SET_TERM_TIME_PARAM

private static final Class[] SET_TERM_TIME_PARAM

methodCache

private static MethodCache methodCache

resourcePropertySet

private ResourcePropertySet resourcePropertySet

ID

private Object ID

resourceBean

private Object resourceBean

setTerminationTimeMethod

private Method setTerminationTimeMethod

getTerminationTimeMethod

private Method getTerminationTimeMethod
Constructor Detail

ReflectionResource

public ReflectionResource()
Method Detail

initialize

public void initialize(Object resourceBean,
                       QName resourceElementQName,
                       Object key)
                throws ResourceException
This should be called before any other resource property addition is made as it will create resource properties object based on the resource properties defined in the schema. It is possible to override the implementation of certain resources properties by adding a new ResourceProperty object to the resource property set after this method has been called. This method should be called in the constructor of the concrete resource class, or shortly after the parameterless constructor has been called.

Parameters:
resourceBean - Object An instance of the Axis-generated class corresponding to the resource property set global Schema type or element (with local type) used by the port type definition. That class has JavaBean properties matching all the resource properties of the port type. The ReflectionResource constructor creates the ResourceProperty objects based on the resource bean, which JavaBean properties SHOULD thus have been initialized beforehand. This object provides an easy way to initialize the values of the resource properties.

resourceElementQName - QName The QName of the resource properties element used by the port type. This corresponds to the value of the 'wsrp:ResourceProperties' attribute. If the type of this element is anonymous (i.e. inlined in the element declaration) then this parameter is optional. If it is non-null though, its value takes precedence over Axis-generated metadata.

key - Object The resource key object for this resource. This is used to set the ID property of this object as a ResourceIdentifier, if the resource class doesn't create it automatically.

Throws:
ResourceException

initializeResourceProperties

private void initializeResourceProperties(Object resourceBean,
                                          QName resourceElementQName)
                                   throws ResourceException
Throws:
ResourceException

createNewResourceProperty

protected ResourceProperty createNewResourceProperty(QName rpQName,
                                                     Object resourceBean)
                                              throws Exception
Warning: this is not a callback (but maybe it should be).

Parameters:
rpQName - QName
resourceBean - Object
Returns:
ResourceProperty
Throws:
Exception

createNewResourceProperty

protected ResourceProperty createNewResourceProperty(ResourcePropertyMetaData metaData,
                                                     Object resourceBean)
                                              throws Exception
Override this callback method to specialize the implementation of the resource property value accessors on a per resource property basis. For instance, in the overriden version, do special processing if the QName of the property matches a special QName, or just call this base implementation otherwise.

The default behavior is to create a new ReflectionResourceProperty constructed with the QName of the resource property and the resource implementation Bean used to construct this ReflectionResource object.

This function handles a few special cases:

Parameters:
metaData - Meta data associated with the resource property object
resourceBean - same as passed to constructor or initialize
Throws:
Exception

setTerminationTime

public void setTerminationTime(Calendar time)
Description copied from interface: ResourceLifetime
Set the termination time

Specified by:
setTerminationTime in interface ResourceLifetime
Parameters:
time - The termination time to set

getTerminationTime

public Calendar getTerminationTime()
Description copied from interface: ResourceLifetime
Get the termination time

Specified by:
getTerminationTime in interface ResourceLifetime
Returns:
The termination time

getCurrentTime

public Calendar getCurrentTime()
Description copied from interface: ResourceLifetime
Get the current time

Specified by:
getCurrentTime in interface ResourceLifetime
Returns:
The current time

getResourcePropertySet

public ResourcePropertySet getResourcePropertySet()
See ResourceProperties.

Specified by:
getResourcePropertySet in interface ResourceProperties
Returns:
ResourcePropertySet

getID

public Object getID()
See ResourceIdentifier.

Specified by:
getID in interface ResourceIdentifier
Returns:
Object The key of the Resource. This is useful for instance when creating an endpoint reference that must be qualified with this resource.

getResourceBean

public Object getResourceBean()
Returns:
Object the Axis-generated Java Bean used as the main implementation of the resource state.