FileDocCategorySizeDatePackage
PluggableFeatureFactoryBaseImpl.javaAPI DocGlassfish v2 API8501Fri May 04 22:32:04 BST 2007com.sun.enterprise.pluggable

PluggableFeatureFactoryBaseImpl

public abstract class PluggableFeatureFactoryBaseImpl extends Object implements InvocationHandler
An abstract base class for implementing a PluggableFeatureFactory interface i * using dynamic proxies. This class does not directly implement the interface PluggableFeatureFactory, but an proxy instance implementing the interface can be obtained by a call to the static method getInstance(). In reality, this class implements InvocationHnalder interface used to handle method invocations on a dynamic proxy object.

Fields Summary
private Logger
_logger
Reference to a logger used to log exceptions.
private Properties
_featureImplClasses
A property object that keeps interface names and the names of corresponding implementation classes.
Constructors Summary
protected PluggableFeatureFactoryBaseImpl(Logger logger)
Private constructor. The public instances of this object are not available. The instance of this class is however used as invocation handler for dynamic proxy returned by static method getInstance().

        _logger = logger;
    
Methods Summary
protected abstract java.lang.ObjectcreateFeatureFactory(java.lang.reflect.InvocationHandler handler)
Get an instance of a pluggable feature factory. The method expects a property object as parameter that has one property for every supported pluggable feature. The property name is the name of the interface (without package name) and property value is the fully qualified name of the class that implements the interface. The implementing class must have a default public constructor.

param
props properties defining name of feature and implementing classes. Name of the feature is the class name of the interface defining the feature.
return
a proxy object implementing the interface PluggableFeatureFactory. If specified parameter props is null, the method returns null.

private java.lang.StringfindFeatureFromMethod(java.lang.reflect.Method method)
Find feature name from a method. For the interface PluggableFeatureFactory, a feature name is name of the interface defining the feature. The return type of any method in the interface PluggableFeatureFactory is the interface defining the feature (Note that the interface only contains getter methods). For example, if one of the pluggable features is defined by the interface com.sun.enterprise.server.pluggable.CoolStuff, the corresponding feature name is CoolStuff.

        Class returnType = method.getReturnType();
        return Utils.getNQClassName(returnType);
    
protected abstract java.lang.StringgetDefaultFeatureFactoryPropertyName()

public java.lang.ObjectgetInstance()
Get an instance of a pluggable feature factory using the system property com.sun.appserv.pluggable.features. The value of the system property is expected to be the name of a class that extends java.util.Properties and defines one property for every supported pluggable feature. This method calls getInstance(String) if the value of com.sun.appserv.pluggable.features is not null. The property com.sun.appserv.pluggable.features is defined as a constant in the interface PluggableFeatureFactory and the implementation uses that (PluggableFeatureFactory.PLUGGABLE_FEATURES_PROPERTY_NAME)

return
the return value from call to getInstance(String) if the system property is defined, null otherwise.
see
getInstance(String propClassName)

        String propClassName = System.getProperty(
                getDefaultFeatureFactoryPropertyName());
        return getInstance(propClassName);
    
public java.lang.ObjectgetInstance(java.lang.String propClassName)
Get an instance of a pluggable feature factory using specified property class name. The method expects name of a class that extends java.util.Properties and has a default (null or no argument) constructor. This method will create an instance of specified class and then call getInstance(Properties). If an instance of specified class name can not be created, the method logs the exception to the logger specified by setLogger() method, or to System.err (if no logger was set).

param
propClassName name of a class that extends Properties and contains a property for every supported pluggable feature.
return
the return value from getInstance(Properties) if propClassName is not null and an instance of the class represented by propClassName was successfully created, null otherwise.
see
getInstance(java.util.Properties props)

        if (propClassName == null) {
            return null;
        }
        Properties props = null;
        try {
            props = (Properties)Class.forName(propClassName).newInstance();
        } catch (Exception ex) {
            String msg = "Error loading pluggable features class "
                    + propClassName;
            if (_logger != null) {
                _logger.log(Level.WARNING, msg, ex);
            } else {
                System.err.println(msg + "\nStack Trace:");
                ex.printStackTrace();
            }
        }
        return getInstance(props);
    
public java.lang.ObjectgetInstance(java.util.Properties props)

        if (props == null) {
            return null;
        }
        _featureImplClasses = props;
        return createFeatureFactory(this);
    
public java.lang.Objectinvoke(java.lang.Object proxy, java.lang.reflect.Method method, java.lang.Object[] args)
Handle a invocation on a proxy object. This implementation looks for a property key matching the return type of the method, then takes the value of the property, assumes it to be a class name, assumes that the class has a default public constructor and then creates an instance of that class and returns it.

        String featureName = findFeatureFromMethod(method);
        String className = _featureImplClasses.getProperty(featureName); 
        Object featureImpl = Class.forName(className).newInstance();
        return featureImpl;