org.globus.wsrf.impl
Class ReflectionResource

java.lang.Object
  |
  +--org.globus.wsrf.impl.ReflectionResource
All Implemented Interfaces:
ResourceIdentifier, ResourceProperties
Direct Known Subclasses:
PersistentReflectionResource

public class ReflectionResource
extends Object
implements ResourceProperties, ResourceIdentifier

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 PersistentResourceHome, 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:


Constructor Summary
ReflectionResource()
           
 
Method Summary
protected  ResourceProperty createNewResourceProperty(QName rpQName, Object resourceBean)
          Override this callback method to specialize the implementation of the resource property value accessors on a per resource property basis.
 Calendar getCurrentTime()
          A default implementation for the wsrl:CurrentTime Resource Property.
 Object getID()
          See ResourceIdentifier.
protected  Object getResourceBean()
           
 ResourcePropertySet getResourcePropertySet()
          See ResourceProperties.
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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.


createNewResourceProperty

protected ResourceProperty createNewResourceProperty(QName rpQName,
                                                     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:
rpQName - the QName of the resource property object
resourceBean - same as passed to constructor or initialize

getCurrentTime

public Calendar getCurrentTime()
A default implementation for the wsrl:CurrentTime Resource Property.
Returns:
Calendar

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

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


Copyright © 1999-2003 University of Chicago and The University of Southern California. All rights reserved.