Author: tchemit Date: 2012-11-13 11:29:53 +0100 (Tue, 13 Nov 2012) New Revision: 1204 Url: http://nuiton.org/repositories/revision/eugene/1204 Log: reuse the getChild method to avoid linkage with nuiton-utils + improve doc Modified: trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java Modified: trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java =================================================================== --- trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2012-11-13 10:24:38 UTC (rev 1203) +++ trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2012-11-13 10:29:53 UTC (rev 1204) @@ -33,7 +33,6 @@ import org.nuiton.eugene.models.object.ObjectModelInterface; import org.nuiton.eugene.models.object.ObjectModelJavaModifier; import org.nuiton.eugene.models.object.ObjectModelOperation; -import org.nuiton.util.CollectionUtil; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; @@ -187,7 +186,12 @@ // Add helper operations if (hasAMultipleProperty) { - addImport(output, CollectionUtil.class); + if (!superClassIsBean) { + + // add getChild methods + createGetChildMethod(output); + } + } } @@ -446,7 +450,7 @@ addParameter(operation, "int", "index"); setOperationBody(operation, "" /*{ - <%=simpleType%> o = CollectionUtil.getOrNull(<%=attrName%>, index); + <%=simpleType%> o = getChild(<%=attrName%>, index); return o; }*/ ); @@ -853,4 +857,36 @@ ); } + protected void createGetChildMethod(ObjectModelClass output) { + ObjectModelOperation getChild = addOperation( + output, + "getChild", "<T> T", + ObjectModelJavaModifier.PROTECTED + ); + addParameter(getChild, "java.util.Collection<T>", "childs"); + addParameter(getChild, "int", "index"); + setOperationBody(getChild, "" +/*{ + T result = null; + if (childs != null) { + if (childs instanceof List) { + if (index < childs.size()) { + result = ((List<T>) childs).get(index); + } + } else { + int i = 0; + for (T o : childs) { + if (index == i) { + result = o; + break; + } + i++; + } + } + } + return result; +}*/ + ); + } + } \ No newline at end of file Modified: trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java =================================================================== --- trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java 2012-11-13 10:24:38 UTC (rev 1203) +++ trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaTemplatesTagValues.java 2012-11-13 10:29:53 UTC (rev 1204) @@ -57,7 +57,11 @@ * If the bean needs Property change support (says you do not add the {@link #TAG_NO_PCS} on classifier or model, * then your class must provide evrything for it. * <p/> - * See newt code to know minimum stuff to add in your class for this purpose). + * More over, if you use some collections in your bean you must also define + * two method named {@code getChild(Collection list, int index)} and + * {@code getChild(List list, int index)} + * <p/> + * See new code to know minimum stuff to add in your class for this purpose. * <pre> * public abstract class AbstractBean implements Serializable { * @@ -89,6 +93,13 @@ * firePropertyChange(propertyName, null, newValue); * } * + * protected <T> T getChild(Collection<T> list, int index) { + * return CollectionUtil.getOrNull(list, index); + * } + * + * protected <T> T getChild(List<T> list, int index) { + * return CollectionUtil.getOrNull(list, index); + * } * } * </pre> * <p/> @@ -99,7 +110,7 @@ */ @ModelPropertiesUtil.TagValueDefinition( target = {ObjectModel.class, ObjectModelClassifier.class}, - documentation = "To specify a super-class to place on generated bean " + + documentation = "To specify a super-class to used on generated bean " + "for a class or any class of a model") String TAG_BEAN_SUPER_CLASS = "beanSuperClass"; }