org.formaria.registry
Class ReflectionAdapter

java.lang.Object
  extended by org.formaria.registry.ComponentAdapter
      extended by org.formaria.registry.ReflectionAdapter
Direct Known Subclasses:
PojoAdapter

public class ReflectionAdapter
extends ComponentAdapter

An adapter of component properties and settings for use with registered components. The class maintains a list of getter and setter methods and helps with invocation of those methods, if a getter or setter is not available then reflection is used to try and find an appropriate method.

Copyright (c) Formaria Ltd., 2008

License: see License.txt


Field Summary
 
Fields inherited from class org.formaria.registry.ComponentAdapter
className, clazz, getters, setters, UI
 
Constructor Summary
ReflectionAdapter(java.lang.ClassLoader cl, java.lang.String clazzName, java.lang.String ui)
          Construct a new adapter for the specified class.
ReflectionAdapter(java.lang.Class clazz, java.lang.String ui)
          Construct a new adapter for the specified class.
ReflectionAdapter(java.lang.String clazzName, java.lang.String ui)
          Construct a new adapter for the specified class.
 
Method Summary
 java.lang.reflect.Method addProperty(java.lang.String type, java.lang.String propertyName)
          Try to get and register a method
 java.lang.Object getProperty(java.lang.Object comp, java.lang.String propertyName)
          Get a property value.
 int setProperty(java.lang.Object comp, java.lang.String propertyName, java.lang.String content, java.lang.String paramType)
          Set a property value.
 
Methods inherited from class org.formaria.registry.ComponentAdapter
addProperty, getAdapterClass, getAdapterClassName, getUI
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ReflectionAdapter

public ReflectionAdapter(java.lang.Class clazz,
                         java.lang.String ui)
Construct a new adapter for the specified class.

Parameters:
clazz - the class being adapter
ui - the type of user interface this component supports, e.g. "swing"
Throws:
java.lang.ClassNotFoundException - Could not find the class
Since:
3.0

ReflectionAdapter

public ReflectionAdapter(java.lang.String clazzName,
                         java.lang.String ui)
                  throws java.lang.ClassNotFoundException
Construct a new adapter for the specified class.

Parameters:
clazzName - the class name e.g. com.myorg.MyClass
ui - the type of user interface this component supports, e.g. "swing"
Throws:
java.lang.ClassNotFoundException - Could not find the class

ReflectionAdapter

public ReflectionAdapter(java.lang.ClassLoader cl,
                         java.lang.String clazzName,
                         java.lang.String ui)
                  throws java.lang.ClassNotFoundException
Construct a new adapter for the specified class.

Parameters:
cl - the class loader to use to load the class
clazzName - the class name e.g. com.myorg.MyClass
ui - the type of user interface this component supports, e.g. "swing"
Throws:
java.lang.ClassNotFoundException - Could not find the class
Method Detail

setProperty

public int setProperty(java.lang.Object comp,
                       java.lang.String propertyName,
                       java.lang.String content,
                       java.lang.String paramType)
Set a property value. If the method has not been registered an attempt will be made to get the method using the bean naming convention.

Overrides:
setProperty in class ComponentAdapter
Parameters:
comp - the comp whose property is set
propertyName - the name of the property
paramType - the type of parameter (String, int, double, boolean, Object) or null for no parameter
content - the value to set
Returns:
0 if all is well, otherwise -1 is returned to indicate an error

getProperty

public java.lang.Object getProperty(java.lang.Object comp,
                                    java.lang.String propertyName)
Get a property value. If the method has not been registered an attempt will be made to get the method using the bean naming convention.

Overrides:
getProperty in class ComponentAdapter
Parameters:
comp - the comp whose property is to be retrieved
propertyName - the name of the property
Returns:
the property value

addProperty

public java.lang.reflect.Method addProperty(java.lang.String type,
                                            java.lang.String propertyName)
Try to get and register a method

Parameters:
type - either "get" or "set"
propertyName - the method name
Returns:
the method or null if not found