Author: tchemit Date: 2012-10-28 13:29:21 +0100 (Sun, 28 Oct 2012) New Revision: 1196 Url: http://nuiton.org/repositories/revision/eugene/1196 Log: refs #2385: Improve JavaBean generation template Modified: trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.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-10-28 12:28:48 UTC (rev 1195) +++ trunk/eugene-java-templates/src/main/java/org/nuiton/eugene/java/JavaBeanTransformer.java 2012-10-28 12:29:21 UTC (rev 1196) @@ -34,6 +34,7 @@ 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; @@ -162,13 +163,14 @@ // Add property change support createPropertyChangeSupport(output); } + } - boolean hasAMultipleProperty = containsMutiple(properties); + boolean hasAMultipleProperty = containsMutiple(properties); - // Add helper operations - if (hasAMultipleProperty) { - createGetChildMethod(output); - } + // Add helper operations + if (hasAMultipleProperty) { + + addImport(output, CollectionUtil.class); } } @@ -401,13 +403,13 @@ String attrType, String methodPrefix) { - ObjectModelOperation getter = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName(methodPrefix , attrName), attrType, ObjectModelJavaModifier.PUBLIC ); - setOperationBody(getter, "" + setOperationBody(operation, "" /*{ return <%=attrName%>; }*/ @@ -418,16 +420,16 @@ String attrName, String attrType, String simpleType) { - ObjectModelOperation getChild = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName("get", attrName), attrType, ObjectModelJavaModifier.PUBLIC ); - addParameter(getChild, "int", "index"); - setOperationBody(getChild, "" + addParameter(operation, "int", "index"); + setOperationBody(operation, "" /*{ - <%=simpleType%> o = getChild(<%=attrName%>, index); + <%=simpleType%> o = CollectionUtil.get(<%=attrName%>, index); return o; }*/ ); @@ -435,13 +437,13 @@ protected void createIsEmptyMethod(ObjectModelClass output, String attrName) { - ObjectModelOperation getChild = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName("is", attrName)+"Empty", boolean.class, ObjectModelJavaModifier.PUBLIC ); - setOperationBody(getChild, "" + setOperationBody(operation, "" /*{ return <%=attrName%> == null || <%=attrName%>.isEmpty(); }*/ @@ -450,13 +452,13 @@ protected void createSizeMethod(ObjectModelClass output, String attrName) { - ObjectModelOperation getChild = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName("size", attrName), int.class, ObjectModelJavaModifier.PUBLIC ); - setOperationBody(getChild, "" + setOperationBody(operation, "" /*{ return <%=attrName%> == null ? 0 : <%=attrName%>.size(); }*/ @@ -467,13 +469,13 @@ String attrType, String constantName, boolean usePCS) { - ObjectModelOperation addChild = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName("add", attrName), "void", ObjectModelJavaModifier.PUBLIC ); - addParameter(addChild, attrType, attrName); + addParameter(operation, attrType, attrName); String methodName = getJavaBeanMethodName("get", attrName); StringBuilder buffer = new StringBuilder("" @@ -487,7 +489,7 @@ }*/ ); } - setOperationBody(addChild, buffer.toString()); + setOperationBody(operation, buffer.toString()); } protected void createAddAllChildrenMethod(ObjectModelClass output, @@ -495,13 +497,13 @@ String attrType, String constantName, boolean usePCS) { - ObjectModelOperation addAllChild = addOperation( + ObjectModelOperation operation = addOperation( output, getJavaBeanMethodName("addAll", attrName), "void", ObjectModelJavaModifier.PUBLIC ); - addParameter(addAllChild, "java.util.Collection<" + attrType + ">", attrName); + addParameter(operation, "java.util.Collection<" + attrType + ">", attrName); String methodName = getJavaBeanMethodName("get", attrName); StringBuilder buffer = new StringBuilder("" @@ -515,7 +517,7 @@ }*/ ); } - setOperationBody(addAllChild, buffer.toString()); + setOperationBody(operation, buffer.toString()); } protected void createRemoveChildMethod(ObjectModelClass output, @@ -669,36 +671,6 @@ } } - 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) { - result = ((List<T>) childs).get(index); - } else { - int i = 0; - for (T o : childs) { - if (index == i) { - result = o; - break; - } - i++; - } - } - } - return result; - }*/ - ); - } - protected void addSerializable(ObjectModelClass input, ObjectModelClass output, boolean interfaceFound) {