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:58:25 UTC
svn commit: r673833 [18/18] - in /myfaces/tomahawk/trunk:
core/src/main/java/org/apache/myfaces/component/
core/src/main/java/org/apache/myfaces/component/html/ext/
core/src/main/java/org/apache/myfaces/component/html/util/
core/src/main/java/org/apach...
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/EjbExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/EjbExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/EjbExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/EjbExtractor.java Thu Jul 3 14:58:05 2008
@@ -66,613 +66,613 @@
*/
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" }));
-
- protected static class ContextInfo
- {
- private Boolean accessField;
- private String name;
- private boolean embedded;
-
- protected ContextInfo(final String name, final Boolean accessField, final boolean embedded)
- {
- super();
- this.name = name;
- this.accessField = accessField;
- this.embedded = embedded;
- }
- }
-
- protected static class Context
- {
- private boolean accessField = false;
- private Stack<ContextInfo> accessFields = new Stack<ContextInfo>();
- private int embeddLevel = 0;
-
- public void setAccessField(boolean accessField)
- {
- this.accessField = accessField;
- }
-
- public Boolean popAccessType()
- {
- return accessFields.pop().accessField;
- }
-
- public boolean getAccessField()
- {
- return accessField;
- }
-
- protected void startEmbedded(final String name, final boolean embedded)
- {
- embeddLevel++;
-
- String contextName = name;
- if (!accessFields.isEmpty())
- {
- contextName = accessFields.peek().name + "." + name;
- }
-
- accessFields.push(new ContextInfo(contextName, accessField, embedded));
- }
-
- 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 EjbExtractor()
- {
- }
-
- /**
- * the entity name as string
- */
- public void getMetaData(MetaData 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.
- */
- protected void createClassList(List<Class> classes, Class clazz)
- {
- Class superClass = clazz.getSuperclass();
- 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, MetaData 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)
- {
- 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));
- }
- }
- }
-
- 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, MetaData metaData, Field[] fields)
- {
- for (Field field : fields)
- {
- if (!validModifier(field.getModifiers(), false)
- || field.isSynthetic()
- || hasAnnotationTransient(field))
- {
- continue;
- }
- String name = field.getName();
- Class type = field.getType();
-
- if (metaData.processField(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, MetaData 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.processFieldParent(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;
- }
-
- MetaData.FieldImpl 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, MetaData metaData, AccessibleObject accessibleObject, String name, Class<?> type)
- {
- if (accessibleObject.isAnnotationPresent(Embedded.class) || accessibleObject.isAnnotationPresent(Id.class))
- {
- if (type.isAnnotationPresent(Embeddable.class) || type.isAnnotationPresent(MappedSuperclass.class))
- {
- // process embedded type
- try
- {
- context.startEmbedded(name, true);
- create(context, metaData, type);
- }
- finally
- {
- context.endEmbedded();
- }
- return true;
- }
- }
-
- return false;
- }
-
- /**
- * check if we should embedd this entity
- */
- protected boolean checkEmbeddEntity(Context context, MetaData 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, MetaData 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);
- create(context, metaData, entityType);
- }
- finally
- {
- context.endEmbedded();
- metaData.setLockFields(previousLock);
- }
- }
-
- /**
- * init metadata from annotations
- */
- protected void initFromAnnotations(Context context, MetaData.FieldImpl 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(Column.class))
- {
- // is required
- Column column = accessibleObject.getAnnotation(Column.class);
- mdField.setRequired(!column.nullable());
- }
-
- 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);
- }
- if (accessibleObject.isAnnotationPresent(OneToMany.class))
- {
- mdField.setRelationType(RelationType.ONE_TO_MANY);
- }
- if (accessibleObject.isAnnotationPresent(ManyToOne.class))
- {
- mdField.setRelationType(RelationType.MANY_TO_ONE);
- }
- 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());
- }
-
- // 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.custom.dynaForm.annot.ui.Temporal.class))
- {
- org.apache.myfaces.custom.dynaForm.annot.ui.Temporal temporal = accessibleObject.getAnnotation(org.apache.myfaces.custom.dynaForm.annot.ui.Temporal.class);
- mdField.setTemporalType(temporal.value());
- }
-
- Class<?> type = mdField.getType();
- if (type.isAnnotationPresent(Entity.class))
- {
- mdField.setEntityType(true);
- }
+ private final static Set<String> SYSTEM_METHODS = new TreeSet<String>(
+ Arrays.asList(new String[]
+ { "hashCode", "getClass", "wait", "equals", "notify", "notifyAll",
+ "toString" }));
+
+ protected static class ContextInfo
+ {
+ private Boolean accessField;
+ private String name;
+ private boolean embedded;
+
+ protected ContextInfo(final String name, final Boolean accessField, final boolean embedded)
+ {
+ super();
+ this.name = name;
+ this.accessField = accessField;
+ this.embedded = embedded;
+ }
+ }
+
+ protected static class Context
+ {
+ private boolean accessField = false;
+ private Stack<ContextInfo> accessFields = new Stack<ContextInfo>();
+ private int embeddLevel = 0;
+
+ public void setAccessField(boolean accessField)
+ {
+ this.accessField = accessField;
+ }
+
+ public Boolean popAccessType()
+ {
+ return accessFields.pop().accessField;
+ }
+
+ public boolean getAccessField()
+ {
+ return accessField;
+ }
+
+ protected void startEmbedded(final String name, final boolean embedded)
+ {
+ embeddLevel++;
+
+ String contextName = name;
+ if (!accessFields.isEmpty())
+ {
+ contextName = accessFields.peek().name + "." + name;
+ }
+
+ accessFields.push(new ContextInfo(contextName, accessField, embedded));
+ }
+
+ 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 EjbExtractor()
+ {
+ }
+
+ /**
+ * the entity name as string
+ */
+ public void getMetaData(MetaData 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.
+ */
+ protected void createClassList(List<Class> classes, Class clazz)
+ {
+ Class superClass = clazz.getSuperclass();
+ 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, MetaData 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)
+ {
+ 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));
+ }
+ }
+ }
+
+ 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, MetaData metaData, Field[] fields)
+ {
+ for (Field field : fields)
+ {
+ if (!validModifier(field.getModifiers(), false)
+ || field.isSynthetic()
+ || hasAnnotationTransient(field))
+ {
+ continue;
+ }
+ String name = field.getName();
+ Class type = field.getType();
+
+ if (metaData.processField(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, MetaData 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.processFieldParent(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;
+ }
+
+ MetaData.FieldImpl 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, MetaData metaData, AccessibleObject accessibleObject, String name, Class<?> type)
+ {
+ if (accessibleObject.isAnnotationPresent(Embedded.class) || accessibleObject.isAnnotationPresent(Id.class))
+ {
+ if (type.isAnnotationPresent(Embeddable.class) || type.isAnnotationPresent(MappedSuperclass.class))
+ {
+ // process embedded type
+ try
+ {
+ context.startEmbedded(name, true);
+ create(context, metaData, type);
+ }
+ finally
+ {
+ context.endEmbedded();
+ }
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ /**
+ * check if we should embedd this entity
+ */
+ protected boolean checkEmbeddEntity(Context context, MetaData 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, MetaData 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);
+ create(context, metaData, entityType);
+ }
+ finally
+ {
+ context.endEmbedded();
+ metaData.setLockFields(previousLock);
+ }
+ }
+
+ /**
+ * init metadata from annotations
+ */
+ protected void initFromAnnotations(Context context, MetaData.FieldImpl 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(Column.class))
+ {
+ // is required
+ Column column = accessibleObject.getAnnotation(Column.class);
+ mdField.setRequired(!column.nullable());
+ }
+
+ 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);
+ }
+ if (accessibleObject.isAnnotationPresent(OneToMany.class))
+ {
+ mdField.setRelationType(RelationType.ONE_TO_MANY);
+ }
+ if (accessibleObject.isAnnotationPresent(ManyToOne.class))
+ {
+ mdField.setRelationType(RelationType.MANY_TO_ONE);
+ }
+ 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());
+ }
+
+ // 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.custom.dynaForm.annot.ui.Temporal.class))
+ {
+ org.apache.myfaces.custom.dynaForm.annot.ui.Temporal temporal = accessibleObject.getAnnotation(org.apache.myfaces.custom.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());
- }
- }
-
- /**
- * configure a special fields as disabled. e.g. used for Id, Version, ....
- */
- protected void setSpecialFieldDisabled(MetaData.FieldImpl mdField)
- {
- mdField.setCanWrite(false);
- mdField.setDisabled(true);
- }
-
- /**
- * ejb3 access through methods (properties)
- */
- protected void initFromMethods(Context context, MetaData metaData, Method[] methods)
- {
- for (Method method : methods)
- {
- if (!validModifier(method.getModifiers(), true)
- || method.isSynthetic()
- || hasAnnotationTransient(method)
- || SYSTEM_METHODS.contains(method.getName()))
- {
- continue;
- }
- String methodName = method.getName();
- String propertyName = convertMethodName(methodName);
-
- if (!metaData.processField(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.processField(createFullName(context, propertyName)))
- {
- processField(context, metaData, method, propertyName, method.getParameterTypes()[0], null, true);
- }
- }
- }
- }
-
- @SuppressWarnings("unchecked")
- protected void initFromType(Context context, org.apache.myfaces.custom.dynaForm.metadata.MetaData.FieldImpl 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;
- }
+ {
+ 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());
+ }
+ }
+
+ /**
+ * configure a special fields as disabled. e.g. used for Id, Version, ....
+ */
+ protected void setSpecialFieldDisabled(MetaData.FieldImpl mdField)
+ {
+ mdField.setCanWrite(false);
+ mdField.setDisabled(true);
+ }
+
+ /**
+ * ejb3 access through methods (properties)
+ */
+ protected void initFromMethods(Context context, MetaData metaData, Method[] methods)
+ {
+ for (Method method : methods)
+ {
+ if (!validModifier(method.getModifiers(), true)
+ || method.isSynthetic()
+ || hasAnnotationTransient(method)
+ || SYSTEM_METHODS.contains(method.getName()))
+ {
+ continue;
+ }
+ String methodName = method.getName();
+ String propertyName = convertMethodName(methodName);
+
+ if (!metaData.processField(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.processField(createFullName(context, propertyName)))
+ {
+ processField(context, metaData, method, propertyName, method.getParameterTypes()[0], null, true);
+ }
+ }
+ }
+ }
+
+ @SuppressWarnings("unchecked")
+ protected void initFromType(Context context, org.apache.myfaces.custom.dynaForm.metadata.MetaData.FieldImpl 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/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/JavaHelper.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/JavaHelper.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/JavaHelper.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/ejb/JavaHelper.java Thu Jul 3 14:58:05 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/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/hibernate/HibernateExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/hibernate/HibernateExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/hibernate/HibernateExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/hibernate/HibernateExtractor.java Thu Jul 3 14:58:05 2008
@@ -28,40 +28,40 @@
*/
public class HibernateExtractor extends EjbExtractor
{
- @Override
- protected void initFromAnnotations(Context context, FieldImpl mdField, AccessibleObject accessibleObject)
- {
+ @Override
+ protected void initFromAnnotations(Context context, FieldImpl 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());
- }
- */
- }
+ {
+ 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/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/AbstractJsfExtractor.java Thu Jul 3 14:58:05 2008
@@ -32,50 +32,50 @@
*/
public abstract class AbstractJsfExtractor implements Extractor
{
- public AbstractJsfExtractor()
- {
- }
+ public AbstractJsfExtractor()
+ {
+ }
- public void getMetaData(MetaData metaData, Object entity)
- {
- if (!(entity instanceof DynaForm))
- {
- throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
- }
-
- create(metaData, (DynaForm) entity);
- }
+ public void getMetaData(MetaData 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(MetaData 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.processField(name))
- {
- MetaData.FieldImpl field = metaData.getOrCreateField(name);
-
- initFromConfig(field, dynaConfig);
- }
- }
- }
+ /**
+ * create the metadata out of the dynaConfigs for the given component
+ */
+ @SuppressWarnings("unchecked")
+ protected void create(MetaData 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.processField(name))
+ {
+ MetaData.FieldImpl field = metaData.getOrCreateField(name);
+
+ initFromConfig(field, dynaConfig);
+ }
+ }
+ }
- protected abstract void initFromConfig(MetaData.FieldImpl field, DynaConfig config);
+ protected abstract void initFromConfig(MetaData.FieldImpl field, DynaConfig config);
}
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExclusiveExtractor.java Thu Jul 3 14:58:05 2008
@@ -29,11 +29,11 @@
*/
public class JsfExclusiveExtractor extends AbstractJsfExtractor
{
- public JsfExclusiveExtractor()
- {
- }
+ public JsfExclusiveExtractor()
+ {
+ }
- protected void initFromConfig(MetaData.FieldImpl field, DynaConfig config)
- {
- }
+ protected void initFromConfig(MetaData.FieldImpl field, DynaConfig config)
+ {
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfExtractor.java Thu Jul 3 14:58:05 2008
@@ -28,12 +28,12 @@
*/
public class JsfExtractor extends AbstractJsfExtractor
{
- public JsfExtractor()
- {
- }
+ public JsfExtractor()
+ {
+ }
- protected void initFromConfig(MetaData.FieldImpl field, DynaConfig config)
- {
- config.configureMetaData(field);
- }
+ protected void initFromConfig(MetaData.FieldImpl field, DynaConfig config)
+ {
+ config.configureMetaData(field);
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/impl/jsf/JsfRequestFieldExtractor.java Thu Jul 3 14:58:05 2008
@@ -34,46 +34,46 @@
*/
public class JsfRequestFieldExtractor implements Extractor
{
- public JsfRequestFieldExtractor()
- {
- }
+ public JsfRequestFieldExtractor()
+ {
+ }
- public void getMetaData(MetaData metaData, Object entity)
- {
- if (!(entity instanceof DynaForm))
- {
- throw new IllegalArgumentException("passed entity argument not a DynaForm: " + entity);
- }
-
- create(metaData, (DynaForm) entity);
- }
+ public void getMetaData(MetaData 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(MetaData 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.processField(name))
- {
- metaData.requestField(name);
- }
- }
- }
+ /**
+ * create the metadata out of the dynaConfigs for the given component
+ */
+ @SuppressWarnings("unchecked")
+ protected void create(MetaData 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.processField(name))
+ {
+ metaData.requestField(name);
+ }
+ }
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/utils/TypeInfos.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/utils/TypeInfos.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/utils/TypeInfos.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/metadata/utils/TypeInfos.java Thu Jul 3 14:58:05 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/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/FacesUriResolver.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/FacesUriResolver.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/FacesUriResolver.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/FacesUriResolver.java Thu Jul 3 14:58:05 2008
@@ -27,16 +27,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;
- }
-
- return super.findConfig(config);
- }
-
+ @Override
+ protected InputStream findConfig(String config)
+ {
+ InputStream is = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream("/WEB-INF/" + config);
+ if (is != null)
+ {
+ return is;
+ }
+
+ return super.findConfig(config);
+ }
+
}
Modified: myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/UriResolver.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/UriResolver.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/UriResolver.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/core/src/main/java/org/apache/myfaces/custom/dynaForm/uri/UriResolver.java Thu Jul 3 14:58:05 2008
@@ -31,157 +31,157 @@
*/
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(":");
+ /**
+ * 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));
- }
-
- /**
- * do the hard work
- */
- 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;
- }
+ {
+ throw new IllegalArgumentException("Invalid uri: " + uri);
+ }
+
+ return resolve(uri.substring(0, pos), uri.substring(pos+1));
+ }
+
+ /**
+ * do the hard work
+ */
+ 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/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/SimpleBeanBacking.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/SimpleBeanBacking.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/SimpleBeanBacking.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/SimpleBeanBacking.java Thu Jul 3 14:58:05 2008
@@ -27,7 +27,7 @@
public class SimpleBeanBacking
{
- private PersonRelation personRelation;
+ private PersonRelation personRelation;
private Person person;
private List<Person> persons;
@@ -39,17 +39,17 @@
protected void initBean()
{
person = new Person();
- person.setId(666L);
+ person.setId(666L);
- Person s1 = new Person();
- s1.setId(4711L);
- s1.setCheckedData(true);
+ Person s1 = new Person();
+ s1.setId(4711L);
+ s1.setCheckedData(true);
s1.setCreationDate(new Date());
s1.setAge(1L);
s1.setUserName("bean 1");
Person s2 = new Person();
- s2.setId(815L);
- s2.setCheckedData(true);
+ s2.setId(815L);
+ s2.setCheckedData(true);
s2.setCreationDate(new Date());
s2.setAge(2L);
s2.setUserName("bean 2");
@@ -58,8 +58,8 @@
persons.add(s1);
persons.add(s2);
- personRelation = new PersonRelation();
- }
+ personRelation = new PersonRelation();
+ }
public Person getPerson()
{
@@ -79,15 +79,15 @@
public void setPersons(List<Person> persons)
{
this.persons = persons;
- }
+ }
- public PersonRelation getPersonRelation()
- {
- return personRelation;
- }
-
- public void setPersonRelation(PersonRelation personRelation)
- {
- this.personRelation = personRelation;
- }
+ public PersonRelation getPersonRelation()
+ {
+ return personRelation;
+ }
+
+ public void setPersonRelation(PersonRelation personRelation)
+ {
+ this.personRelation = personRelation;
+ }
}
\ No newline at end of file
Modified: myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/Person.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/Person.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/Person.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/Person.java Thu Jul 3 14:58:05 2008
@@ -27,9 +27,9 @@
public class Person implements Serializable
{
- private Long id;
+ private Long id;
- private String userName;
+ private String userName;
private long age;
private Date creationDate;
private Date birthday;
@@ -37,18 +37,18 @@
private String description;
private boolean checkedData;
- @DisplayOnly
- public Long getId()
- {
- return id;
- }
-
- public void setId(Long id)
- {
- this.id = id;
- }
+ @DisplayOnly
+ public Long getId()
+ {
+ return id;
+ }
- public String getUserName()
+ public void setId(Long id)
+ {
+ this.id = id;
+ }
+
+ public String getUserName()
{
return userName;
}
@@ -119,11 +119,11 @@
this.description = description;
}
- @Override
- public boolean equals(Object o)
- {
- Person p = (Person) o;
+ @Override
+ public boolean equals(Object o)
+ {
+ Person p = (Person) o;
- return id.equals(p.id);
- }
+ return id.equals(p.id);
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonProvider.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonProvider.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonProvider.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonProvider.java Thu Jul 3 14:58:05 2008
@@ -23,38 +23,38 @@
public class PersonProvider
{
- public List<Person> persons = new ArrayList<Person>();
+ public List<Person> persons = new ArrayList<Person>();
- public PersonProvider()
- {
- for (int i=0;i<20; i++)
- {
- persons.add(createPersonFake("dummy", i));
- }
- }
-
- public List<Person> getSearchPersons(String searchString)
- {
- return persons;
- }
-
- private Person createPersonFake(String search, long count)
- {
- Person p = new Person();
- p.setId(count);
- p.setUserName(search + " " + count);
- p.setAge(count);
- p.setMartialStatus(MartialStatus.MARRIED);
- return p;
- }
-
- public String getPersonDescription(Person person)
- {
- if (person == null)
- {
- return "#null?";
- }
+ public PersonProvider()
+ {
+ for (int i=0;i<20; i++)
+ {
+ persons.add(createPersonFake("dummy", i));
+ }
+ }
+
+ public List<Person> getSearchPersons(String searchString)
+ {
+ return persons;
+ }
+
+ private Person createPersonFake(String search, long count)
+ {
+ Person p = new Person();
+ p.setId(count);
+ p.setUserName(search + " " + count);
+ p.setAge(count);
+ p.setMartialStatus(MartialStatus.MARRIED);
+ return p;
+ }
+
+ public String getPersonDescription(Person person)
+ {
+ if (person == null)
+ {
+ return "#null?";
+ }
- return person.getUserName() + ", " + person.getAge();
- }
+ return person.getUserName() + ", " + person.getAge();
+ }
}
Modified: myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonRelation.java
URL: http://svn.apache.org/viewvc/myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonRelation.java?rev=673833&r1=673832&r2=673833&view=diff
==============================================================================
--- myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonRelation.java (original)
+++ myfaces/tomahawk/trunk/sandbox15/examples/src/main/java/org/apache/myfaces/examples/dynaForm/lib/PersonRelation.java Thu Jul 3 14:58:05 2008
@@ -31,51 +31,51 @@
public class PersonRelation implements Serializable
{
- private Person person1;
- private Person person2;
- private Date liveTogetherSince;
-
- @NotNull
- @ManyToOne
- @DataProvider(
- value="#{personProvider.getSearchPersons}",
- description="#{personProvider.getPersonDescription}"
- )
- public Person getPerson1()
- {
- return person1;
- }
-
- public void setPerson1(Person person1)
- {
- this.person1 = person1;
- }
-
- @NotNull
- @ManyToOne
- @UIComponent(type= ComponentEnum.SelectOneMenu)
- @DataProvider(
- value="#{personProvider.getSearchPersons}",
- description="#{personProvider.getPersonDescription}"
- )
- public Person getPerson2()
- {
- return person2;
- }
-
- public void setPerson2(Person person2)
- {
- this.person2 = person2;
- }
-
- @Temporal(value=TemporalType.DATE)
- public Date getLiveTogetherSince()
- {
- return liveTogetherSince;
- }
-
- public void setLiveTogetherSince(Date liveTogetherSince)
- {
- this.liveTogetherSince = liveTogetherSince;
- }
+ private Person person1;
+ private Person person2;
+ private Date liveTogetherSince;
+
+ @NotNull
+ @ManyToOne
+ @DataProvider(
+ value="#{personProvider.getSearchPersons}",
+ description="#{personProvider.getPersonDescription}"
+ )
+ public Person getPerson1()
+ {
+ return person1;
+ }
+
+ public void setPerson1(Person person1)
+ {
+ this.person1 = person1;
+ }
+
+ @NotNull
+ @ManyToOne
+ @UIComponent(type= ComponentEnum.SelectOneMenu)
+ @DataProvider(
+ value="#{personProvider.getSearchPersons}",
+ description="#{personProvider.getPersonDescription}"
+ )
+ public Person getPerson2()
+ {
+ return person2;
+ }
+
+ public void setPerson2(Person person2)
+ {
+ this.person2 = person2;
+ }
+
+ @Temporal(value=TemporalType.DATE)
+ public Date getLiveTogetherSince()
+ {
+ return liveTogetherSince;
+ }
+
+ public void setLiveTogetherSince(Date liveTogetherSince)
+ {
+ this.liveTogetherSince = liveTogetherSince;
+ }
}