Author: fdesbois Date: 2010-06-25 12:28:33 +0200 (Fri, 25 Jun 2010) New Revision: 2029 Url: http://nuiton.org/repositories/revision/topia/2029 Log: Evo #609 : Refactor generation for properties operations (association class are not considered in refactor yet). Generation is still working as before. Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java =================================================================== --- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-24 22:43:33 UTC (rev 2028) +++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-25 10:28:33 UTC (rev 2029) @@ -43,6 +43,7 @@ import org.nuiton.topia.persistence.EntityVisitor; import org.nuiton.topia.persistence.TopiaEntity; import org.nuiton.topia.persistence.TopiaEntityAbstract; +import org.nuiton.topia.persistence.util.TopiaEntityHelper; import java.beans.Introspector; import java.net.URL; @@ -51,13 +52,10 @@ import java.util.List; import java.util.Set; -import static org.nuiton.eugene.GeneratorUtil.getSimpleName; import static org.nuiton.topia.generator.TopiaGeneratorUtil.STEREOTYPE_ENTITY; import static org.nuiton.topia.generator.TopiaGeneratorUtil.TAG_ANNOTATION; import static org.nuiton.topia.generator.TopiaGeneratorUtil.TAG_DB_NAME; import static org.nuiton.topia.generator.TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType; -import static org.nuiton.topia.generator.TopiaGeneratorUtil.isDateType; -import static org.nuiton.topia.generator.TopiaGeneratorUtil.isPrimitiveType; import static org.nuiton.topia.generator.TopiaGeneratorUtil.shouldBeAbstract; @@ -142,26 +140,11 @@ outputInterface = createInterface(clazzName, packageName); outputAbstract = createAbstractClass(clazzName + "Abstract", packageName); + // generateOperationsFromAttributes(input.getAttributes()); is executed in generateInterface + generateInterface(input, outputInterface, attributes, operations); generateAbstract(input, outputAbstract, attributes, operations); -// ObjectModelClassifier output; -// -// // generate interface -// -// { -// outputInterface = createInterface(clazzName, packageName); -// generateInterface(input, outputInterface, attributes, operations); -// } -// -// // generate abstract -// -// { -// outputAbstract = createAbstractClass( clazzName + "Abstract", packageName); -// generateAbstract(input, outputAbstract, attributes, operations); -// -// } - boolean generateImpl = isGenerateImpl(input, operations); if (generateImpl) { @@ -225,6 +208,539 @@ return true; } + protected void generateOperationsFromAttributes(Collection<ObjectModelAttribute> attributes) { + + for (ObjectModelAttribute attribute : attributes) { + + if (!attribute.isNavigable() && + !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType( + attribute.getReverseAttribute(), model)) { + continue; + } + + // Don't manage association class for instance + if (attribute.hasAssociationClass()) { + continue; + } + + if (attribute.getMaxMultiplicity() == 1) { + + // setXXX + addSimpleSetOperation(attribute); + + // getXXX + addSimpleGetOperation(attribute, null); + + } else { + + // List, Set or Collection ? + String collectionInterface = + TopiaGeneratorUtil.getNMultiplicityInterfaceType(attribute); + String collectionImpl = + TopiaGeneratorUtil.getNMultiplicityObjectType(attribute); + + addImport(outputInterface, collectionInterface); + addImport(outputAbstract, collectionInterface); + addImport(outputAbstract, collectionImpl); + + collectionInterface = + TopiaGeneratorUtil.getSimpleName(collectionInterface); + collectionImpl = + TopiaGeneratorUtil.getSimpleName(collectionImpl); + + // addXXX + addMultipleAddOperation(attribute, collectionImpl); + + // addAllXXX + addMultipleAddAllOperation(attribute, collectionInterface); + + // setXXX + addMultipleSetOperation(attribute, collectionInterface); + + // removeXXX + addMultipleRemoveOperation(attribute); + + // clearXXX + addMultipleClearOperation(attribute, collectionInterface, collectionImpl); + + // getXXX + addMultipleGetOperation(attribute, collectionInterface); + + if (!TopiaGeneratorUtil.isPrimitiveType(attribute) && + !TopiaGeneratorUtil.isDateType(attribute)) { + + // getXXXByTopiaId + addMultipleGetTopiaIdOperation(attribute); + } + + // sizeXXX + addMultipleSizeOperation(attribute); + + // isXXXEmpty + addMultipleIsEmptyOperation(attribute); + } + + } + } + + // TODO-fdesbois-2010-06-25 : This method can be put in JavaBuilder or ObjectModelTransformerToJava + protected ObjectModelOperation createPropertySetterSignature(ObjectModelClassifier classifier, + String propertyType, + String propertyName, + String operationDocumentation) { + // Operation + ObjectModelOperation operation = + addOperation(classifier, "set" + StringUtils.capitalize(propertyName), + void.class, ObjectModelModifier.PACKAGE); + + ObjectModelParameter param = + addParameter(operation, propertyType, propertyName); + + // Documentation + if (StringUtils.isNotEmpty(operationDocumentation)) { + setDocumentation(operation, operationDocumentation); + } + setDocumentation(param, "La valeur de l'attribut à positionner."); + + return operation; + } + + protected void addSimpleSetOperation(ObjectModelAttribute attribute) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + + // Interface operation + ObjectModelOperation interfaceOperation = + createPropertySetterSignature(outputInterface, attrType, attrName, + attribute.getDocumentation()); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + <%=attrType%> oldValue = this.<%=attrName%>; + fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>); + this.<%=attrName%> = <%=attrName%>; + fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>); +}*/ + ); + } + + /** + * Add getter for simple property (neither association nor multiple). + * Will add two different operations for boolean case ('is' method and + * 'get' method). This method add the operation in both {@code + * outputAbstract} and {@code outputInterface}. + * + * @param attribute ObjectModelAttribute for getter operation + * @param operationPrefix Operation prefix : 'get' by default, if prefix + * is null + */ + protected void addSimpleGetOperation(ObjectModelAttribute attribute, + String operationPrefix) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + + if (operationPrefix == null) { + operationPrefix = TopiaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX; + } + + if (log.isDebugEnabled()) { + log.debug("Add getter operation for " + attrName + + " prefix = " + operationPrefix); + } + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, operationPrefix + StringUtils.capitalize(attrName), + attrType, ObjectModelModifier.PACKAGE); + + // Documentation + if (TopiaGeneratorUtil.hasDocumentation(attribute)) { + setDocumentation(interfaceOperation, attribute.getDocumentation()); + } + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + fireOnPreRead(<%=getConstantName(attrName)%>, <%=attrName%>); + <%=attrType%> result = this.<%=attrName%>; + fireOnPostRead(<%=getConstantName(attrName)%>, <%=attrName%>); + return result; +}*/ + ); + + // Generate 'is' getter for boolean attributes + if (attrType.toLowerCase().contains("boolean") && + !operationPrefix.equals(TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX)) { + addSimpleGetOperation(attribute, + TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX); + } + } + + protected void addMultipleAddOperation(ObjectModelAttribute attribute, String collectionImpl) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + ObjectModelAttribute reverse = attribute.getReverseAttribute(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "add" + StringUtils.capitalize(attrName), + void.class, ObjectModelModifier.PACKAGE); + ObjectModelParameter param = + addParameter(interfaceOperation, attrType, attrName); + + // Documentation + if (TopiaGeneratorUtil.hasDocumentation(attribute)) { + setDocumentation(interfaceOperation, attribute.getDocumentation()); + } + setDocumentation(param, "L'instance de " + attrType + " à ajouter"); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + StringBuilder body = new StringBuilder(); + + body.append("" +/*{ + fireOnPreWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>); + if (this.<%=attrName%> == null) { + this.<%=attrName%> = new <%=collectionImpl%><<%=attrType%>>(); + } +}*/ + ); + + if (reverse != null && (reverse.isNavigable() || + hasUnidirectionalRelationOnAbstractType(attribute, model))) { + String reverseAttrName = StringUtils.capitalize(reverse.getName()); + String reverseAttrType = TopiaGeneratorUtil.getSimpleName(reverse.getType()); + if (!GeneratorUtil.isNMultiplicity(reverse)) { + body.append("" +/*{ + <%=attrName%>.set<%=reverseAttrName%>(this); +}*/ + ); + } else { + body.append("" +/*{ + if (<%=attrName%>.get<%=reverseAttrName%>() == null) { + <%=attrName%>.set<%=reverseAttrName%>(new <%=collectionImpl%><<%=reverseAttrType%>>()); + } + <%=attrName%>.get<%=reverseAttrName%>().add(this); +}*/ + ); + } + } + body.append("" +/*{ + this.<%=attrName%>.add(<%=attrName%>); + fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size(), null, <%=attrName%>); +}*/ + ); + setOperationBody(implOperation, body.toString()); + } + + protected void addMultipleAddAllOperation(ObjectModelAttribute attribute, String collectionInterface) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "addAll" + StringUtils.capitalize(attrName), + void.class, ObjectModelModifier.PACKAGE); + ObjectModelParameter param = + addParameter(interfaceOperation, collectionInterface + "<" + attrType + ">", attrName); + + // Documentation + if (TopiaGeneratorUtil.hasDocumentation(attribute)) { + setDocumentation(interfaceOperation, attribute.getDocumentation()); + } + setDocumentation(param, "Les instances de " + attrType + " à ajouter"); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + if (<%=attrName%> == null) { + return; + } + for (<%=attrType%> item : <%=attrName%>) { + add<%=StringUtils.capitalize(attrName)%>(item); + } +}*/ + ); + } + + protected void addMultipleSetOperation(ObjectModelAttribute attribute, String collectionInterface) { + + String attrName = attribute.getName(); + String attrType = collectionInterface + "<" + attribute.getType() + ">"; + + // Interface operation + ObjectModelOperation interfaceOperation = + createPropertySetterSignature(outputInterface, attrType, attrName, + attribute.getDocumentation()); + + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + // Force fire for collection + setOperationBody(implOperation, "" +/*{ + fireOnPreWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>); + this.<%=attrName%> = <%=attrName%>; + fireOnPostWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>); +}*/ + ); + } + + protected void addMultipleRemoveOperation(ObjectModelAttribute attribute) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + ObjectModelAttribute reverse = attribute.getReverseAttribute(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "remove" + StringUtils.capitalize(attrName), + void.class, ObjectModelModifier.PACKAGE); + ObjectModelParameter param = + addParameter(interfaceOperation, attrType, attrName); + + // Documentation + if (TopiaGeneratorUtil.hasDocumentation(attribute)) { + setDocumentation(interfaceOperation, attribute.getDocumentation()); + } + setDocumentation(param, "L'instance de " + attrType + " à retirer"); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + StringBuilder body = new StringBuilder(); + + body.append("" +/*{ + fireOnPreWrite(<%=getConstantName(attrName)%>, <%=attrName%>, null); + if ((this.<%=attrName%> == null) || (!this.<%=attrName%>.remove(<%=attrName%>))) { + throw new IllegalArgumentException("List does not contain given element"); + } +}*/ + ); + + if (reverse != null && (reverse.isNavigable() || + hasUnidirectionalRelationOnAbstractType(attribute, model))) { + String reverseAttrName = StringUtils.capitalize(reverse.getName()); + if (!GeneratorUtil.isNMultiplicity(reverse)) { + body.append("" +/*{ + <%=attrName%>.set<%=reverseAttrName%>(null); +}*/ + ); + } else { + body.append("" +/*{ + <%=attrName%>.get<%=reverseAttrName%>().remove(this); +}*/ + ); + } + } + body.append("" +/*{ + fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size() + 1, <%=attrName%>, null); +}*/ + ); + setOperationBody(implOperation, body.toString()); + } + + protected void addMultipleClearOperation(ObjectModelAttribute attribute, + String collectionInterface, + String collectionImpl) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + ObjectModelAttribute reverse = attribute.getReverseAttribute(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "clear" + StringUtils.capitalize(attrName), + void.class, ObjectModelModifier.PACKAGE); + + // Documentation + if (TopiaGeneratorUtil.hasDocumentation(attribute)) { + setDocumentation(interfaceOperation, attribute.getDocumentation()); + } + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + StringBuilder body = new StringBuilder("" +/*{ + if (this.<%=attrName%> == null) { + return; + } +}*/ + ); + + if (reverse != null && (reverse.isNavigable() || + hasUnidirectionalRelationOnAbstractType(attribute, model))) { + String reverseAttrName = StringUtils.capitalize(reverse.getName()); + body.append("" +/*{ for (<%=attrType%> item : this.<%=attrName%>) { +}*/ + ); + if (!GeneratorUtil.isNMultiplicity(reverse)) { + body.append("" +/*{ item.set<%=reverseAttrName%>(null); +}*/ + ); + } else { + body.append("" +/*{ item.get<%=reverseAttrName%>().remove(this); +}*/ + ); + } + body.append("" +/*{ } +}*/ + ); + } + // FIXME-fdesbois-2010-06-25 : Very strange behavior, why the oldValue is a new instance ? + body.append("" +/*{ <%=collectionInterface%><<%=attrType%>> _oldValue = new <%=collectionImpl%><<%=attrType%>>(this.<%=attrName%>); + fireOnPreWrite(<%=getConstantName(attrName)%>, _oldValue, this.<%=attrName%>); + this.<%=attrName%>.clear(); + fireOnPostWrite(<%=getConstantName(attrName)%>, _oldValue, this.<%=attrName%>); +}*/ + ); + setOperationBody(implOperation, body.toString()); + } + + protected void addMultipleGetOperation(ObjectModelAttribute attribute, + String collectionInterface) { + + String attrName = attribute.getName(); + String attrType = collectionInterface + "<" + attribute.getType() + ">"; + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "get" + StringUtils.capitalize(attrName), + attrType, ObjectModelModifier.PACKAGE); + + // Documentation +// if (TopiaGeneratorUtil.hasDocumentation(attribute)) { +// // ?? +// setDocumentation(interfaceOperation, "Retourne la collection."); +// } + setDocumentation(interfaceOperation, "Retourne la collection."); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + return <%=attrName%>; +}*/ + ); + } + + protected void addMultipleGetTopiaIdOperation(ObjectModelAttribute attribute) { + + String attrName = attribute.getName(); + String attrType = attribute.getType(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "get" + StringUtils.capitalize(attrName) + "ByTopiaId", + attrType, ObjectModelModifier.PACKAGE); + ObjectModelParameter param = + addParameter(interfaceOperation, String.class, "topiaId"); + + // Documentation + setDocumentation(interfaceOperation, "Recupère l'attribut " + attrName + + " à partir de son topiaId"); + setDocumentation(param, "le topia id de l'entité recherchée"); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + addImport(outputAbstract, TopiaEntityHelper.class); + + setOperationBody(implOperation, "" +/*{ + return TopiaEntityHelper.getEntityByTopiaId(<%=attrName%>, topiaId); + }*/ + ); + } + + protected void addMultipleSizeOperation(ObjectModelAttribute attribute) { + + String attrName = attribute.getName(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "size" + StringUtils.capitalize(attrName), + int.class, ObjectModelModifier.PACKAGE); + + // Documentation + setDocumentation(interfaceOperation, "Retourne le nombre d'éléments de la collection " + attrName); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + if (<%=attrName%> == null) { + return 0; + } + return <%=attrName%>.size(); +}*/ + ); + } + + protected void addMultipleIsEmptyOperation(ObjectModelAttribute attribute) { + + String attrName = attribute.getName(); + + // Interface operation + ObjectModelOperation interfaceOperation = + addOperation(outputInterface, "is" + StringUtils.capitalize(attrName) + "Empty", + boolean.class, ObjectModelModifier.PACKAGE); + + // Documentation + setDocumentation(interfaceOperation, "Retourne {@code true} si la collection " + attrName + " est vide."); + + // Implementation + ObjectModelOperation implOperation = + cloneOperationSignature(interfaceOperation, outputAbstract); + + setOperationBody(implOperation, "" +/*{ + int size = size<%=StringUtils.capitalize(attrName)%>(); + return size == 0; +}*/ + ); + } + + + ///////////////////////////////// OLD + protected void generateInterface(ObjectModelClass input, ObjectModelInterface output, Collection<ObjectModelAttribute> attributes, @@ -265,6 +781,8 @@ // attributes + generateOperationsFromAttributes(attributes); + for (ObjectModelAttribute attr : attributes) { ObjectModelAttribute reverse = attr.getReverseAttribute(); if (!attr.isNavigable() && @@ -278,11 +796,11 @@ addInterfaceAssociationAttribute(output, attr); } else { - - addInterfaceNoneAssociationAttribute(output, attr); + //addInterfaceNoneAssociationAttribute(output, attr); } } + //Méthodes d'accès aux attributs d'une classe d'associations if (input instanceof ObjectModelAssociationClass) { @@ -590,6 +1108,7 @@ } } + @Deprecated protected void addInterfaceNoneAssociationAttribute(ObjectModelInterface output, ObjectModelAttribute attr) { String attrName = attr.getName(); @@ -598,6 +1117,7 @@ ObjectModelParameter attr2; if (!GeneratorUtil.isNMultiplicity(attr)) { + // DONE // setXXX @@ -618,13 +1138,13 @@ // Add getter for simple property. // Only one call for this method, no need for abstract generation // TODO-fdesbois-2010-05-27 : manage all attribute cases in this method - addSimpleGetterOperation(attr, null); + addSimpleGetOperation(attr, null); } else { String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr); - // addXXX + // addXXX : DONE op = addOperation(output, "add" + StringUtils.capitalize(attrName), @@ -638,7 +1158,7 @@ setDocumentation(attr2, "L'instance de " + attrName + " à ajouter"); - // addAllXXX + // addAllXXX : DONE op = addOperation(output, "addAll" + StringUtils.capitalize(attrName), @@ -653,7 +1173,7 @@ setDocumentation(attr2, "Les instances de " + attrName + " à ajouter"); - // setXXX + // setXXX : DONE op = addOperation(output, "set" + StringUtils.capitalize(attrName), @@ -668,7 +1188,7 @@ setDocumentation(attr2, "La Collection de " + attrName + " à ajouter"); - // removeXXX + // removeXXX : DONE op = addOperation(output, "remove" + StringUtils.capitalize(attrName), @@ -683,7 +1203,7 @@ setDocumentation(attr2, "L'instance de " + attrName + " à retirer"); - // clearXXX + // clearXXX : DONE op = addOperation(output, "clear" + StringUtils.capitalize(attrName), @@ -694,7 +1214,7 @@ } setDocumentation(attr2, "Vide la Collection de " + attrName); - // getXXX + // getXXX : DONE op = addOperation(output, "get" + StringUtils.capitalize(attrName), @@ -707,7 +1227,7 @@ if (!TopiaGeneratorUtil.isPrimitiveType(attr) && !TopiaGeneratorUtil.isDateType(attr)) { - // getXXXByTopiaId + // getXXXByTopiaId : DONE op = addOperation(output, "get" + StringUtils.capitalize(attrName) + "ByTopiaId", @@ -718,7 +1238,7 @@ setDocumentation(attr2, "le topia id de l'entité recherchée"); } - // sizeXXX + // sizeXXX : DONE op = addOperation(output, "size" + StringUtils.capitalize(attrName), @@ -726,7 +1246,7 @@ ObjectModelModifier.PACKAGE); setDocumentation(op, "Retourne le nombre d'éléments de la collection " + attrName); - // isXXXEmpty + // isXXXEmpty : DONE op = addOperation(output, "is" + StringUtils.capitalize(attrName) + "Empty", @@ -961,7 +1481,9 @@ return <%=name%>; }*/ ); - } else { + // Code is refactored and generated with correct methods, see generateOperationsFromAttributes + } else if (false) { + // DONE // setXXX @@ -992,12 +1514,13 @@ addImport(result, collectionInterface); addImport(result, collectionObject); collectionInterface = TopiaGeneratorUtil.getSimpleName(collectionInterface); - collectionObject = getSimpleName(collectionObject); + collectionObject = TopiaGeneratorUtil.getSimpleName(collectionObject); - if (!attr.hasAssociationClass()) { + // Code is refactored and generated with correct methods, see generateOperationsFromAttributes + if (!attr.hasAssociationClass() && false) { //Méthodes remplacées par des accesseurs sur les classes d'assoc - // addXXX + // addXXX : DONE op = addOperation(result, "add" + StringUtils.capitalize(attrName), @@ -1041,7 +1564,7 @@ ); setOperationBody(op, body.toString()); - // addAllXXX + // addAllXXX : DONE op = addOperation(result, "addAll" + StringUtils.capitalize(attrName), @@ -1060,8 +1583,11 @@ }*/ ); - if (!isPrimitiveType(attr) && !isDateType(attr)) { + // getXXXByTopiaId : DONE + if (!TopiaGeneratorUtil.isPrimitiveType(attr) && + !TopiaGeneratorUtil.isDateType(attr)) { + op = addOperation(result, "get" + StringUtils.capitalize(attrName) + "ByTopiaId", attrType, @@ -1075,7 +1601,7 @@ } - // setXXX + // setXXX : DONE op = addOperation(result, "set" + StringUtils.capitalize(attrName), @@ -1093,7 +1619,7 @@ ); - // removeXXX + // removeXXX : DONE op = addOperation(result, @@ -1134,7 +1660,7 @@ setOperationBody(op, body.toString()); - // clearXXX + // clearXXX : DONE op = addOperation(result, "clear" + StringUtils.capitalize(attrName), @@ -1184,7 +1710,7 @@ setOperationBody(op, body.toString()); - } else { + } else if (attr.hasAssociationClass()) { String assocAttrName = GeneratorUtil.getAssocAttrName(attr); @@ -1225,7 +1751,8 @@ setOperationBody(op, body.toString()); - if (!isPrimitiveType(attr) && !isDateType(attr)) { + if (!TopiaGeneratorUtil.isPrimitiveType(attr) && + !TopiaGeneratorUtil.isDateType(attr)) { // getXXXByTopiaId @@ -1349,9 +1876,10 @@ setOperationBody(op, body.toString()); } - if (!attr.hasAssociationClass()) { + // Code is refactored and generated with correct methods, see generateOperationsFromAttributes + if (!attr.hasAssociationClass() && false) { - // getXXX : getter for collection entity attribute (N multiplicity) + // getXXX : getter for collection entity attribute (N multiplicity) : DONE op = addOperation(result, "get" + StringUtils.capitalize(attrName), @@ -1363,7 +1891,7 @@ }*/ ); - // sizeXXX + // sizeXXX : DONE op = addOperation(result, "size" + StringUtils.capitalize(attrName), @@ -1378,7 +1906,7 @@ }*/ ); - // isXXXEmpty + // isXXXEmpty : DONE op = addOperation(result, "is" + StringUtils.capitalize(attrName) + "Empty", @@ -1391,7 +1919,7 @@ }*/ ); - } else { + } else if (attr.hasAssociationClass()) { String assocAttrName = GeneratorUtil.getAssocAttrName(attr); String assocClassFQN = attr.getAssociationClass().getQualifiedName(); // String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName()); @@ -1464,63 +1992,6 @@ } } - /** - * Add getter for simple property (neither association nor multiple). - * Will add two different operations for boolean case ('is' method and - * 'get' method). This method add the operation in both {@code - * outputAbstract} and {@code outputInterface}. - * - * @param attribute ObjectModelAttribute for getter operation - * @param operationPrefix Operation prefix : 'get' by default, if prefix - * is null - */ - protected void addSimpleGetterOperation(ObjectModelAttribute attribute, - String operationPrefix) { - - String attrName = attribute.getName(); - String attrType = attribute.getType(); - - if (operationPrefix == null) { - operationPrefix = TopiaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX; - } - - if (log.isDebugEnabled()) { - log.debug("Add getter operation for " + attrName + - " prefix = " + operationPrefix); - } - - // CONTRACT in Interface - ObjectModelOperation contract = addOperation(outputInterface, - operationPrefix + StringUtils.capitalize(attrName), - attrType, - ObjectModelModifier.PACKAGE); - - if (TopiaGeneratorUtil.hasDocumentation(attribute)) { - setDocumentation(contract, attribute.getDocumentation()); - } - - // IMPLEMENTATION in Abstract - ObjectModelOperation impl = addOperation(outputAbstract, - contract.getName(), - contract.getReturnType(), - ObjectModelModifier.PUBLIC); - setOperationBody(impl, "" -/*{ - fireOnPreRead(<%=getConstantName(attrName)%>, <%=attrName%>); - <%=attrType%> result = this.<%=attrName%>; - fireOnPostRead(<%=getConstantName(attrName)%>, <%=attrName%>); - return result; -}*/ - ); - - // Generate 'is' getter for boolean attributes - if (attrType.toLowerCase().contains("boolean") && - !operationPrefix.equals(TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX)) { - addSimpleGetterOperation(attribute, - TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX); - } - } - protected void generateToStringMethod(ObjectModelClass output, ObjectModelClass clazz) { if (log.isDebugEnabled()) {
participants (1)
-
fdesbois@users.nuiton.org