You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by sk...@apache.org on 2008/07/03 23:35:00 UTC
svn commit: r673822 [7/7] - in /myfaces/orchestra/trunk:
examples/src/main/java/org/apache/myfaces/examples/annotations/
examples/src/main/java/org/apache/myfaces/examples/ballot/backings/
examples/src/main/java/org/apache/myfaces/examples/ballot/dao/ ...
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/BcelHelper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/BcelHelper.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/BcelHelper.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/BcelHelper.java Thu Jul 3 14:34:56 2008
@@ -45,147 +45,147 @@
*/
public class BcelHelper implements ClassHelper
{
- /**
- * Return a list of all the static and non-static fields of the specified
- * class, regardless of their accessability.
- * <p>
- * The array order matches the order in which the fields were declared within
- * the original source file.
- */
- public Field[] getFields(Class<?> clazz)
- {
- JavaClass javaClass = Repository.lookupClass(clazz);
- org.apache.bcel.classfile.Field[] fields = javaClass.getFields();
-
- List<Field> ret = new ArrayList<Field>(fields.length);
- for (org.apache.bcel.classfile.Field field : fields)
- {
- try
- {
- ret.add(clazz.getDeclaredField(field.getName()));
- }
- catch (SecurityException e)
- {
- throw new DynaFormException(e);
- }
- catch (NoSuchFieldException e)
- {
- throw new DynaFormException(e);
- }
- }
- return ret.toArray(new Field[ret.size()]);
- }
-
- /**
- * Return a list of all the get*, set* and is* method on the specified class,
- * regardless of their accessability.
- * <p>
- * The array order matches the order in which the methods were declared within
- * the original source file.
- */
- public Method[] getMethods(Class<?> clazz)
- {
- JavaClass javaClass = Repository.lookupClass(clazz);
- org.apache.bcel.classfile.Method[] methods = javaClass.getMethods();
-
- List<Method> ret = new ArrayList<Method>(methods.length);
- for (org.apache.bcel.classfile.Method method : methods)
- {
- String methodName = method.getName();
- if (!methodName.startsWith("set") && !methodName.startsWith("get") && !methodName.startsWith("is"))
- {
- continue;
- }
-
- Type[] types = method.getArgumentTypes();
- Class<?>[] args = new Class[types.length];
- for (int i = 0; i < types.length; i++)
- {
- args[i] = type2Class(types[i]);
- }
-
- try
- {
- ret.add(clazz.getDeclaredMethod(methodName, args));
- }
- catch (SecurityException e)
- {
- throw new DynaFormException(e);
- }
- catch (NoSuchMethodException e)
- {
- throw new DynaFormException(e);
- }
- }
- return ret.toArray(new Method[ret.size()]);
- }
-
- protected Class<?> type2Class(Type type)
- {
- if (type instanceof BasicType)
- {
- BasicType basicType = (BasicType) type;
- if (basicType.getType() == BasicType.BOOLEAN.getType())
- {
- return boolean.class;
- }
- else if (basicType.getType() == BasicType.BYTE.getType())
- {
- return byte.class;
- }
- else if (basicType.getType() == BasicType.CHAR.getType())
- {
- return char.class;
- }
- else if (basicType.getType() == BasicType.DOUBLE.getType())
- {
- return double.class;
- }
- else if (basicType.getType() == BasicType.FLOAT.getType())
- {
- return float.class;
- }
- else if (basicType.getType() == BasicType.INT.getType())
- {
- return int.class;
- }
- else if (basicType.getType() == BasicType.LONG.getType())
- {
- return long.class;
- }
- else if (basicType.getType() == BasicType.SHORT.getType())
- {
- return short.class;
- }
- else if (basicType.getType() == BasicType.STRING.getType())
- {
- return String.class;
- }
- else if (basicType.getType() == BasicType.VOID.getType())
- {
- return void.class;
- }
- throw new IllegalArgumentException("dont know how to map " + basicType);
- }
- else if (type instanceof ObjectType)
- {
- ObjectType objectType = (ObjectType) type;
- try
- {
- return Class.forName(objectType.getClassName());
- }
- catch (ClassNotFoundException e)
- {
- throw new DynaFormException(e);
- }
- }
- else if (type instanceof ArrayType)
- {
- Class<?> elementType = type2Class(((ArrayType) type).getElementType());
- return Array.newInstance(elementType, 0).getClass();
- }
+ /**
+ * Return a list of all the static and non-static fields of the specified
+ * class, regardless of their accessability.
+ * <p>
+ * The array order matches the order in which the fields were declared within
+ * the original source file.
+ */
+ public Field[] getFields(Class<?> clazz)
+ {
+ JavaClass javaClass = Repository.lookupClass(clazz);
+ org.apache.bcel.classfile.Field[] fields = javaClass.getFields();
+
+ List<Field> ret = new ArrayList<Field>(fields.length);
+ for (org.apache.bcel.classfile.Field field : fields)
+ {
+ try
+ {
+ ret.add(clazz.getDeclaredField(field.getName()));
+ }
+ catch (SecurityException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (NoSuchFieldException e)
+ {
+ throw new DynaFormException(e);
+ }
+ }
+ return ret.toArray(new Field[ret.size()]);
+ }
+
+ /**
+ * Return a list of all the get*, set* and is* method on the specified class,
+ * regardless of their accessability.
+ * <p>
+ * The array order matches the order in which the methods were declared within
+ * the original source file.
+ */
+ public Method[] getMethods(Class<?> clazz)
+ {
+ JavaClass javaClass = Repository.lookupClass(clazz);
+ org.apache.bcel.classfile.Method[] methods = javaClass.getMethods();
+
+ List<Method> ret = new ArrayList<Method>(methods.length);
+ for (org.apache.bcel.classfile.Method method : methods)
+ {
+ String methodName = method.getName();
+ if (!methodName.startsWith("set") && !methodName.startsWith("get") && !methodName.startsWith("is"))
+ {
+ continue;
+ }
+
+ Type[] types = method.getArgumentTypes();
+ Class<?>[] args = new Class[types.length];
+ for (int i = 0; i < types.length; i++)
+ {
+ args[i] = type2Class(types[i]);
+ }
+
+ try
+ {
+ ret.add(clazz.getDeclaredMethod(methodName, args));
+ }
+ catch (SecurityException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (NoSuchMethodException e)
+ {
+ throw new DynaFormException(e);
+ }
+ }
+ return ret.toArray(new Method[ret.size()]);
+ }
+
+ protected Class<?> type2Class(Type type)
+ {
+ if (type instanceof BasicType)
+ {
+ BasicType basicType = (BasicType) type;
+ if (basicType.getType() == BasicType.BOOLEAN.getType())
+ {
+ return boolean.class;
+ }
+ else if (basicType.getType() == BasicType.BYTE.getType())
+ {
+ return byte.class;
+ }
+ else if (basicType.getType() == BasicType.CHAR.getType())
+ {
+ return char.class;
+ }
+ else if (basicType.getType() == BasicType.DOUBLE.getType())
+ {
+ return double.class;
+ }
+ else if (basicType.getType() == BasicType.FLOAT.getType())
+ {
+ return float.class;
+ }
+ else if (basicType.getType() == BasicType.INT.getType())
+ {
+ return int.class;
+ }
+ else if (basicType.getType() == BasicType.LONG.getType())
+ {
+ return long.class;
+ }
+ else if (basicType.getType() == BasicType.SHORT.getType())
+ {
+ return short.class;
+ }
+ else if (basicType.getType() == BasicType.STRING.getType())
+ {
+ return String.class;
+ }
+ else if (basicType.getType() == BasicType.VOID.getType())
+ {
+ return void.class;
+ }
+ throw new IllegalArgumentException("dont know how to map " + basicType);
+ }
+ else if (type instanceof ObjectType)
+ {
+ ObjectType objectType = (ObjectType) type;
+ try
+ {
+ return Class.forName(objectType.getClassName());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DynaFormException(e);
+ }
+ }
+ else if (type instanceof ArrayType)
+ {
+ Class<?> elementType = type2Class(((ArrayType) type).getElementType());
+ return Array.newInstance(elementType, 0).getClass();
+ }
- throw new IllegalArgumentException("unkown type " + type);
- }
+ throw new IllegalArgumentException("unkown type " + type);
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/ClassHelper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/ClassHelper.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/ClassHelper.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/ClassHelper.java Thu Jul 3 14:34:56 2008
@@ -35,7 +35,7 @@
* The array order matches the order in which the fields were declared within
* the original source file.
*/
- public Field[] getFields(Class<?> clazz);
+ public Field[] getFields(Class<?> clazz);
/**
* Return a list of all the get*, set* and is* method on the specified class,
@@ -44,5 +44,5 @@
* The array order matches the order in which the methods were declared within
* the original source file.
*/
- public Method[] getMethods(Class<?> clazz);
+ public Method[] getMethods(Class<?> clazz);
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/EjbExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/EjbExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/EjbExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/EjbExtractor.java Thu Jul 3 14:34:56 2008
@@ -79,94 +79,94 @@
*/
public class EjbExtractor implements Extractor
{
- private final static Set<String> SYSTEM_METHODS = new TreeSet<String>(
- Arrays.asList(new String[]
- {"hashCode", "getClass", "wait", "equals", "notify", "notifyAll",
- "toString"}));
-
- // Info about how to introspect a particular class
- protected static class ContextInfo
- {
- private final Boolean accessField;
- private final String name;
- private final boolean embedded;
+ private final static Set<String> SYSTEM_METHODS = new TreeSet<String>(
+ Arrays.asList(new String[]
+ {"hashCode", "getClass", "wait", "equals", "notify", "notifyAll",
+ "toString"}));
+
+ // Info about how to introspect a particular class
+ protected static class ContextInfo
+ {
+ private final Boolean accessField;
+ private final String name;
+ private final boolean embedded;
private final boolean id;
protected ContextInfo(final String name, final Boolean accessField, final boolean embedded, final boolean id)
- {
- super();
- this.name = name;
- this.accessField = accessField;
- this.embedded = embedded;
+ {
+ super();
+ this.name = name;
+ this.accessField = accessField;
+ this.embedded = embedded;
this.id = id;
}
- }
+ }
+
+ // Info about how to introspect the "current class" within a hierarchy
+ // of Class objects.
+ protected static class Context
+ {
+ private boolean accessField = false;
+ private Stack<ContextInfo> accessFields = new Stack<ContextInfo>();
+ private int embeddLevel = 0;
+
+ // Are persistent properties detected by inspecting fields, or
+ // accessor-methods?
+ public void setAccessField(boolean accessField)
+ {
+ this.accessField = accessField;
+ }
- // Info about how to introspect the "current class" within a hierarchy
- // of Class objects.
- protected static class Context
- {
- private boolean accessField = false;
- private Stack<ContextInfo> accessFields = new Stack<ContextInfo>();
- private int embeddLevel = 0;
-
- // Are persistent properties detected by inspecting fields, or
- // accessor-methods?
- public void setAccessField(boolean accessField)
- {
- this.accessField = accessField;
- }
-
- public Boolean popAccessType()
- {
- return accessFields.pop().accessField;
- }
-
- // Defaults to false.
- public boolean getAccessField()
- {
- return accessField;
- }
-
- // Start processing an embedded persistent class.
- protected void startEmbedded(final String name, final boolean embedded, final boolean id)
- {
- embeddLevel++;
-
- String contextName = name;
- if (!accessFields.isEmpty())
- {
- contextName = accessFields.peek().name + "." + name;
- }
-
- accessFields.push(new ContextInfo(contextName, accessField, embedded, id));
- }
-
- protected void endEmbedded()
- {
- embeddLevel--;
- accessField = popAccessType();
- }
-
- public String getContextName()
- {
- if (accessFields.isEmpty())
- {
- return null;
- }
-
- return accessFields.peek().name;
- }
-
- public boolean isEmbedded()
- {
- if (accessFields.isEmpty())
- {
- return true;
- }
+ public Boolean popAccessType()
+ {
+ return accessFields.pop().accessField;
+ }
- return accessFields.peek().embedded;
- }
+ // Defaults to false.
+ public boolean getAccessField()
+ {
+ return accessField;
+ }
+
+ // Start processing an embedded persistent class.
+ protected void startEmbedded(final String name, final boolean embedded, final boolean id)
+ {
+ embeddLevel++;
+
+ String contextName = name;
+ if (!accessFields.isEmpty())
+ {
+ contextName = accessFields.peek().name + "." + name;
+ }
+
+ accessFields.push(new ContextInfo(contextName, accessField, embedded, id));
+ }
+
+ protected void endEmbedded()
+ {
+ embeddLevel--;
+ accessField = popAccessType();
+ }
+
+ public String getContextName()
+ {
+ if (accessFields.isEmpty())
+ {
+ return null;
+ }
+
+ return accessFields.peek().name;
+ }
+
+ public boolean isEmbedded()
+ {
+ if (accessFields.isEmpty())
+ {
+ return true;
+ }
+
+ return accessFields.peek().embedded;
+ }
public boolean isId()
{
@@ -177,369 +177,369 @@
return accessFields.peek().id;
}
- }
+ }
+
+ public EjbExtractor()
+ {
+ }
+
+ /**
+ * Implement the Extractor interface.
+ * <p>
+ * The entity parameter must be a String containing the fully-qualified name of a
+ * java class.
+ * <p>
+ * The specified class and its ancestors are inspected for JPA annotations, and
+ */
+ public void getMetaData(MetaDataWritable metaData, Object entity)
+ {
+ if (!(entity instanceof String))
+ {
+ throw new IllegalArgumentException("passed entity argument not a string: " + entity);
+ }
+
+ Class<?> entityClass;
+ try
+ {
+ entityClass = Class.forName(entity.toString());
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new RuntimeException(e);
+ }
+
+ Context context = new Context();
+
+ create(context, metaData, entityClass);
+ }
+
+ /**
+ * get all super classes needed to be parsed.
+ * <p>
+ * Populates the classes list with the complete superclass chain of the specified
+ * class. At return the first entry added to the list is the furthest ancestor that
+ * is NOT Object.class, and the last entry in the list is the clazz parameter itself.
+ */
+ protected void createClassList(List<Class<?>> classes, Class<?> clazz)
+ {
+ Class<?> superClass = clazz.getSuperclass();
+ // todo: rewrite this funky recursive method as a normal loop.
+ if (superClass != null && !superClass.equals(Object.class))
+ {
+ createClassList(classes, superClass);
+ }
+
+ classes.add(clazz);
+ }
+
+ /**
+ * create the metadata for the given class
+ */
+ @SuppressWarnings("unchecked")
+ protected void create(Context context, MetaDataWritable metaData, Class entityClass)
+ {
+ /* do not check if this is really a entity. this allows us to parse any given bean
+ if (!entityClass.isAnnotationPresent(Entity.class))
+ {
+ throw new IllegalArgumentException(entityClass.getName()
+ + " is not a ejb3 bean");
+ }
+ */
+
+ List<Class<?>> classes = new ArrayList<Class<?>>(10);
+ createClassList(classes, entityClass);
+
+ for (Class clazz : classes)
+ {
+ // Note that accessByField defaults to false. That means that
+ // initFromMethods is called.
+ boolean accessByField = context.getAccessField();
+
+ Boolean determinedAccessByField = determineAccessByField(entityClass);
+ if (determinedAccessByField != null)
+ {
+ accessByField = determinedAccessByField.booleanValue();
+ }
+
+ if (accessByField)
+ {
+ context.setAccessField(true);
+ initFromFields(context, metaData, getFields(clazz));
+ }
+ else
+ {
+ context.setAccessField(false);
+ initFromMethods(context, metaData, getMethods(clazz));
+ }
+ }
+ }
+
+ // Check whether we should look at the persistent fields of this class, or the
+ // accessor-methods. This is done by looking for JPA annotations.
+ //
+ // TODO: this only works when annotations are used, but annotations are optional in
+ // JPA; external xml config can also be used.
+ //
+ // Returns Boolean.TRUE if we should definitely look at the fields.
+ // Returns Boolean.FALSE if we should definitely look at the methods
+ // Returns null if there is no way to tell.
+ protected Boolean determineAccessByField(Class<?> clazz)
+ {
+ Class<?> checkClass = clazz;
+ while (checkClass != null && !checkClass.equals(Object.class))
+ {
+ Method[] methods = checkClass.getDeclaredMethods();
+ for (Method method : methods)
+ {
+ if (method.isSynthetic())
+ {
+ continue;
+ }
+
+ if (method.isAnnotationPresent(Id.class) || method.isAnnotationPresent(EmbeddedId.class))
+ {
+ return Boolean.FALSE;
+ }
+ }
+
+ Field[] fields = checkClass.getDeclaredFields();
+ for (Field field : fields)
+ {
+ if (field.isSynthetic())
+ {
+ continue;
+ }
+
+ if (field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class))
+ {
+ return Boolean.TRUE;
+ }
+ }
+
+ checkClass = checkClass.getSuperclass();
+ }
+
+ return null;
+ }
+
+ protected Method[] getMethods(Class<?> entityClass)
+ {
+ return ClassHelperFactory.get().getMethods(entityClass);
+ }
+
+ protected Field[] getFields(Class<?> entityClass)
+ {
+ return ClassHelperFactory.get().getFields(entityClass);
+ }
+
+ /**
+ * ejb3 access through fields
+ */
+ protected void initFromFields(Context context, MetaDataWritable metaData, Field[] fields)
+ {
+ for (Field field : fields)
+ {
+ if (!validModifier(field.getModifiers(), false)
+ || field.isSynthetic()
+ || hasAnnotationTransient(field))
+ {
+ // Field is static, or is marked with java keyword transient, or
+ // is marked with JPA annotation @Transient. Ignore it.
+ continue;
+ }
+ String name = field.getName();
+ Class<?> type = field.getType();
+
+ if (metaData.isWantedField(createFullName(context, name)))
+ {
+ processField(context, metaData, field, name, type, true, true);
+ }
+ }
+ }
+
+ /**
+ * process the given field - or ist superclass if it is embedded
+ */
+ protected void processField(Context context, MetaDataWritable metaData, AccessibleObject accessibleObject,
+ String name, Class<?> type, Boolean canRead, Boolean canWrite)
+ {
+ if (accessibleObject.isAnnotationPresent(IgnoreProperty.class))
+ {
+ // skip this field
+ return;
+ }
+
+ // embeddable if its annotation with @embedded - also check of @id, it might be a composite-key
+ if (processEmbedded(context, metaData, accessibleObject, name, type))
+ {
+ return;
+ }
- public EjbExtractor()
- {
- }
-
- /**
- * Implement the Extractor interface.
- * <p>
- * The entity parameter must be a String containing the fully-qualified name of a
- * java class.
- * <p>
- * The specified class and its ancestors are inspected for JPA annotations, and
- */
- public void getMetaData(MetaDataWritable metaData, Object entity)
- {
- if (!(entity instanceof String))
- {
- throw new IllegalArgumentException("passed entity argument not a string: " + entity);
- }
-
- Class<?> entityClass;
- try
- {
- entityClass = Class.forName(entity.toString());
- }
- catch (ClassNotFoundException e)
- {
- throw new RuntimeException(e);
- }
-
- Context context = new Context();
-
- create(context, metaData, entityClass);
- }
-
- /**
- * get all super classes needed to be parsed.
- * <p>
- * Populates the classes list with the complete superclass chain of the specified
- * class. At return the first entry added to the list is the furthest ancestor that
- * is NOT Object.class, and the last entry in the list is the clazz parameter itself.
- */
- protected void createClassList(List<Class<?>> classes, Class<?> clazz)
- {
- Class<?> superClass = clazz.getSuperclass();
- // todo: rewrite this funky recursive method as a normal loop.
- if (superClass != null && !superClass.equals(Object.class))
- {
- createClassList(classes, superClass);
- }
-
- classes.add(clazz);
- }
-
- /**
- * create the metadata for the given class
- */
- @SuppressWarnings("unchecked")
- protected void create(Context context, MetaDataWritable metaData, Class entityClass)
- {
- /* do not check if this is really a entity. this allows us to parse any given bean
- if (!entityClass.isAnnotationPresent(Entity.class))
- {
- throw new IllegalArgumentException(entityClass.getName()
- + " is not a ejb3 bean");
- }
- */
-
- List<Class<?>> classes = new ArrayList<Class<?>>(10);
- createClassList(classes, entityClass);
-
- for (Class clazz : classes)
- {
- // Note that accessByField defaults to false. That means that
- // initFromMethods is called.
- boolean accessByField = context.getAccessField();
-
- Boolean determinedAccessByField = determineAccessByField(entityClass);
- if (determinedAccessByField != null)
- {
- accessByField = determinedAccessByField.booleanValue();
- }
-
- if (accessByField)
- {
- context.setAccessField(true);
- initFromFields(context, metaData, getFields(clazz));
- }
- else
- {
- context.setAccessField(false);
- initFromMethods(context, metaData, getMethods(clazz));
- }
- }
- }
-
- // Check whether we should look at the persistent fields of this class, or the
- // accessor-methods. This is done by looking for JPA annotations.
- //
- // TODO: this only works when annotations are used, but annotations are optional in
- // JPA; external xml config can also be used.
- //
- // Returns Boolean.TRUE if we should definitely look at the fields.
- // Returns Boolean.FALSE if we should definitely look at the methods
- // Returns null if there is no way to tell.
- protected Boolean determineAccessByField(Class<?> clazz)
- {
- Class<?> checkClass = clazz;
- while (checkClass != null && !checkClass.equals(Object.class))
- {
- Method[] methods = checkClass.getDeclaredMethods();
- for (Method method : methods)
- {
- if (method.isSynthetic())
- {
- continue;
- }
-
- if (method.isAnnotationPresent(Id.class) || method.isAnnotationPresent(EmbeddedId.class))
- {
- return Boolean.FALSE;
- }
- }
-
- Field[] fields = checkClass.getDeclaredFields();
- for (Field field : fields)
- {
- if (field.isSynthetic())
- {
- continue;
- }
-
- if (field.isAnnotationPresent(Id.class) || field.isAnnotationPresent(EmbeddedId.class))
- {
- return Boolean.TRUE;
- }
- }
-
- checkClass = checkClass.getSuperclass();
- }
-
- return null;
- }
-
- protected Method[] getMethods(Class<?> entityClass)
- {
- return ClassHelperFactory.get().getMethods(entityClass);
- }
-
- protected Field[] getFields(Class<?> entityClass)
- {
- return ClassHelperFactory.get().getFields(entityClass);
- }
-
- /**
- * ejb3 access through fields
- */
- protected void initFromFields(Context context, MetaDataWritable metaData, Field[] fields)
- {
- for (Field field : fields)
- {
- if (!validModifier(field.getModifiers(), false)
- || field.isSynthetic()
- || hasAnnotationTransient(field))
- {
- // Field is static, or is marked with java keyword transient, or
- // is marked with JPA annotation @Transient. Ignore it.
- continue;
- }
- String name = field.getName();
- Class<?> type = field.getType();
-
- if (metaData.isWantedField(createFullName(context, name)))
- {
- processField(context, metaData, field, name, type, true, true);
- }
- }
- }
-
- /**
- * process the given field - or ist superclass if it is embedded
- */
- protected void processField(Context context, MetaDataWritable metaData, AccessibleObject accessibleObject,
- String name, Class<?> type, Boolean canRead, Boolean canWrite)
- {
- if (accessibleObject.isAnnotationPresent(IgnoreProperty.class))
- {
- // skip this field
- return;
- }
-
- // embeddable if its annotation with @embedded - also check of @id, it might be a composite-key
- if (processEmbedded(context, metaData, accessibleObject, name, type))
- {
- return;
- }
-
- if (metaData.isParentOfWantedField(name))
- {
- // we processed this field due to the fact that it was the parent of a requestedField
- embeddEntity(context, metaData, name, type);
- // now exit
- return;
- }
-
- MetaFieldWritable mdField = metaData.getOrCreateField(createFullName(context, name));
- mdField.setType(type);
- if (canRead != null && mdField.getCanRead() == null)
- {
- mdField.setCanRead(canRead);
- }
- if (canWrite != null && mdField.getCanWrite() == null)
- {
- mdField.setCanWrite(canWrite);
- }
- mdField.setEmbedded(context.isEmbedded());
- initFromType(context, mdField, type);
- initFromAnnotations(context, mdField, accessibleObject);
- }
-
- protected boolean processEmbedded(Context context, MetaDataWritable metaData, AccessibleObject accessibleObject,
- String name, Class<?> type)
- {
- if (accessibleObject.isAnnotationPresent(Embedded.class) || accessibleObject.isAnnotationPresent(Id.class) || accessibleObject.isAnnotationPresent(EmbeddedId.class))
- {
- if (type.isAnnotationPresent(Embeddable.class) || type.isAnnotationPresent(MappedSuperclass.class))
- {
- // process embedded type
- try
- {
+ if (metaData.isParentOfWantedField(name))
+ {
+ // we processed this field due to the fact that it was the parent of a requestedField
+ embeddEntity(context, metaData, name, type);
+ // now exit
+ return;
+ }
+
+ MetaFieldWritable mdField = metaData.getOrCreateField(createFullName(context, name));
+ mdField.setType(type);
+ if (canRead != null && mdField.getCanRead() == null)
+ {
+ mdField.setCanRead(canRead);
+ }
+ if (canWrite != null && mdField.getCanWrite() == null)
+ {
+ mdField.setCanWrite(canWrite);
+ }
+ mdField.setEmbedded(context.isEmbedded());
+ initFromType(context, mdField, type);
+ initFromAnnotations(context, mdField, accessibleObject);
+ }
+
+ protected boolean processEmbedded(Context context, MetaDataWritable metaData, AccessibleObject accessibleObject,
+ String name, Class<?> type)
+ {
+ if (accessibleObject.isAnnotationPresent(Embedded.class) || accessibleObject.isAnnotationPresent(Id.class) || accessibleObject.isAnnotationPresent(EmbeddedId.class))
+ {
+ if (type.isAnnotationPresent(Embeddable.class) || type.isAnnotationPresent(MappedSuperclass.class))
+ {
+ // process embedded type
+ try
+ {
boolean isId = context.isId() || accessibleObject.isAnnotationPresent(Id.class) || accessibleObject.isAnnotationPresent(EmbeddedId.class);
context.startEmbedded(name, true, isId);
create(context, metaData, type);
- }
- finally
- {
- context.endEmbedded();
- }
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * check if we should embedd this entity
- */
- protected boolean checkEmbeddEntity(Context context, MetaDataWritable metaData, String name)
- {
- String checkName = createFullName(context, name) + ".";
-
- for (String fieldName : metaData.getRequestedFields())
- {
- if (fieldName.startsWith(checkName))
- {
- return true;
- }
- }
-
- return false;
- }
-
- protected String createFullName(Context context, String name)
- {
- if (context.getContextName() != null)
- {
- return context.getContextName() + "." + name;
- }
- else
- {
- return name;
- }
- }
-
- /**
- * embedd this entity
- */
- protected void embeddEntity(Context context, MetaDataWritable metaData, String name, Class<?> entityType)
- {
- // process embedded type
- boolean previousLock = false;
- try
- {
- boolean processAll = metaData.getRequestedFields().contains(createFullName(context, name + ".*"));
- if (!processAll)
- {
- previousLock = metaData.setLockFields(true);
- }
- context.startEmbedded(name, false, context.isId());
- create(context, metaData, entityType);
- }
- finally
- {
- context.endEmbedded();
- metaData.setLockFields(previousLock);
- }
- }
-
- /**
- * init metadata from annotations
- */
- protected void initFromAnnotations(Context context, MetaFieldWritable mdField, AccessibleObject accessibleObject)
- {
- if (accessibleObject.isAnnotationPresent(DisplayOnly.class))
- {
- // display only
- mdField.setDisplayOnly(true);
- }
- if (accessibleObject.isAnnotationPresent(ReadOnly.class))
- {
- ReadOnly readOnly = accessibleObject.getAnnotation(ReadOnly.class);
-
- // read-only only
- mdField.setCanWrite(false);
- if (readOnly.disabled())
- {
- mdField.setDisabled(true);
- }
- }
-
- if (accessibleObject.isAnnotationPresent(UIComponent.class))
- {
- UIComponent component = accessibleObject.getAnnotation(UIComponent.class);
- mdField.setWantedComponentType(component.type());
- }
-
- if (accessibleObject.isAnnotationPresent(ComponentHandler.class))
- {
- ComponentHandler componentHandler = accessibleObject.getAnnotation(ComponentHandler.class);
- String componentHandlerBeanName = componentHandler.value();
- Object componentHandlerBean = FrameworkAdapter.getCurrentInstance().getBean(componentHandlerBeanName);
- if (componentHandlerBean == null)
- {
- throw new IllegalArgumentException("no component handler with bean name " + componentHandlerBeanName + " found.");
- }
- if (!(componentHandlerBean instanceof DynaFormComponentHandler))
- {
- throw new IllegalArgumentException("component handler with bean name " + componentHandlerBeanName + " doesn't implement the " + DynaFormComponentHandler.class.getName() + " interface.");
- }
-
- mdField.setComponentHandler((DynaFormComponentHandler) componentHandlerBean);
- }
-
- if (accessibleObject.isAnnotationPresent(Column.class))
- {
- // is required
- Column column = accessibleObject.getAnnotation(Column.class);
- mdField.setRequired(!column.nullable());
- }
- if (accessibleObject.isAnnotationPresent(Basic.class))
- {
- // is required
- Basic basic = accessibleObject.getAnnotation(Basic.class);
- // do not clear flag if its already required from the @column annotation
- if (!basic.optional())
- {
- mdField.setRequired(!basic.optional());
- }
- }
+ }
+ finally
+ {
+ context.endEmbedded();
+ }
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * check if we should embedd this entity
+ */
+ protected boolean checkEmbeddEntity(Context context, MetaDataWritable metaData, String name)
+ {
+ String checkName = createFullName(context, name) + ".";
+
+ for (String fieldName : metaData.getRequestedFields())
+ {
+ if (fieldName.startsWith(checkName))
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ protected String createFullName(Context context, String name)
+ {
+ if (context.getContextName() != null)
+ {
+ return context.getContextName() + "." + name;
+ }
+ else
+ {
+ return name;
+ }
+ }
+
+ /**
+ * embedd this entity
+ */
+ protected void embeddEntity(Context context, MetaDataWritable metaData, String name, Class<?> entityType)
+ {
+ // process embedded type
+ boolean previousLock = false;
+ try
+ {
+ boolean processAll = metaData.getRequestedFields().contains(createFullName(context, name + ".*"));
+ if (!processAll)
+ {
+ previousLock = metaData.setLockFields(true);
+ }
+ context.startEmbedded(name, false, context.isId());
+ create(context, metaData, entityType);
+ }
+ finally
+ {
+ context.endEmbedded();
+ metaData.setLockFields(previousLock);
+ }
+ }
+
+ /**
+ * init metadata from annotations
+ */
+ protected void initFromAnnotations(Context context, MetaFieldWritable mdField, AccessibleObject accessibleObject)
+ {
+ if (accessibleObject.isAnnotationPresent(DisplayOnly.class))
+ {
+ // display only
+ mdField.setDisplayOnly(true);
+ }
+ if (accessibleObject.isAnnotationPresent(ReadOnly.class))
+ {
+ ReadOnly readOnly = accessibleObject.getAnnotation(ReadOnly.class);
+
+ // read-only only
+ mdField.setCanWrite(false);
+ if (readOnly.disabled())
+ {
+ mdField.setDisabled(true);
+ }
+ }
+
+ if (accessibleObject.isAnnotationPresent(UIComponent.class))
+ {
+ UIComponent component = accessibleObject.getAnnotation(UIComponent.class);
+ mdField.setWantedComponentType(component.type());
+ }
+
+ if (accessibleObject.isAnnotationPresent(ComponentHandler.class))
+ {
+ ComponentHandler componentHandler = accessibleObject.getAnnotation(ComponentHandler.class);
+ String componentHandlerBeanName = componentHandler.value();
+ Object componentHandlerBean = FrameworkAdapter.getCurrentInstance().getBean(componentHandlerBeanName);
+ if (componentHandlerBean == null)
+ {
+ throw new IllegalArgumentException("no component handler with bean name " + componentHandlerBeanName + " found.");
+ }
+ if (!(componentHandlerBean instanceof DynaFormComponentHandler))
+ {
+ throw new IllegalArgumentException("component handler with bean name " + componentHandlerBeanName + " doesn't implement the " + DynaFormComponentHandler.class.getName() + " interface.");
+ }
+
+ mdField.setComponentHandler((DynaFormComponentHandler) componentHandlerBean);
+ }
+
+ if (accessibleObject.isAnnotationPresent(Column.class))
+ {
+ // is required
+ Column column = accessibleObject.getAnnotation(Column.class);
+ mdField.setRequired(!column.nullable());
+ }
+ if (accessibleObject.isAnnotationPresent(Basic.class))
+ {
+ // is required
+ Basic basic = accessibleObject.getAnnotation(Basic.class);
+ // do not clear flag if its already required from the @column annotation
+ if (!basic.optional())
+ {
+ mdField.setRequired(!basic.optional());
+ }
+ }
if (accessibleObject.isAnnotationPresent(Id.class)
|| accessibleObject.isAnnotationPresent(EmbeddedId.class)
@@ -549,247 +549,247 @@
}
if (accessibleObject.isAnnotationPresent(Id.class))
- {
+ {
// id column cant be written if its a generated value
- if (accessibleObject.isAnnotationPresent(GeneratedValue.class))
- {
- setSpecialFieldDisabled(mdField);
- }
- }
-
- if (accessibleObject.isAnnotationPresent(Version.class))
- {
- setSpecialFieldDisabled(mdField);
- }
-
- if (accessibleObject.isAnnotationPresent(OneToOne.class))
- {
- mdField.setRelationType(RelationType.ONE_TO_ONE);
- OneToOne relation = accessibleObject.getAnnotation(OneToOne.class);
- if (!relation.optional())
- {
- mdField.setRequired(relation.optional());
- }
- }
- if (accessibleObject.isAnnotationPresent(OneToMany.class))
- {
- mdField.setRelationType(RelationType.ONE_TO_MANY);
- }
- if (accessibleObject.isAnnotationPresent(ManyToOne.class))
- {
- mdField.setRelationType(RelationType.MANY_TO_ONE);
-
- ManyToOne relation = accessibleObject.getAnnotation(ManyToOne.class);
- if (!relation.optional())
- {
- mdField.setRequired(relation.optional());
- }
- }
- if (accessibleObject.isAnnotationPresent(ManyToMany.class))
- {
- mdField.setRelationType(RelationType.MANY_TO_MANY);
- }
- if (accessibleObject.isAnnotationPresent(DataProvider.class))
- {
- DataProvider dataProvider = accessibleObject.getAnnotation(DataProvider.class);
- mdField.setDataSource(dataProvider.value());
- mdField.setDataSourceDescription(dataProvider.description());
- if (!StringUtils.isEmpty(dataProvider.converterBean()))
- {
- mdField.setConverterBean(dataProvider.converterBean());
- }
- }
-
- // get Temporal from model ...
- if (accessibleObject.isAnnotationPresent(Temporal.class))
- {
- Temporal temporal = accessibleObject.getAnnotation(Temporal.class);
- mdField.setTemporalType(temporal.value());
- }
- // ... but override with our own Temporal if required
- if (accessibleObject.isAnnotationPresent(org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal.class))
- {
- org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal temporal = accessibleObject.getAnnotation(org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal.class);
- mdField.setTemporalType(temporal.value());
- }
-
- Class<?> type = mdField.getType();
- if (type.isAnnotationPresent(Entity.class))
- {
- mdField.setEntityType(true);
- }
-
- if (accessibleObject.isAnnotationPresent(Min.class))
- {
- Min annot = accessibleObject.getAnnotation(Min.class);
- mdField.setMinValue((double) annot.value());
- }
- if (accessibleObject.isAnnotationPresent(Max.class))
- {
- Max annot = accessibleObject.getAnnotation(Max.class);
- mdField.setMaxValue((double) annot.value());
- }
- if (accessibleObject.isAnnotationPresent(Length.class))
- {
- Length annot = accessibleObject.getAnnotation(Length.class);
- mdField.setMinSize(annot.min());
- mdField.setMaxSize(annot.max());
- }
- if (accessibleObject.isAnnotationPresent(NotNull.class))
- {
- mdField.setRequired(true);
- }
- if (accessibleObject.isAnnotationPresent(Range.class))
- {
- Range annot = accessibleObject.getAnnotation(Range.class);
- mdField.setMinValue((double) annot.min());
- mdField.setMaxValue((double) annot.max());
- }
-
- if (accessibleObject.isAnnotationPresent(DisplaySize.class))
- {
- DisplaySize displaySize = accessibleObject.getAnnotation(DisplaySize.class);
- mdField.setDisplaySize(displaySize.value());
- }
- }
-
- /**
- * configure a special fields as disabled. e.g. used for Id, Version, ....
- */
- protected void setSpecialFieldDisabled(MetaFieldWritable mdField)
- {
- mdField.setCanWrite(false);
- mdField.setDisabled(true);
- }
-
- /**
- * ejb3 access through methods (properties)
- */
- protected void initFromMethods(Context context, MetaDataWritable metaData, Method[] methods)
- {
- for (Method method : methods)
- {
- if (!validModifier(method.getModifiers(), true)
- || method.isSynthetic()
- || hasAnnotationTransient(method)
- || SYSTEM_METHODS.contains(method.getName()))
- {
- continue;
- }
-
- // Given a method of name "getFoo", look for a member field of name "foo".
- String methodName = method.getName();
- String propertyName = convertMethodName(methodName);
-
- if (!metaData.isWantedField(createFullName(context, propertyName)))
- {
- continue;
- }
-
- if (methodName.startsWith("get") || methodName.startsWith("is"))
- {
- Class<?>[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length > 0)
- {
- // not a bean getter
- continue;
- }
-
- processField(context, metaData, method, propertyName, method.getReturnType(), true, null);
- }
- else if (methodName.startsWith("set"))
- {
- if (!void.class.equals(method.getReturnType()) && !Void.class.equals(method.getReturnType()))
- {
- // not a bean setter
- continue;
- }
-
- Class<?>[] parameters = method.getParameterTypes();
- if (parameters != null && parameters.length != 1)
- {
- // not a bean setter
- continue;
- }
-
- if (metaData.isWantedField(createFullName(context, propertyName)))
- {
- processField(context, metaData, method, propertyName, method.getParameterTypes()[0], null, true);
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void initFromType(Context context, MetaFieldWritable mdField, Class type)
- {
- if (type.isEnum())
- {
- EnumSet es = EnumSet.allOf(type);
- Object[] enums = es.toArray(new Object[]{es.size()});
-
- Selection[] selections = new Selection[enums.length];
- for (int i = 0; i < enums.length; i++)
- {
- Enum e = (Enum) enums[i];
- selections[i] = new Selection(e.name(), e);
- }
-
- mdField.setAllowedSelections(selections);
- }
- /*
- else if (Number.class.isAssignableFrom(type))
- {
- } 1
- */
- }
-
- /**
- * get rid of get/set/is in method names
- */
- protected String convertMethodName(String name)
- {
- if (name.startsWith("get"))
- {
- name = name.substring("get".length());
- }
- else if (name.startsWith("set"))
- {
- name = name.substring("set".length());
- }
- else if (name.startsWith("is"))
- {
- name = name.substring("is".length());
- }
- return Character.toLowerCase(name.charAt(0)) + name.substring(1);
- }
-
- /**
- * skip method/fields annotated with transient
- */
- protected boolean hasAnnotationTransient(AccessibleObject accessibleObject)
- {
- return accessibleObject.isAnnotationPresent(Transient.class);
- }
-
- /**
- * skip method/fields marked as static/transient
- */
- protected boolean validModifier(int modifier, boolean isMethod)
- {
- if (isMethod && !Modifier.isPublic(modifier))
- {
- return false;
- }
- if (Modifier.isStatic(modifier))
- {
- return false;
- }
- if (Modifier.isTransient(modifier))
- {
- return false;
- }
+ if (accessibleObject.isAnnotationPresent(GeneratedValue.class))
+ {
+ setSpecialFieldDisabled(mdField);
+ }
+ }
+
+ if (accessibleObject.isAnnotationPresent(Version.class))
+ {
+ setSpecialFieldDisabled(mdField);
+ }
+
+ if (accessibleObject.isAnnotationPresent(OneToOne.class))
+ {
+ mdField.setRelationType(RelationType.ONE_TO_ONE);
+ OneToOne relation = accessibleObject.getAnnotation(OneToOne.class);
+ if (!relation.optional())
+ {
+ mdField.setRequired(relation.optional());
+ }
+ }
+ if (accessibleObject.isAnnotationPresent(OneToMany.class))
+ {
+ mdField.setRelationType(RelationType.ONE_TO_MANY);
+ }
+ if (accessibleObject.isAnnotationPresent(ManyToOne.class))
+ {
+ mdField.setRelationType(RelationType.MANY_TO_ONE);
+
+ ManyToOne relation = accessibleObject.getAnnotation(ManyToOne.class);
+ if (!relation.optional())
+ {
+ mdField.setRequired(relation.optional());
+ }
+ }
+ if (accessibleObject.isAnnotationPresent(ManyToMany.class))
+ {
+ mdField.setRelationType(RelationType.MANY_TO_MANY);
+ }
+ if (accessibleObject.isAnnotationPresent(DataProvider.class))
+ {
+ DataProvider dataProvider = accessibleObject.getAnnotation(DataProvider.class);
+ mdField.setDataSource(dataProvider.value());
+ mdField.setDataSourceDescription(dataProvider.description());
+ if (!StringUtils.isEmpty(dataProvider.converterBean()))
+ {
+ mdField.setConverterBean(dataProvider.converterBean());
+ }
+ }
+
+ // get Temporal from model ...
+ if (accessibleObject.isAnnotationPresent(Temporal.class))
+ {
+ Temporal temporal = accessibleObject.getAnnotation(Temporal.class);
+ mdField.setTemporalType(temporal.value());
+ }
+ // ... but override with our own Temporal if required
+ if (accessibleObject.isAnnotationPresent(org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal.class))
+ {
+ org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal temporal = accessibleObject.getAnnotation(org.apache.myfaces.orchestra.dynaForm.annot.ui.Temporal.class);
+ mdField.setTemporalType(temporal.value());
+ }
+
+ Class<?> type = mdField.getType();
+ if (type.isAnnotationPresent(Entity.class))
+ {
+ mdField.setEntityType(true);
+ }
+
+ if (accessibleObject.isAnnotationPresent(Min.class))
+ {
+ Min annot = accessibleObject.getAnnotation(Min.class);
+ mdField.setMinValue((double) annot.value());
+ }
+ if (accessibleObject.isAnnotationPresent(Max.class))
+ {
+ Max annot = accessibleObject.getAnnotation(Max.class);
+ mdField.setMaxValue((double) annot.value());
+ }
+ if (accessibleObject.isAnnotationPresent(Length.class))
+ {
+ Length annot = accessibleObject.getAnnotation(Length.class);
+ mdField.setMinSize(annot.min());
+ mdField.setMaxSize(annot.max());
+ }
+ if (accessibleObject.isAnnotationPresent(NotNull.class))
+ {
+ mdField.setRequired(true);
+ }
+ if (accessibleObject.isAnnotationPresent(Range.class))
+ {
+ Range annot = accessibleObject.getAnnotation(Range.class);
+ mdField.setMinValue((double) annot.min());
+ mdField.setMaxValue((double) annot.max());
+ }
+
+ if (accessibleObject.isAnnotationPresent(DisplaySize.class))
+ {
+ DisplaySize displaySize = accessibleObject.getAnnotation(DisplaySize.class);
+ mdField.setDisplaySize(displaySize.value());
+ }
+ }
+
+ /**
+ * configure a special fields as disabled. e.g. used for Id, Version, ....
+ */
+ protected void setSpecialFieldDisabled(MetaFieldWritable mdField)
+ {
+ mdField.setCanWrite(false);
+ mdField.setDisabled(true);
+ }
+
+ /**
+ * ejb3 access through methods (properties)
+ */
+ protected void initFromMethods(Context context, MetaDataWritable metaData, Method[] methods)
+ {
+ for (Method method : methods)
+ {
+ if (!validModifier(method.getModifiers(), true)
+ || method.isSynthetic()
+ || hasAnnotationTransient(method)
+ || SYSTEM_METHODS.contains(method.getName()))
+ {
+ continue;
+ }
+
+ // Given a method of name "getFoo", look for a member field of name "foo".
+ String methodName = method.getName();
+ String propertyName = convertMethodName(methodName);
+
+ if (!metaData.isWantedField(createFullName(context, propertyName)))
+ {
+ continue;
+ }
+
+ if (methodName.startsWith("get") || methodName.startsWith("is"))
+ {
+ Class<?>[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length > 0)
+ {
+ // not a bean getter
+ continue;
+ }
+
+ processField(context, metaData, method, propertyName, method.getReturnType(), true, null);
+ }
+ else if (methodName.startsWith("set"))
+ {
+ if (!void.class.equals(method.getReturnType()) && !Void.class.equals(method.getReturnType()))
+ {
+ // not a bean setter
+ continue;
+ }
+
+ Class<?>[] parameters = method.getParameterTypes();
+ if (parameters != null && parameters.length != 1)
+ {
+ // not a bean setter
+ continue;
+ }
+
+ if (metaData.isWantedField(createFullName(context, propertyName)))
+ {
+ processField(context, metaData, method, propertyName, method.getParameterTypes()[0], null, true);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initFromType(Context context, MetaFieldWritable mdField, Class type)
+ {
+ if (type.isEnum())
+ {
+ EnumSet es = EnumSet.allOf(type);
+ Object[] enums = es.toArray(new Object[]{es.size()});
+
+ Selection[] selections = new Selection[enums.length];
+ for (int i = 0; i < enums.length; i++)
+ {
+ Enum e = (Enum) enums[i];
+ selections[i] = new Selection(e.name(), e);
+ }
+
+ mdField.setAllowedSelections(selections);
+ }
+ /*
+ else if (Number.class.isAssignableFrom(type))
+ {
+ } 1
+ */
+ }
+
+ /**
+ * get rid of get/set/is in method names
+ */
+ protected String convertMethodName(String name)
+ {
+ if (name.startsWith("get"))
+ {
+ name = name.substring("get".length());
+ }
+ else if (name.startsWith("set"))
+ {
+ name = name.substring("set".length());
+ }
+ else if (name.startsWith("is"))
+ {
+ name = name.substring("is".length());
+ }
+ return Character.toLowerCase(name.charAt(0)) + name.substring(1);
+ }
+
+ /**
+ * skip method/fields annotated with transient
+ */
+ protected boolean hasAnnotationTransient(AccessibleObject accessibleObject)
+ {
+ return accessibleObject.isAnnotationPresent(Transient.class);
+ }
+
+ /**
+ * skip method/fields marked as static/transient
+ */
+ protected boolean validModifier(int modifier, boolean isMethod)
+ {
+ if (isMethod && !Modifier.isPublic(modifier))
+ {
+ return false;
+ }
+ if (Modifier.isStatic(modifier))
+ {
+ return false;
+ }
+ if (Modifier.isTransient(modifier))
+ {
+ return false;
+ }
- return true;
- }
+ return true;
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/JavaHelper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/JavaHelper.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/JavaHelper.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/JavaHelper.java Thu Jul 3 14:34:56 2008
@@ -28,13 +28,13 @@
*/
public class JavaHelper implements ClassHelper
{
- public Field[] getFields(Class<?> clazz)
- {
- return clazz.getDeclaredFields();
- }
+ public Field[] getFields(Class<?> clazz)
+ {
+ return clazz.getDeclaredFields();
+ }
- public Method[] getMethods(Class<?> clazz)
- {
- return clazz.getDeclaredMethods();
- }
+ public Method[] getMethods(Class<?> clazz)
+ {
+ return clazz.getDeclaredMethods();
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/hibernate/HibernateExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/hibernate/HibernateExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/hibernate/HibernateExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/hibernate/HibernateExtractor.java Thu Jul 3 14:34:56 2008
@@ -28,40 +28,40 @@
*/
public class HibernateExtractor extends EjbExtractor
{
- @Override
- protected void initFromAnnotations(Context context, MetaFieldWritable mdField, AccessibleObject accessibleObject)
- {
- throw new UnsupportedOperationException();
+ @Override
+ protected void initFromAnnotations(Context context, MetaFieldWritable mdField, AccessibleObject accessibleObject)
+ {
+ throw new UnsupportedOperationException();
- /*
- super.initFromAnnotations(context, mdField, accessibleObject);
+ /*
+ super.initFromAnnotations(context, mdField, accessibleObject);
- if (accessibleObject.isAnnotationPresent(Min.class))
- {
- Min annot = accessibleObject.getAnnotation(Min.class);
- mdField.setMinValue((double) annot.value());
- }
- if (accessibleObject.isAnnotationPresent(Max.class))
- {
- Max annot = accessibleObject.getAnnotation(Max.class);
- mdField.setMaxValue((double) annot.value());
- }
- if (accessibleObject.isAnnotationPresent(Length.class))
- {
- Length annot = accessibleObject.getAnnotation(Length.class);
- mdField.setMinSize(annot.min());
- mdField.setMaxSize(annot.max());
- }
- if (accessibleObject.isAnnotationPresent(NotNull.class))
- {
- mdField.setRequired(true);
- }
- if (accessibleObject.isAnnotationPresent(Range.class))
- {
- Range annot = accessibleObject.getAnnotation(Range.class);
- mdField.setMinValue((double) annot.min());
- mdField.setMaxValue((double) annot.max());
- }
- */
- }
+ if (accessibleObject.isAnnotationPresent(Min.class))
+ {
+ Min annot = accessibleObject.getAnnotation(Min.class);
+ mdField.setMinValue((double) annot.value());
+ }
+ if (accessibleObject.isAnnotationPresent(Max.class))
+ {
+ Max annot = accessibleObject.getAnnotation(Max.class);
+ mdField.setMaxValue((double) annot.value());
+ }
+ if (accessibleObject.isAnnotationPresent(Length.class))
+ {
+ Length annot = accessibleObject.getAnnotation(Length.class);
+ mdField.setMinSize(annot.min());
+ mdField.setMaxSize(annot.max());
+ }
+ if (accessibleObject.isAnnotationPresent(NotNull.class))
+ {
+ mdField.setRequired(true);
+ }
+ if (accessibleObject.isAnnotationPresent(Range.class))
+ {
+ Range annot = accessibleObject.getAnnotation(Range.class);
+ mdField.setMinValue((double) annot.min());
+ mdField.setMaxValue((double) annot.max());
+ }
+ */
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java Thu Jul 3 14:34:56 2008
@@ -37,56 +37,56 @@
*/
public abstract class AbstractJsfExtractor implements Extractor
{
- public AbstractJsfExtractor()
- {
- }
-
- /**
- * Copy metadata overrides attached to a DynaForm UIComponent into an
- * existing MetaData instance.
- * <p>
- * The specified entity must be an instance of DynaForm (a JSF UIComponent).
- */
- public void getMetaData(MetaDataWritable metaData, Object entity)
- {
- if (!(entity instanceof DynaForm))
- {
- throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
- }
-
- create(metaData, (DynaForm) entity);
- }
-
- /**
- * create the metadata out of the dynaConfigs for the given component
- */
- @SuppressWarnings("unchecked")
- protected void create(MetaDataWritable metaData, DynaForm dynaForm)
- {
- DynaConfigs formConfig = dynaForm.getFormConfigs();
- if (formConfig == null)
- {
- return;
- }
-
- Iterator<DynaConfig> entries = formConfig.iterator();
- while (entries.hasNext())
- {
- DynaConfig dynaConfig = entries.next();
- String name = dynaConfig.getFor();
- if (name == null)
- {
- throw new IllegalArgumentException("'for' in config tag required");
- }
-
- if (metaData.isWantedField(name))
- {
- MetaFieldWritable field = metaData.getOrCreateField(name);
-
- initFromConfig(field, dynaConfig);
- }
- }
- }
+ public AbstractJsfExtractor()
+ {
+ }
+
+ /**
+ * Copy metadata overrides attached to a DynaForm UIComponent into an
+ * existing MetaData instance.
+ * <p>
+ * The specified entity must be an instance of DynaForm (a JSF UIComponent).
+ */
+ public void getMetaData(MetaDataWritable metaData, Object entity)
+ {
+ if (!(entity instanceof DynaForm))
+ {
+ throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
+ }
+
+ create(metaData, (DynaForm) entity);
+ }
+
+ /**
+ * create the metadata out of the dynaConfigs for the given component
+ */
+ @SuppressWarnings("unchecked")
+ protected void create(MetaDataWritable metaData, DynaForm dynaForm)
+ {
+ DynaConfigs formConfig = dynaForm.getFormConfigs();
+ if (formConfig == null)
+ {
+ return;
+ }
+
+ Iterator<DynaConfig> entries = formConfig.iterator();
+ while (entries.hasNext())
+ {
+ DynaConfig dynaConfig = entries.next();
+ String name = dynaConfig.getFor();
+ if (name == null)
+ {
+ throw new IllegalArgumentException("'for' in config tag required");
+ }
+
+ if (metaData.isWantedField(name))
+ {
+ MetaFieldWritable field = metaData.getOrCreateField(name);
+
+ initFromConfig(field, dynaConfig);
+ }
+ }
+ }
- protected abstract void initFromConfig(MetaFieldWritable field, DynaConfig config);
+ protected abstract void initFromConfig(MetaFieldWritable field, DynaConfig config);
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java Thu Jul 3 14:34:56 2008
@@ -29,11 +29,11 @@
*/
public class JsfExclusiveExtractor extends AbstractJsfExtractor
{
- public JsfExclusiveExtractor()
- {
- }
+ public JsfExclusiveExtractor()
+ {
+ }
- protected void initFromConfig(MetaFieldWritable field, DynaConfig config)
- {
- }
+ protected void initFromConfig(MetaFieldWritable field, DynaConfig config)
+ {
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfExtractor.java Thu Jul 3 14:34:56 2008
@@ -28,12 +28,12 @@
*/
public class JsfExtractor extends AbstractJsfExtractor
{
- public JsfExtractor()
- {
- }
+ public JsfExtractor()
+ {
+ }
- protected void initFromConfig(MetaFieldWritable field, DynaConfig config)
- {
- config.configureMetaData(field);
- }
+ protected void initFromConfig(MetaFieldWritable field, DynaConfig config)
+ {
+ config.configureMetaData(field);
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java Thu Jul 3 14:34:56 2008
@@ -34,46 +34,46 @@
*/
public class JsfRequestFieldExtractor implements Extractor
{
- public JsfRequestFieldExtractor()
- {
- }
+ public JsfRequestFieldExtractor()
+ {
+ }
- public void getMetaData(MetaDataWritable metaData, Object entity)
- {
- if (!(entity instanceof DynaForm))
- {
- throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
- }
+ public void getMetaData(MetaDataWritable metaData, Object entity)
+ {
+ if (!(entity instanceof DynaForm))
+ {
+ throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
+ }
- create(metaData, (DynaForm) entity);
- }
+ create(metaData, (DynaForm) entity);
+ }
- /**
- * create the metadata out of the dynaConfigs for the given component
- */
- @SuppressWarnings("unchecked")
- protected void create(MetaDataWritable metaData, DynaForm dynaForm)
- {
- DynaConfigs formConfig = dynaForm.getFormConfigs();
- if (formConfig == null)
- {
- return;
- }
+ /**
+ * create the metadata out of the dynaConfigs for the given component
+ */
+ @SuppressWarnings("unchecked")
+ protected void create(MetaDataWritable metaData, DynaForm dynaForm)
+ {
+ DynaConfigs formConfig = dynaForm.getFormConfigs();
+ if (formConfig == null)
+ {
+ return;
+ }
- Iterator<DynaConfig> entries = formConfig.iterator();
- while (entries.hasNext())
- {
- DynaConfig dynaConfig = entries.next();
- String name = dynaConfig.getFor();
- if (name == null)
- {
- throw new IllegalArgumentException("'for' in config tag required");
- }
+ Iterator<DynaConfig> entries = formConfig.iterator();
+ while (entries.hasNext())
+ {
+ DynaConfig dynaConfig = entries.next();
+ String name = dynaConfig.getFor();
+ if (name == null)
+ {
+ throw new IllegalArgumentException("'for' in config tag required");
+ }
- if (metaData.isWantedField(name))
- {
- metaData.requestField(name);
- }
- }
- }
+ if (metaData.isWantedField(name))
+ {
+ metaData.requestField(name);
+ }
+ }
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/utils/TypeInfos.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/utils/TypeInfos.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/utils/TypeInfos.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/metadata/utils/TypeInfos.java Thu Jul 3 14:34:56 2008
@@ -25,109 +25,109 @@
public class TypeInfos
{
- private final static Map<Class<?>, Info> INFOS = new HashMap<Class<?>, Info>(10);
+ private final static Map<Class<?>, Info> INFOS = new HashMap<Class<?>, Info>(10);
- public static class Info
- {
- /**
- * min possible value
- */
- private final Double minValue;
-
- /**
- * max possible value
- */
- private final Double maxValue;
-
- /**
- * display length, -1 means unknown
- */
- private final int length;
-
- /**
- * do this type has a fractional part
- */
- private final boolean hasFractional;
-
- /**
- * if this is a number
- */
- private final boolean number;
-
- private Info(boolean number, Double minValue, Double maxValue, boolean hasFractional)
- {
- if (minValue != null)
- {
- int length = String.valueOf(minValue).length();
- if (!hasFractional)
- {
- length = length - 2; // strip off the .0 part after string conversion
- }
- this.length = length;
- }
- else
- {
- length = -1;
- }
- this.minValue = minValue;
- this.maxValue = maxValue;
- this.hasFractional = hasFractional;
- this.number = number;
- }
-
- public int getLength()
- {
- return length;
- }
-
- public Double getMaxValue()
- {
- return maxValue;
- }
-
- public Double getMinValue()
- {
- return minValue;
- }
-
- public boolean isHasFractional()
- {
- return hasFractional;
- }
-
- public boolean isNumber()
- {
- return number;
- }
- }
-
- static
- {
- addInfo(new Info(true, (double) Byte.MIN_VALUE, (double) Byte.MAX_VALUE, false), Byte.class, Byte.TYPE);
- addInfo(new Info(true, (double) Short.MIN_VALUE, (double) Short.MAX_VALUE, false), Short.class, Short.TYPE);
- addInfo(new Info(true, (double) Integer.MIN_VALUE, (double) Integer.MAX_VALUE, false), Integer.class, Integer.TYPE);
- addInfo(new Info(true, (double) Long.MIN_VALUE, (double) Long.MAX_VALUE, false), Long.class, Long.TYPE);
- addInfo(new Info(true, null, null, false), BigInteger.class);
- addInfo(new Info(true, null, (double) Float.MAX_VALUE, true), Float.class, Float.TYPE);
- addInfo(new Info(true, null, Double.MAX_VALUE, true), Double.class, Double.TYPE);
- addInfo(new Info(true, null, null, true), BigDecimal.class);
- addInfo(new Info(false, null, null, false), String.class);
- }
-
- private TypeInfos()
- {
- }
-
- private static void addInfo(Info info, Class<?>... types)
- {
- for (Class<?> type : types)
- {
- INFOS.put(type, info);
- }
- }
-
- public static Info getInfo(Class<?> type)
- {
- return INFOS.get(type);
- }
+ public static class Info
+ {
+ /**
+ * min possible value
+ */
+ private final Double minValue;
+
+ /**
+ * max possible value
+ */
+ private final Double maxValue;
+
+ /**
+ * display length, -1 means unknown
+ */
+ private final int length;
+
+ /**
+ * do this type has a fractional part
+ */
+ private final boolean hasFractional;
+
+ /**
+ * if this is a number
+ */
+ private final boolean number;
+
+ private Info(boolean number, Double minValue, Double maxValue, boolean hasFractional)
+ {
+ if (minValue != null)
+ {
+ int length = String.valueOf(minValue).length();
+ if (!hasFractional)
+ {
+ length = length - 2; // strip off the .0 part after string conversion
+ }
+ this.length = length;
+ }
+ else
+ {
+ length = -1;
+ }
+ this.minValue = minValue;
+ this.maxValue = maxValue;
+ this.hasFractional = hasFractional;
+ this.number = number;
+ }
+
+ public int getLength()
+ {
+ return length;
+ }
+
+ public Double getMaxValue()
+ {
+ return maxValue;
+ }
+
+ public Double getMinValue()
+ {
+ return minValue;
+ }
+
+ public boolean isHasFractional()
+ {
+ return hasFractional;
+ }
+
+ public boolean isNumber()
+ {
+ return number;
+ }
+ }
+
+ static
+ {
+ addInfo(new Info(true, (double) Byte.MIN_VALUE, (double) Byte.MAX_VALUE, false), Byte.class, Byte.TYPE);
+ addInfo(new Info(true, (double) Short.MIN_VALUE, (double) Short.MAX_VALUE, false), Short.class, Short.TYPE);
+ addInfo(new Info(true, (double) Integer.MIN_VALUE, (double) Integer.MAX_VALUE, false), Integer.class, Integer.TYPE);
+ addInfo(new Info(true, (double) Long.MIN_VALUE, (double) Long.MAX_VALUE, false), Long.class, Long.TYPE);
+ addInfo(new Info(true, null, null, false), BigInteger.class);
+ addInfo(new Info(true, null, (double) Float.MAX_VALUE, true), Float.class, Float.TYPE);
+ addInfo(new Info(true, null, Double.MAX_VALUE, true), Double.class, Double.TYPE);
+ addInfo(new Info(true, null, null, true), BigDecimal.class);
+ addInfo(new Info(false, null, null, false), String.class);
+ }
+
+ private TypeInfos()
+ {
+ }
+
+ private static void addInfo(Info info, Class<?>... types)
+ {
+ for (Class<?> type : types)
+ {
+ INFOS.put(type, info);
+ }
+ }
+
+ public static Info getInfo(Class<?> type)
+ {
+ return INFOS.get(type);
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/FacesUriResolver.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/FacesUriResolver.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/FacesUriResolver.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/FacesUriResolver.java Thu Jul 3 14:34:56 2008
@@ -26,16 +26,16 @@
*/
public class FacesUriResolver extends UriResolver
{
- @Override
- protected InputStream findConfig(String config)
- {
- InputStream is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/WEB-INF/" + config);
- if (is != null)
- {
- return is;
- }
+ @Override
+ protected InputStream findConfig(String config)
+ {
+ InputStream is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/WEB-INF/" + config);
+ if (is != null)
+ {
+ return is;
+ }
- return super.findConfig(config);
- }
+ return super.findConfig(config);
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/UriResolver.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/UriResolver.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/UriResolver.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/main/java/org/apache/myfaces/orchestra/dynaForm/uri/UriResolver.java Thu Jul 3 14:34:56 2008
@@ -31,167 +31,167 @@
*/
public abstract class UriResolver
{
- /**
- * The configuration
- */
- public static class Configuration
- {
- private final Extractor extractor;
- private final String entity;
-
- protected Configuration(Extractor extractor, String entity)
- {
- this.extractor = extractor;
- this.entity = entity;
- }
-
- /**
- * metadata for the given entity
- */
- public Extractor getExtractor()
- {
- return extractor;
- }
-
- /**
- * the entity identification
- */
- public String getEntity()
- {
- return entity;
- }
- }
-
- protected Configuration createConfiguration(Extractor extractor, String entity)
- {
- return new Configuration(extractor, entity);
- }
-
- /**
- * resolve the given uri
- */
- public Configuration resolveUri(String uri)
- {
- int pos = uri.indexOf(":");
- if (pos < 0)
- {
- return resolve("default", uri);
- }
- if (uri.length() < pos + 1)
- {
- throw new IllegalArgumentException("Invalid uri: " + uri);
- }
-
- return resolve(uri.substring(0, pos), uri.substring(pos + 1));
- }
-
- /**
- * Look in all META-INF directories in the classpath for a file of name
- * "dynaForm-scheme.xml", where scheme is a parameter to this method.
- * <p>
- * From that file, load a Properties object and get the value of key
- * "Extractor", which is expected to be the name of a class that implements
- * the {@link org.apache.myfaces.orchestra.dynaForm.metadata.Extractor}
- * interface.
- * <p>
- * Use the Extractor instance to return a simple (extractor, classname)
- * pairing.
+ /**
+ * The configuration
+ */
+ public static class Configuration
+ {
+ private final Extractor extractor;
+ private final String entity;
+
+ protected Configuration(Extractor extractor, String entity)
+ {
+ this.extractor = extractor;
+ this.entity = entity;
+ }
+
+ /**
+ * metadata for the given entity
+ */
+ public Extractor getExtractor()
+ {
+ return extractor;
+ }
+
+ /**
+ * the entity identification
+ */
+ public String getEntity()
+ {
+ return entity;
+ }
+ }
+
+ protected Configuration createConfiguration(Extractor extractor, String entity)
+ {
+ return new Configuration(extractor, entity);
+ }
+
+ /**
+ * resolve the given uri
+ */
+ public Configuration resolveUri(String uri)
+ {
+ int pos = uri.indexOf(":");
+ if (pos < 0)
+ {
+ return resolve("default", uri);
+ }
+ if (uri.length() < pos + 1)
+ {
+ throw new IllegalArgumentException("Invalid uri: " + uri);
+ }
+
+ return resolve(uri.substring(0, pos), uri.substring(pos + 1));
+ }
+
+ /**
+ * Look in all META-INF directories in the classpath for a file of name
+ * "dynaForm-scheme.xml", where scheme is a parameter to this method.
+ * <p>
+ * From that file, load a Properties object and get the value of key
+ * "Extractor", which is expected to be the name of a class that implements
+ * the {@link org.apache.myfaces.orchestra.dynaForm.metadata.Extractor}
+ * interface.
+ * <p>
+ * Use the Extractor instance to return a simple (extractor, classname)
+ * pairing.
TODO: use the normal java Service configuration approach instead.
- */
- protected Configuration resolve(String scheme, String path)
- {
- String config = "dynaForm-" + scheme + ".xml";
- Properties props = new Properties();
- InputStream resource = null;
- try
- {
- resource = findConfig(config);
- if (resource == null)
- {
- throw new DynaFormException("configuration '" + config + "' not found.");
- }
-
- props.loadFromXML(resource);
- }
- catch (InvalidPropertiesFormatException e)
- {
- throw new DynaFormException(e);
- }
- catch (IOException e)
- {
- throw new DynaFormException(e);
- }
- finally
- {
- if (resource != null)
- {
- try
- {
- resource.close();
- }
- catch (IOException e)
- {
- // do not shadow the real exception
- }
- }
- }
-
- String extractor = getRequiredProperty(config, props, "Extractor");
-
- try
- {
- Extractor extractorClass = (Extractor) Class.forName(extractor).newInstance();
- return createConfiguration(
- extractorClass,
- path);
- }
- catch (InstantiationException e)
- {
- throw new DynaFormException(e);
- }
- catch (IllegalAccessException e)
- {
- throw new DynaFormException(e);
- }
- catch (ClassNotFoundException e)
- {
- throw new DynaFormException(e);
- }
- catch (SecurityException e)
- {
- throw new DynaFormException(e);
- }
- catch (IllegalArgumentException e)
- {
- throw new DynaFormException(e);
- }
- }
-
- /**
- * load the configuration
- */
- protected InputStream findConfig(String config)
- {
- return getResourceAsStream("META-INF/" + config);
- }
-
- protected InputStream getResourceAsStream(String resource)
- {
- InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
- if (stream == null)
- {
- stream = UriResolver.class.getClassLoader().getResourceAsStream(resource);
- }
- return stream;
- }
-
- protected String getRequiredProperty(String config, Properties props, String key)
- {
- String value = props.getProperty(key);
- if (value == null)
- {
- throw new IllegalStateException("Configuration '" + key + "' missing in config " + config);
- }
- return value;
- }
+ */
+ protected Configuration resolve(String scheme, String path)
+ {
+ String config = "dynaForm-" + scheme + ".xml";
+ Properties props = new Properties();
+ InputStream resource = null;
+ try
+ {
+ resource = findConfig(config);
+ if (resource == null)
+ {
+ throw new DynaFormException("configuration '" + config + "' not found.");
+ }
+
+ props.loadFromXML(resource);
+ }
+ catch (InvalidPropertiesFormatException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (IOException e)
+ {
+ throw new DynaFormException(e);
+ }
+ finally
+ {
+ if (resource != null)
+ {
+ try
+ {
+ resource.close();
+ }
+ catch (IOException e)
+ {
+ // do not shadow the real exception
+ }
+ }
+ }
+
+ String extractor = getRequiredProperty(config, props, "Extractor");
+
+ try
+ {
+ Extractor extractorClass = (Extractor) Class.forName(extractor).newInstance();
+ return createConfiguration(
+ extractorClass,
+ path);
+ }
+ catch (InstantiationException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (ClassNotFoundException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (SecurityException e)
+ {
+ throw new DynaFormException(e);
+ }
+ catch (IllegalArgumentException e)
+ {
+ throw new DynaFormException(e);
+ }
+ }
+
+ /**
+ * load the configuration
+ */
+ protected InputStream findConfig(String config)
+ {
+ return getResourceAsStream("META-INF/" + config);
+ }
+
+ protected InputStream getResourceAsStream(String resource)
+ {
+ InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream(resource);
+ if (stream == null)
+ {
+ stream = UriResolver.class.getClassLoader().getResourceAsStream(resource);
+ }
+ return stream;
+ }
+
+ protected String getRequiredProperty(String config, Properties props, String key)
+ {
+ String value = props.getProperty(key);
+ if (value == null)
+ {
+ throw new IllegalStateException("Configuration '" + key + "' missing in config " + config);
+ }
+ return value;
+ }
}
Modified: myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestAsmHelper.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestAsmHelper.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestAsmHelper.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestAsmHelper.java Thu Jul 3 14:34:56 2008
@@ -28,13 +28,13 @@
*/
public class TestAsmHelper extends TestCase
{
- public void testSimple()
- {
- AsmHelper asmHelper = new AsmHelper();
+ public void testSimple()
+ {
+ AsmHelper asmHelper = new AsmHelper();
- Field[] fields = asmHelper.getFields(Bean.class);
- assertEquals(5, fields.length);
- assertEquals("propInt", fields[0].getName());
+ Field[] fields = asmHelper.getFields(Bean.class);
+ assertEquals(5, fields.length);
+ assertEquals("propInt", fields[0].getName());
assertEquals("propString", fields[1].getName());
assertEquals("propBool", fields[2].getName());
assertEquals("propBool2", fields[3].getName());
@@ -52,5 +52,5 @@
assertEquals("setPropDouble", methods[7].getName());
assertEquals("isPropBool2", methods[8].getName());
assertEquals("setPropBool2", methods[9].getName());
- }
+ }
}
\ No newline at end of file
Modified: myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestClassHelperFactory.java
URL: http://svn.apache.org/viewvc/myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestClassHelperFactory.java?rev=673822&r1=673821&r2=673822&view=diff
==============================================================================
--- myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestClassHelperFactory.java (original)
+++ myfaces/orchestra/trunk/sandbox/src/test/java/org/apache/myfaces/orchestra/dynaForm/metadata/impl/ejb/TestClassHelperFactory.java Thu Jul 3 14:34:56 2008
@@ -25,9 +25,9 @@
*/
public class TestClassHelperFactory extends TestCase
{
- public void testSimple()
- {
- ClassHelper h = ClassHelperFactory.newClassHelper();
- assertEquals(AsmHelper.class.getName(), h.getClass().getName());
- }
+ public void testSimple()
+ {
+ ClassHelper h = ClassHelperFactory.newClassHelper();
+ assertEquals(AsmHelper.class.getName(), h.getClass().getName());
+ }
}
\ No newline at end of file