org.jboss.ejb.plugins.jaws.metadata
public class: ValueObjectHelper [javadoc |
source]
java.lang.Object
org.jboss.ejb.plugins.jaws.metadata.ValueObjectHelper
Provide static method to obtain a private attribute of a value object using
its get method, and to set the value of a private attribute using its set
method.
WARNING : These methods use Reflection so OK to run them at deployment time
but at run time, we should better catch the Method get/set at CMPFieldMetaData
level. So that the only invoke() method will be called at run time. This still
needs to be done.
- author:
< - a href="mailto:vincent.harcq@hubmethods.com">Vincent Harcq
- version:
$ - Revision: 1.3 $
| Method from org.jboss.ejb.plugins.jaws.metadata.ValueObjectHelper Detail: |
public static Class getNestedFieldType(Class ejbClass,
String name) throws NoSuchMethodException {
StringTokenizer st = new StringTokenizer(name,".");
Class clazz = ejbClass;
while (st.hasMoreTokens())
{
String tmp = st.nextToken();
try
{
// First try to find a public Field
Field tmpField = clazz.getField(tmp);
clazz = tmpField.getType();
}
catch (NoSuchFieldException e)
{
// Else try to find the getMethod
Method m = clazz.getMethod(getGetMethod(tmp),null);
// TODO what about primitive types ?
clazz = m.getReturnType();
}
}
return clazz;
}
|
public static Object getValue(Object o,
String fieldName) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
Method m=o.getClass().getMethod(getGetMethod(fieldName),null);
return m.invoke(o,null);
}
|
public static void setValue(Object o,
String fieldName,
Object value) throws InvocationTargetException, NoSuchMethodException, IllegalAccessException {
if (value == null) return;
Class[] paramTypes= { value.getClass() };
Method m=o.getClass().getMethod(getSetMethod(fieldName),paramTypes);
Object[] args = { value };
m.invoke(o,args);
}
|