Topia-commits
Threads by month
- ----- 2026 -----
- June
- May
- April
- March
- February
- January
- ----- 2025 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2024 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2023 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2022 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2021 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2020 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2019 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2018 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2017 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2016 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2015 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2014 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2013 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2012 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2011 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2010 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2009 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2008 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2007 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2006 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2005 -----
- December
- November
- October
- September
- August
- July
- June
- May
- April
- March
- February
- January
- ----- 2004 -----
- December
- November
- October
- September
- August
- July
- June
- May
June 2010
- 5 participants
- 63 discussions
r2038 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 27 Jun '10
by fdesbois@users.nuiton.org 27 Jun '10
27 Jun '10
Author: fdesbois
Date: 2010-06-27 14:51:25 +0200 (Sun, 27 Jun 2010)
New Revision: 2038
Url: http://nuiton.org/repositories/revision/topia/2038
Log:
Evo #609 : Refactor aggregate and composite operations + abstract methods from entity
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-27 11:13:04 UTC (rev 2037)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-27 12:51:25 UTC (rev 2038)
@@ -205,8 +205,6 @@
input.getPackageName());
// These import will be removed (will be automatically added if needed)
- addImport(outputAbstract, ArrayList.class);
- addImport(outputAbstract, List.class);
// addImport(output, TopiaEntity.class);
addImport(outputAbstract, TopiaContextImplementor.class);
@@ -321,11 +319,13 @@
createAcceptOperation();
- generateAggregateMethod(outputAbstract, input);
+ // Imports needed for aggregate and composite operations
+ addImport(outputAbstract, ArrayList.class);
+ addImport(outputAbstract, List.class);
- generateCompositeMethod(outputAbstract, input);
+ createAggregateOperation();
- generateAbstractMethods(outputAbstract, input);
+ createCompositeOperation();
boolean doGenerateToString = TopiaGeneratorUtil.generateToString(input,
model);
@@ -344,6 +344,10 @@
protected void stopGenerateUtilOperations() {
closeAcceptOperation();
+
+ closeAggregateOperation();
+
+ closeCompositeOperation();
}
/**
@@ -362,32 +366,35 @@
protected void generateExtraOperations(ObjectModelClass input) {
for (ObjectModelOperation operation : input.getOperations()) {
- String visibility = operation.getVisibility();
- if (operation.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO) ||
- !visibility.equals(ObjectModelModifier.PUBLIC.toString())) {
- // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
- return;
- }
String opName = operation.getName();
String opType = operation.getReturnType();
+ ObjectModelModifier visibility =
+ ObjectModelModifier.toValue(operation.getVisibility());
- ObjectModelOperation op2 = addOperation(outputInterface, opName, opType, ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(operation)) {
- setDocumentation(op2, operation.getDocumentation());
+ if (isVerbose()) {
+ log.info("Extra operation for : " + input.getQualifiedName() +
+ " - method : " + opName +
+ " - returnType : " + opType +
+ " - visibility : " + visibility);
}
- for (ObjectModelParameter param : operation.getParameters()) {
- String paramName = param.getName();
- String paramType = param.getType();
- ObjectModelParameter param2 = addParameter(op2, paramType, paramName);
- if (TopiaGeneratorUtil.hasDocumentation(param)) {
- setDocumentation(param2, param.getDocumentation());
- }
+ // Deprecated from 2.3.4
+ // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
+ if (operation.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO)) {
+ return;
+
+ // Generate entity methods which have not a public visibility.
+ // Only in abstract entity class as abstract operation.
+ } else if (!visibility.equals(ObjectModelModifier.PUBLIC)) {
+ addOperation(outputAbstract, opName, opType, visibility,
+ ObjectModelModifier.ABSTRACT);
+
+ // Other operations, only in entity interface, implementations
+ // need to be done in implementation class created by developper
+ } else {
+ cloneOperationSignature(operation, outputInterface, true);
}
- for (String exception : operation.getExceptions()) {
- addException(op2, exception);
- }
}
}
@@ -402,7 +409,7 @@
if (!associationClass) {
- // FIXME-fdesbois-2010-06-25 : Strange behavior to keep those links
+ // FIXME-fdesbois-2010-06-25 : Strange behavior to keep those links, will break hibernate, may be a problem in mapping
if (!attribute.isNavigable() && attribute.hasAssociationClass()) {
generatePropertyConstant(attribute);
@@ -487,8 +494,10 @@
addAnnotation(outputAbstract, property, annotation);
}
- // accept operation body
+ // Update util operations body
updateAcceptOperation(attribute);
+ updateAggregateOperation(attribute);
+ updateCompositeOperation(attribute);
}
/**
@@ -1116,6 +1125,14 @@
private StringBuilder acceptOperationBody;
+ private ObjectModelOperation aggregateOperation;
+
+ private StringBuilder aggregateOperationBody;
+
+ private ObjectModelOperation compositeOperation;
+
+ private StringBuilder compositeOperationBody;
+
protected void createAcceptOperation() {
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -1172,7 +1189,174 @@
" " : acceptOperationBody.toString());
}
+ protected void createAggregateOperation() {
+ // Interface operation
+ ObjectModelOperation interfaceOperation =
+ addOperation(outputInterface, "getAggregate",
+ List.class.getName() + '<' + TopiaEntity.class.getName() + '>');
+
+ addException(interfaceOperation, TopiaException.class);
+
+ // Implementation
+ aggregateOperation = createImplOperation(interfaceOperation);
+
+ aggregateOperationBody = new StringBuilder(""
+/*{
+ List<TopiaEntity> tmp = new ArrayList<TopiaEntity>();
+
+ // pour tous les attributs rechecher les composites et les class d'asso
+ // on les ajoute dans tmp
+}*/
+ );
+ }
+
+ protected void updateAggregateOperation(ObjectModelAttribute attribute) {
+ if (attribute.isAggregate() &&
+ attribute.referenceClassifier() &&
+ attribute.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
+
+ String attrName = attribute.getName();
+ String getterName = "get" + StringUtils.capitalize(attrName);
+ if (GeneratorUtil.isNMultiplicity(attribute)) {
+ aggregateOperationBody.append(""
+/*{ tmp.addAll(<%=getterName%>());
+}*/
+ );
+ } else {
+ aggregateOperationBody.append(""
+/*{ tmp.add(<%=getterName%>());
+}*/
+ );
+ }
+ }
+ }
+
+ protected void closeAggregateOperation() {
+ aggregateOperationBody.append(""
+/*{
+ // on refait un tour sur chaque entity de tmp pour recuperer leur
+ // composite
+ List<TopiaEntity> result = new ArrayList<TopiaEntity>();
+ for (TopiaEntity entity : tmp) {
+ result.add(entity);
+ result.addAll(entity.getAggregate());
+ }
+
+ return result;
+}*/
+ );
+ setOperationBody(aggregateOperation, aggregateOperationBody.length() == 0 ?
+ " " : aggregateOperationBody.toString());
+ }
+
+ protected void createCompositeOperation() {
+
+ // Interface operation
+ ObjectModelOperation interfaceOperation =
+ addOperation(outputInterface, "getComposite",
+ List.class.getName() + '<' + TopiaEntity.class.getName() + '>');
+
+ addException(interfaceOperation, TopiaException.class);
+
+ // Implementation
+ compositeOperation = createImplOperation(interfaceOperation);
+
+ compositeOperationBody = new StringBuilder(""
+/*{
+ List<TopiaEntity> tmp = new ArrayList<TopiaEntity>();
+
+ // pour tous les attributs rechecher les composites et les class d'asso
+ // on les ajoute dans tmp
+}*/
+ );
+ }
+
+ protected void updateCompositeOperation(ObjectModelAttribute attribute) {
+ if (attribute.referenceClassifier() &&
+ attribute.getClassifier().hasStereotype(STEREOTYPE_ENTITY)) {
+ if (attribute.isComposite()) {
+ String attrName = attribute.getName();
+ String getterName = "get" + StringUtils.capitalize(attrName);
+ if (GeneratorUtil.isNMultiplicity(attribute)) {
+ compositeOperationBody.append(""
+/*{ if (<%=getterName%>() != null) {
+ tmp.addAll(<%=getterName%>());
+ }
+}*/
+ );
+ } else {
+ compositeOperationBody.append(""
+/*{ tmp.add(<%=getterName%>());
+}*/
+ );
+ }
+ } else if (attribute.hasAssociationClass()) {
+ String assocAttrName = GeneratorUtil.getAssocAttrName(
+ attribute);
+ String assocClassFQN = TopiaGeneratorUtil.getSimpleName(
+ attribute.getAssociationClass().getQualifiedName());
+ String ref = "this." + GeneratorUtil.toLowerCaseFirstLetter(
+ assocAttrName);
+ if (!GeneratorUtil.isNMultiplicity(attribute)) {
+ compositeOperationBody.append(""
+/*{
+ if (<%=ref%> != null) {
+ tmp.add(<%=ref%>);
+ }
+}*/
+ );
+ } else {
+ ObjectModelAttribute reverse = attribute.getReverseAttribute();
+ String reverseAttrName = reverse.getName();
+ // On utilise pas l'attribut car il est potentiellement
+ // pas a jour, car pour les asso avec cardinalité
+ // personne ne fait de add. Ce qui est normal, mais
+ // pour pouvoir faire tout de meme des delete en cascade
+ // sur les asso, le champs est dans le mapping
+ // hibernate et donc il le faut aussi dans la classe
+ // sinon hibernate rale lorsqu'il charge l'objet
+// if (<%=ref%> != null) {
+// tmp.addAll(<%=ref%>);
+// }
+ compositeOperationBody.append(""
+/*{
+ {
+ org.nuiton.topia.persistence.TopiaDAO<<%=assocClassFQN%>> dao = ((TopiaContextImplementor) getTopiaContext()).getDAO(<%=assocClassFQN%>.class);
+ List<<%=assocClassFQN%>> findAllByProperties = dao.findAllByProperties("<%=reverseAttrName%>", this);
+ if (findAllByProperties != null) {
+ tmp.addAll(findAllByProperties);
+ }
+ }
+}*/
+ );
+ }
+ }
+ }
+ }
+
+ protected void closeCompositeOperation() {
+ compositeOperationBody.append(""
+/*{
+ // on refait un tour sur chaque entity de tmp pour recuperer leur
+ // composite
+ List<TopiaEntity> result = new ArrayList<TopiaEntity>();
+ for (TopiaEntity entity : tmp) {
+ if (entity != null) {
+ result.add(entity);
+ result.addAll(entity.getComposite());
+ }
+ }
+
+ return result;
+ }*/
+ );
+
+ setOperationBody(compositeOperation, compositeOperationBody.length() == 0 ?
+ " " : compositeOperationBody.toString());
+ }
+
+
///////////////////////////////// OLD
// -------------------------------------------------------------------------
@@ -1225,6 +1409,7 @@
}
+ @Deprecated
protected void generateCompositeMethod(ObjectModelClass output,
ObjectModelClass clazz) {
@@ -1325,6 +1510,7 @@
setOperationBody(op, body.length() == 0 ? " " : body.toString());
}
+ @Deprecated
protected void generateAggregateMethod(ObjectModelClass output,
ObjectModelClass clazz) {
@@ -1485,6 +1671,7 @@
* @param output ObjectModelClass result corresponding to the EntityAbstract
* @param input ObjectModelClass source from ObjectModel
*/
+ @Deprecated
private void generateAbstractMethods(ObjectModelClass output,
ObjectModelClass input) {
for (ObjectModelOperation op : input.getOperations()) {
@@ -1508,6 +1695,8 @@
private void generateI18n(ObjectModelClass result, String i18nPrefix,
ObjectModelClass clazz) {
+ ObjectModelOperation block = addBlock(result, ObjectModelModifier.STATIC);
+
StringBuilder buffer = new StringBuilder(300);
addI18n(buffer, i18nPrefix, Introspector.decapitalize(clazz.getName()));
for (ObjectModelAttribute attr : clazz.getAttributes()) {
@@ -1516,10 +1705,7 @@
addI18n(buffer, i18nPrefix, Introspector.decapitalize(attr.getName()));
}
}
-
- //FIXME : use a block extension for java
- ObjectModelOperation op = addBlock(result, ObjectModelModifier.STATIC);
- setOperationBody(op, buffer.toString());
+ setOperationBody(block, buffer.toString());
}
private void addI18n(StringBuilder buffer, String i18nPrefix,
@@ -1595,7 +1781,7 @@
protected ObjectModelOperation createImplOperation(ObjectModelOperation interfaceOperation) {
ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ cloneOperationSignature(interfaceOperation, outputAbstract, false);
addAnnotation(outputAbstract, implOperation, Override.class.getSimpleName());
return implOperation;
}
@@ -1635,5 +1821,4 @@
return operation;
}
-
}
1
0
r2037 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 27 Jun '10
by fdesbois@users.nuiton.org 27 Jun '10
27 Jun '10
Author: fdesbois
Date: 2010-06-27 13:13:04 +0200 (Sun, 27 Jun 2010)
New Revision: 2037
Url: http://nuiton.org/repositories/revision/topia/2037
Log:
Evo #609 : Refactor attribute generation + accept method
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-27 06:36:23 UTC (rev 2036)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-27 11:13:04 UTC (rev 2037)
@@ -56,7 +56,6 @@
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.shouldBeAbstract;
@@ -113,14 +112,12 @@
}
if (log.isDebugEnabled()) {
- log.debug("for entity : "+input.getQualifiedName());
- log.info("Will use classLoader "+ getClassLoader());
+ log.debug("for entity : " + input.getQualifiedName());
+ log.info("Will use classLoader " + getClassLoader());
}
// fix once for all the constant prefix to use
-
String prefix = getConstantPrefix(input, "");
-
if (StringUtils.isEmpty(prefix)) {
// no specific prefix, so no prefix
@@ -128,74 +125,65 @@
log.warn("[" + input.getName() + "] Will generate constants with NO prefix, not a good idea...");
}
}
-
setConstantPrefix(prefix);
- String clazzName = input.getName();
- String packageName = input.getPackageName();
+ // Create Entity Interface and its header
+ createEntityInterface(input);
- Collection<ObjectModelAttribute> attributes = input.getAttributes();
+ // Create Entity Abstract class and its header
+ createEntityAbstractClass(input);
- Collection<ObjectModelOperation> operations = input.getOperations();
+ // Start util operations : create operations : accept, aggregate, composite, toString
+ startGenerateUtilOperations(input);
- // Create classifiers : Interface, Abstract
- outputInterface = createInterface(clazzName, packageName);
- outputAbstract = createAbstractClass(clazzName + "Abstract", packageName);
+ // Add constant, attribute and operations for each property
+ generateProperties(input.getAttributes());
- generateHeaders(input);
-
- generateProperties(input);
-
// Case of association class : properties from participants/extremities
// of the association class.
if (input instanceof ObjectModelAssociationClass) {
ObjectModelAssociationClass association = (ObjectModelAssociationClass)input;
- generatePropertiesFromAssociation(association);
+ associationClass = true;
+ generateProperties(association.getParticipantsAttributes());
+ associationClass = false;
}
+ // Stop util operations : set each operation body
+ stopGenerateUtilOperations();
+
+ // Add extra constants (from uml dependency)
generateExtraConstants(input);
+ // Add extra operations (defined on the entity)
generateExtraOperations(input);
- generateAbstract(input, outputAbstract, attributes, operations);
+ boolean generateImpl = isGenerateImpl(input, input.getOperations());
- boolean generateImpl = isGenerateImpl(input, operations);
-
if (generateImpl) {
- String implName = clazzName + "Impl";
- if (isVerbose()) {
- log.info("Will generate [" + implName + "]");
- }
-
- if (isAbstract(input)) {
- outputImpl = createAbstractClass(implName, packageName);
- } else {
- outputImpl = createClass(implName, packageName);
- }
-
// generate impl
- generateImpl(input, outputImpl);
+ generateImpl(input);
}
// Clean data output after transformation
clean();
}
- protected void generateHeaders(ObjectModelClass input) {
+ protected void createEntityInterface(ObjectModelClass input) {
- ////// For Interface
- addImport(outputInterface, TopiaEntity.class);
+ outputInterface = createInterface(input.getName(), input.getPackageName());
+ // Documentation
if (TopiaGeneratorUtil.hasDocumentation(input)) {
setDocumentation(outputInterface, input.getDocumentation());
}
- // super interfaces
+ // Extends
for (ObjectModelClassifier parent : input.getInterfaces()) {
addInterface(outputInterface, parent.getQualifiedName());
}
+ // Extends from inheritance
boolean needTopiaEntity = true;
for (ObjectModelClassifier parent : input.getSuperclasses()) {
if (parent.hasStereotype(STEREOTYPE_ENTITY)) {
@@ -205,56 +193,244 @@
}
}
+ // Extends TopiaEntity (only if hasn't parent entity)
if (needTopiaEntity) {
addInterface(outputInterface, TopiaEntity.class);
}
}
+ protected void createEntityAbstractClass(ObjectModelClass input) {
+
+ outputAbstract = createAbstractClass(input.getName() + "Abstract",
+ input.getPackageName());
+
+ // These import will be removed (will be automatically added if needed)
+ addImport(outputAbstract, ArrayList.class);
+ addImport(outputAbstract, List.class);
+// addImport(output, TopiaEntity.class);
+ addImport(outputAbstract, TopiaContextImplementor.class);
+
+ // Documentation
+ StringBuilder doc = new StringBuilder();
+ doc.append("Implantation POJO pour l'entité {@link ");
+ doc.append(StringUtils.capitalize(outputInterface.getName()));
+ doc.append("}\n");
+
+ String dbName = input.getTagValue(TAG_DB_NAME);
+ if (dbName != null) {
+ doc.append("<p>Nom de l'entité en BD : ");
+ doc.append(dbName);
+ doc.append(".</p>");
+ }
+
+ setDocumentation(outputAbstract, doc.toString());
+
+ // Implements
+ addInterface(outputAbstract, outputInterface.getName());
+
+ // Extends
+ for (ObjectModelClass parent : input.getSuperclasses()) {
+ String extendClass = parent.getQualifiedName();
+ //Si une des classes parentes définies des méthodes abstraites, son
+ // impl ne sera pas créé
+ boolean abstractParent = TopiaGeneratorUtil.shouldBeAbstract(parent);
+ if (parent.hasStereotype(STEREOTYPE_ENTITY)) {
+ if (abstractParent) {
+ extendClass += "Abstract";
+ } else {
+ extendClass += "Impl";
+ }
+ }
+ setSuperClass(outputAbstract, extendClass);
+ }
+
+ // Extends TopiaEntityAbstract (only if hasn't parent entity)
+ if (outputAbstract.getSuperclasses().isEmpty()) {
+ setSuperClass(outputAbstract, TopiaEntityAbstract.class);
+ }
+
+ // serialVersionUID
+ String svUID =
+ TopiaGeneratorUtil.findTagValue("serialVersionUID", input, model);
+ if (svUID != null) {
+ addConstant(outputInterface, "serialVersionUID", long.class, svUID,
+ ObjectModelModifier.PRIVATE);
+ }
+ }
+
+ protected boolean isGenerateImpl(ObjectModelClass input,
+ Collection<ObjectModelOperation> operations) {
+
+ String fqn = input.getQualifiedName() + "Impl";
+
+ URL fileLocation = getFileInClassPath(fqn);
+
+ if (fileLocation != null) {
+
+ // there is already a existing file in class-path, skip
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], found existing file in class-path : " + fileLocation);
+ }
+ return false;
+ }
+
+ // On ne génère pas le impl si l'entité a des opérations qui ne sont
+ // pas seulement pour le DAO
+ if (!operations.isEmpty()) {
+
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], there is some operations and not only DAO ones");
+ }
+ return false;
+ }
+
+ //De même, on ne génère pas le impl si il y a des opérations venant des
+ // superclasses non implémentées
+ for (ObjectModelOperation otherOp : input.getAllOtherOperations(false)) {
+ if (otherOp.isAbstract()) {
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], there is a abstract operation [" + otherOp.getName() + "] in allOtherOperations.");
+ }
+ return false;
+ }
+ }
+
+ return true;
+ }
+
+ protected void generateImpl(ObjectModelClass input) {
+
+ String implName = input.getName() + "Impl";
+ String packageName = input.getPackageName();
+ if (isVerbose()) {
+ log.info("Will generate [" + implName + "]");
+ }
+
+ if (isAbstract(input)) {
+ outputImpl = createAbstractClass(implName, packageName);
+ } else {
+ outputImpl = createClass(implName, packageName);
+ }
+
+ setDocumentation(outputImpl, "Implantation des operations pour l'entité " +
+ input.getName() + ".");
+ setSuperClass(outputImpl, input.getQualifiedName() + "Abstract");
+ }
+
+ protected void startGenerateUtilOperations(ObjectModelClass input) {
+
+ createAcceptOperation();
+
+ generateAggregateMethod(outputAbstract, input);
+
+ generateCompositeMethod(outputAbstract, input);
+
+ generateAbstractMethods(outputAbstract, input);
+
+ boolean doGenerateToString = TopiaGeneratorUtil.generateToString(input,
+ model);
+ if (doGenerateToString) {
+ addImport(outputAbstract, ToStringBuilder.class);
+ generateToStringMethod(outputAbstract, input);
+ }
+
+ String i18nPrefix = TopiaGeneratorUtil.getI18nPrefix(input, model);
+ if (!StringUtils.isEmpty(i18nPrefix)) {
+ // generate i18n prefix
+ generateI18n(outputAbstract, i18nPrefix, input);
+ }
+ }
+
+ protected void stopGenerateUtilOperations() {
+
+ closeAcceptOperation();
+ }
+
/**
- * Generate properties from {@code input} entity class. Generate
- * constant and operations for each property.
+ * Generate extra constants if {@code input} has dependencies on
+ * enum used as constant injector.
*
- * @param input Input entity class
+ * @param input Entity class to treate
*/
- protected void generateProperties(ObjectModelClass input) {
- for (ObjectModelAttribute attribute : input.getAttributes()) {
+ protected void generateExtraConstants(ObjectModelClass input) {
+ Set<String> constants = addConstantsFromDependency(input, outputInterface);
- // FIXME-fdesbois-2010-06-25 : Stupid case, need to be removed
- if (!attribute.isNavigable() && attribute.hasAssociationClass()) {
- generatePropertyConstant(attribute);
- }
+ if (log.isDebugEnabled()) {
+ log.debug("Add constants from dependency : " + constants);
+ }
+ }
- if (!attribute.isNavigable() &&
- !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
- attribute.getReverseAttribute(), model)) {
- continue;
+ protected void generateExtraOperations(ObjectModelClass input) {
+ for (ObjectModelOperation operation : input.getOperations()) {
+ String visibility = operation.getVisibility();
+ if (operation.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO) ||
+ !visibility.equals(ObjectModelModifier.PUBLIC.toString())) {
+ // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
+ return;
}
- generatePropertyConstant(attribute);
+ String opName = operation.getName();
+ String opType = operation.getReturnType();
- generatePropertyOperations(attribute);
+ ObjectModelOperation op2 = addOperation(outputInterface, opName, opType, ObjectModelModifier.PACKAGE);
+ if (TopiaGeneratorUtil.hasDocumentation(operation)) {
+ setDocumentation(op2, operation.getDocumentation());
+ }
+
+ for (ObjectModelParameter param : operation.getParameters()) {
+ String paramName = param.getName();
+ String paramType = param.getType();
+ ObjectModelParameter param2 = addParameter(op2, paramType, paramName);
+ if (TopiaGeneratorUtil.hasDocumentation(param)) {
+ setDocumentation(param2, param.getDocumentation());
+ }
+ }
+ for (String exception : operation.getExceptions()) {
+ addException(op2, exception);
+ }
}
}
/**
- * Generate properties from {@code input} entity assocation class. Generate
- * constant and operations for each property.
+ * Generate properties from {@code attributes}. Generate
+ * constant, attribute and operations for each property.
*
- * @param association Input entity association class
+ * @param attributes Input attributes
*/
- protected void generatePropertiesFromAssociation(ObjectModelAssociationClass association) {
- associationClass = true;
- for (ObjectModelAttribute attribute : association.getParticipantsAttributes()) {
+ protected void generateProperties(Collection<ObjectModelAttribute> attributes) {
+ for (ObjectModelAttribute attribute : attributes) {
+ if (!associationClass) {
+
+ // FIXME-fdesbois-2010-06-25 : Strange behavior to keep those links
+ if (!attribute.isNavigable() && attribute.hasAssociationClass()) {
+ generatePropertyConstant(attribute);
+
+ generatePropertyAttribute(attribute);
+ }
+
+ if (!attribute.isNavigable() &&
+ !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
+ attribute.getReverseAttribute(), model)) {
+ continue;
+ }
+ }
+
+ // constant
generatePropertyConstant(attribute);
- addSingleSetOperation(attribute);
+ // attribute
+ generatePropertyAttribute(attribute);
- addSingleGetOperation(attribute, null);
+ // operations
+ generatePropertyOperations(attribute);
}
- associationClass = false;
}
+ // -------------------------------------------------------------------------
+ // Generate for property
+ // -------------------------------------------------------------------------
+
/**
* Generate constant in interface for {@code attribute}.
*
@@ -272,6 +448,49 @@
"\"" + attrName + "\"");
}
+ protected void generatePropertyAttribute(ObjectModelAttribute attribute) {
+
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
+ String collectionType = getCollectionType(attribute);
+
+ if (collectionType != null) {
+ attrType = collectionType + "<" + attrType + ">";
+ }
+
+ //String attrVisibility = attr.getVisibility();
+
+ // Declaration
+ ObjectModelAttribute property =
+ addAttribute(outputAbstract, attrName, attrType, null,
+ //ObjectModelModifier.toValue(attrVisibility),
+ ObjectModelModifier.PROTECTED
+ );
+
+ // Documentation
+ StringBuilder buffer = new StringBuilder();
+ if (TopiaGeneratorUtil.hasDocumentation(attribute)) {
+ String attrDocumentation = attribute.getDocumentation();
+ buffer.append(attrDocumentation).append('\n');
+ }
+ if (attribute.hasTagValue(TAG_DB_NAME)) {
+ String dbName = attribute.getTagValue(TAG_DB_NAME);
+ buffer.append("Nom de l'attribut en BD : ").append(dbName).append('\n');
+ }
+ setDocumentation(property, buffer.toString());
+
+ // Annotation
+ if (attribute.hasTagValue(TAG_ANNOTATION)) {
+ String annotation = attribute.getTagValue(TAG_ANNOTATION);
+ //FIXME Make annotation works...
+ //TODO tchemit 20100513 Test it still works
+ addAnnotation(outputAbstract, property, annotation);
+ }
+
+ // accept operation body
+ updateAcceptOperation(attribute);
+ }
+
/**
* Generation operations for {@code attributes}.
* One method exists for each operation to generate. Methods starting
@@ -295,7 +514,7 @@
*/
protected void generatePropertyOperations(ObjectModelAttribute attribute) {
- if (attribute.getMaxMultiplicity() == 1) {
+ if (attribute.getMaxMultiplicity() == 1 || associationClass) {
// setXXX
addSingleSetOperation(attribute);
@@ -358,91 +577,6 @@
}
}
- /**
- * Generate extra constants if {@code input} has dependencies on
- * enum used as constant injector.
- *
- * @param input Entity class to treate
- */
- protected void generateExtraConstants(ObjectModelClass input) {
- Set<String> constants = addConstantsFromDependency(input, outputInterface);
-
- if (log.isDebugEnabled()) {
- log.debug("Add constants from dependency : " + constants);
- }
- }
-
- protected void generateExtraOperations(ObjectModelClass input) {
- for (ObjectModelOperation operation : input.getOperations()) {
- String visibility = operation.getVisibility();
- if (operation.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO) ||
- !visibility.equals(ObjectModelModifier.PUBLIC.toString())) {
- // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
- return;
- }
-
- String opName = operation.getName();
- String opType = operation.getReturnType();
-
- ObjectModelOperation op2 = addOperation(outputInterface, opName, opType, ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(operation)) {
- setDocumentation(op2, operation.getDocumentation());
- }
-
- for (ObjectModelParameter param : operation.getParameters()) {
- String paramName = param.getName();
- String paramType = param.getType();
- ObjectModelParameter param2 = addParameter(op2, paramType, paramName);
- if (TopiaGeneratorUtil.hasDocumentation(param)) {
- setDocumentation(param2, param.getDocumentation());
- }
- }
- for (String exception : operation.getExceptions()) {
- addException(op2, exception);
- }
- }
- }
-
- protected boolean isGenerateImpl(ObjectModelClass input,
- Collection<ObjectModelOperation> operations) {
-
- String fqn = input.getQualifiedName() + "Impl";
-
- URL fileLocation = getFileInClassPath(fqn);
-
- if (fileLocation != null) {
-
- // there is already a existing file in class-path, skip
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], found existing file in class-path : " + fileLocation);
- }
- return false;
- }
-
- // On ne génère pas le impl si l'entité a des opérations qui ne sont
- // pas seulement pour le DAO
- if (!operations.isEmpty()) {
-
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], there is some operations and not only DAO ones");
- }
- return false;
- }
-
- //De même, on ne génère pas le impl si il y a des opérations venant des
- // superclasses non implémentées
- for (ObjectModelOperation otherOp : input.getAllOtherOperations(false)) {
- if (otherOp.isAbstract()) {
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], there is a abstract operation [" + otherOp.getName() + "] in allOtherOperations.");
- }
- return false;
- }
- }
-
- return true;
- }
-
protected void addSingleSetOperation(ObjectModelAttribute attribute) {
String attrName = getPropertyName(attribute);
@@ -459,8 +593,7 @@
attribute.getDocumentation());
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -510,8 +643,7 @@
}
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -557,8 +689,7 @@
setDocumentation(param, "L'instance de " + attrType + " à ajouter");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -628,8 +759,7 @@
setDocumentation(param, "Les instances de " + attrType + " à ajouter");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -661,8 +791,7 @@
createPropertySetterSignature(outputInterface, attrType, attrName,
attribute.getDocumentation());
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
referenceType = TopiaGeneratorUtil.getSimpleName(referenceType);
@@ -704,8 +833,7 @@
setDocumentation(param, "L'instance de " + attrType + " à retirer");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -770,8 +898,7 @@
}
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -837,8 +964,7 @@
setDocumentation(interfaceOperation, "Retourne la collection.");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
setOperationBody(implOperation, ""
/*{
@@ -870,8 +996,7 @@
setDocumentation(param, "le topia id de l'entité recherchée");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
addImport(outputAbstract, TopiaEntityHelper.class);
@@ -908,8 +1033,7 @@
// no doc from previous code
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
attrType = TopiaGeneratorUtil.getSimpleName(attrType);
@@ -945,8 +1069,7 @@
setDocumentation(interfaceOperation, "Retourne le nombre d'éléments de la collection " + attrName);
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
setOperationBody(implOperation, ""
/*{
@@ -975,8 +1098,7 @@
setDocumentation(interfaceOperation, "Retourne {@code true} si la collection " + attrName + " est vide.");
// Implementation
- ObjectModelOperation implOperation =
- cloneOperationSignature(interfaceOperation, outputAbstract);
+ ObjectModelOperation implOperation = createImplOperation(interfaceOperation);
setOperationBody(implOperation, ""
/*{
@@ -986,413 +1108,74 @@
);
}
+ // -------------------------------------------------------------------------
+ // Generate util operations
+ // -------------------------------------------------------------------------
- ///////////////////////////////// OLD
+ private ObjectModelOperation acceptOperation;
- @Deprecated
- protected void generateInterface(ObjectModelClass input,
- ObjectModelInterface output,
- Collection<ObjectModelAttribute> attributes,
- Collection<ObjectModelOperation> operations) {
+ private StringBuilder acceptOperationBody;
- addImport(output, TopiaEntity.class);
+ protected void createAcceptOperation() {
+ // Interface operation
+ ObjectModelOperation interfaceOperation =
+ addOperation(outputInterface, "accept", void.class);
+ ObjectModelParameter param =
+ addParameter(interfaceOperation, EntityVisitor.class, "visitor");
- Set<String> constants = addConstantsFromDependency(input, output);
+ addException(interfaceOperation, TopiaException.class);
- if (log.isDebugEnabled()) {
- log.debug("Add constants from dependency : " + constants);
- }
+ // Documentation
+ setDocumentation(interfaceOperation, "Envoi via les methodes du visitor l'ensemble des " +
+ "champs de l'entity\n" +
+ "avec leur nom, type et valeur.");
+ setDocumentation(param, "le visiteur de l'entite.");
- if (TopiaGeneratorUtil.hasDocumentation(input)) {
- setDocumentation(output,input.getDocumentation());
- }
+ // Implementation
+ acceptOperation = createImplOperation(interfaceOperation);
- // super classes
-
- for (ObjectModelClassifier parent : input.getInterfaces()) {
- addInterface(output,parent.getQualifiedName());
- }
-
- boolean needTopiaEntity = true;
- for (ObjectModelClassifier parent : input.getSuperclasses()) {
- if (parent.hasStereotype(STEREOTYPE_ENTITY)) {
- addInterface(output,parent.getQualifiedName());
- needTopiaEntity = false;
- break;
- }
- }
-
- if (needTopiaEntity) {
- addInterface(output, TopiaEntity.class);
- }
-
- generateInterfaceStaticColumnNames(input, output);
-
- //Méthodes d'accès aux attributs d'une classe d'associations
-
- if (input instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc =
- (ObjectModelAssociationClass) input;
- for (ObjectModelAttribute attr :
- assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String type = attr.getType();
- String name = attr.getName();
- generateInterfaceAssociationAccessors(output, name, type);
- if (attr.getReverseAttribute() == null) {
- type = ((ObjectModelClassifier)
- attr.getDeclaringElement()).getQualifiedName();
- name = attr.getDeclaringElement().getName();
- generateInterfaceAssociationAccessors(output, name, type);
- }
- }
- }
- }
-
- for (ObjectModelOperation operation : operations) {
- generateInterfaceOperation(operation, output);
- }
+ acceptOperationBody = new StringBuilder();
+ acceptOperationBody.append(""
+/*{
+ visitor.start(this);
+}*/
+ );
}
- @Deprecated
- protected void generateAbstract(ObjectModelClass input,
- ObjectModelClass output,
- Collection<ObjectModelAttribute> attributes,
- Collection<ObjectModelOperation> operations) {
+ protected void updateAcceptOperation(ObjectModelAttribute attribute) {
+ String attrName =
+ TopiaGeneratorUtil.getSimpleName(getPropertyName(attribute));
+ String attrType =
+ TopiaGeneratorUtil.getSimpleName(getPropertyType(attribute));
+ String collectionType = getCollectionType(attribute);
- String clazzName = input.getName();
- String clazzFQN = TopiaGeneratorUtil.getSimpleName(
- input.getQualifiedName());
-
- addInterface(output, clazzName);
-
- addImport(output, ArrayList.class);
- addImport(output, List.class);
- addImport(output, TopiaEntity.class);
- addImport(output, TopiaContextImplementor.class);
-
- // javadoc
-
- StringBuilder doc = new StringBuilder();
- doc.append("Implantation POJO pour l'entité {@link ");
- doc.append(StringUtils.capitalize(clazzFQN));
- doc.append("}\n");
-
- {
- String dbName = input.getTagValue(TAG_DB_NAME);
- if (dbName != null) {
- doc.append("<p>Nom de l'entité en BD : ");
- doc.append(dbName);
- doc.append(".</p>");
- }
- }
-
- setDocumentation(output, doc.toString());
-
- // super classes
-
- for (ObjectModelClass parent : input.getSuperclasses()) {
- String extendClass = parent.getQualifiedName();
- //Si une des classes parentes définies des méthodes abstraites, son
- // impl ne sera pas créé
- boolean abstractParent = shouldBeAbstract(parent);
- if (parent.hasStereotype(STEREOTYPE_ENTITY)) {
- if (abstractParent) {
- extendClass += "Abstract";
- } else {
- extendClass += "Impl";
- }
- }
- setSuperClass(output, extendClass);
- }
-
- if (output.getSuperclasses().isEmpty()) {
- setSuperClass(output, TopiaEntityAbstract.class);
- }
-
- // serialVersionUID
-
- String svUID = TopiaGeneratorUtil.findTagValue("serialVersionUID",
- input, model);
- if (svUID != null) {
-
- addConstant(output, "serialVersionUID", long.class, svUID,
- ObjectModelModifier.PRIVATE
+ if (collectionType != null) {
+ collectionType = TopiaGeneratorUtil.getSimpleName(collectionType);
+ acceptOperationBody.append(""
+/*{ visitor.visit(this, <%=getConstantName(attrName)%>, <%=collectionType%>.class, <%=attrType%>.class, <%=attrName%>);
+}*/
);
- }
-
- ObjectModelParameter attr2;
-
- for (ObjectModelAttribute attr : attributes) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
-
- // pour les asso quoi qu'il arrive il faut les lier des 2 cotes
- // pour pouvoir supprimer en cascade l'asso lors de la suppression
- // d'un des cotes
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model)
- || attr.hasAssociationClass())) {
- continue;
- }
-
- String type;
- String name;
-
- if (!attr.hasAssociationClass()) {
- String attrName = attr.getName();
- name = attrName;
- type = attr.getType();
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- //TODO THIMEL : Je pense que les
- // GeneratorUtil.toLowerCaseFirstLetter sont inutiles
- // ici, ou alors il faudrait le faire partout
- name = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- type = attr.getAssociationClass().getQualifiedName();
- }
-
- if (GeneratorUtil.isNMultiplicity(attr)) {
- String collectionType =
- TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
- type = collectionType + '<' + type + '>';
- }
-
- String attrVisibility = attr.getVisibility();
-
- attr2 = addAttribute(output, name, type, null,
- ObjectModelModifier.toValue(attrVisibility),
- ObjectModelModifier.PROTECTED
+ } else {
+ acceptOperationBody.append(""
+/*{ visitor.visit(this, <%=getConstantName(attrName)%>, <%=attrType%>.class, <%=attrName%>);
+}*/
);
-
- doc = new StringBuilder();
-
- if (TopiaGeneratorUtil.hasDocumentation(attr) ||
- attr.hasTagValue(TAG_DB_NAME)) {
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- String attrDocumentation = attr.getDocumentation();
- doc.append(attrDocumentation).append('\n');
- }
- if (attr.hasTagValue(TAG_DB_NAME)) {
- String dbName =
- attr.getTagValue(TAG_DB_NAME);
- doc.append("Nom de l'attribut en BD : ");
- doc.append(dbName);
- doc.append('\n');
- }
- }
-
- setDocumentation(attr2, doc.toString());
-
-
- if (attr.hasTagValue(TAG_ANNOTATION)) {
- String annotation = attr.getTagValue(TAG_ANNOTATION);
- //FIXME Make annotation works...
- //TODO tchemit 20100513 Test it still works
- addAnnotation(output, attr2, annotation);
- }
}
+ }
- //Déclaration des attributs d'une classe d'associations
- if (input instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc =
- (ObjectModelAssociationClass) input;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrVisibility = attr.getVisibility();
- String attrType = attr.getType();
- String attrName = attr.getName();
- addAttribute(output,
- GeneratorUtil.toLowerCaseFirstLetter(attrName),
- attrType, null,
- ObjectModelModifier.toValue(attrVisibility));
- }
- }
- }
-
- ObjectModelOperation op = addOperation(output, "update", "void",
- ObjectModelModifier.PUBLIC);
- addException(op, TopiaException.class);
- setDocumentation(op,"@deprecated since 2.3.4, use the DAO api instead.");
- addAnnotation(output, op, Deprecated.class.getSimpleName());
- addAnnotation(output, op, Override.class.getSimpleName());
- setOperationBody(op, ""
-/*{
- ((TopiaContextImplementor)getTopiaContext()).getDAO(<%=clazzName%>.class).update(this);
+ protected void closeAcceptOperation() {
+ acceptOperationBody.append(""
+/*{ visitor.end(this);
}*/
);
-
- op = addOperation(output, "delete", "void", ObjectModelModifier.PUBLIC);
- addException(op, TopiaException.class);
- setDocumentation(op,"@deprecated since 2.3.4, use the DAO api instead.");
- addAnnotation(output, op, Deprecated.class.getSimpleName());
- addAnnotation(output, op, Override.class.getSimpleName());
- setOperationBody(op, ""
-/*{
- ((TopiaContextImplementor)getTopiaContext()).getDAO(<%=clazzName%>.class).delete(this);
-}*/
- );
-
- generateAcceptMethod(output, input);
-
- generateAggregateMethod(output, input);
-
- generateCompositeMethod(output, input);
-
- // DONE
-// for (ObjectModelAttribute attr : attributes) {
-// ObjectModelAttribute reverse = attr.getReverseAttribute();
-//
-// if (!(attr.isNavigable()
-// || hasUnidirectionalRelationOnAbstractType(reverse, model))) {
-// continue;
-// }
-//
-// transformAttribute(output, attr, reverse);
-// }
-
- // DONE
- //Méthodes d'accès aux attributs d'une classe d'associations
-// if (input instanceof ObjectModelAssociationClass) {
-//
-// for (ObjectModelAttribute attr :
-// ((ObjectModelAssociationClass) input).getParticipantsAttributes()) {
-// if (attr != null) {
-// String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
-// String attrName = attr.getName();
-// generateAssociationAccessors(output, attrName, attrType);
-// }
-// }
-// }
-
- generateAbstractMethods(output, input);
-
- boolean doGenerateToString = TopiaGeneratorUtil.generateToString(input,
- model);
- if (doGenerateToString) {
- addImport(output, ToStringBuilder.class);
- generateToStringMethod(output, input);
- }
-
- String i18nPrefix = TopiaGeneratorUtil.getI18nPrefix(input, model);
- if (!StringUtils.isEmpty(i18nPrefix)) {
- // generate i18n prefix
- generateI18n(output, i18nPrefix, input);
- }
+ setOperationBody(acceptOperation, acceptOperationBody.length() == 0 ?
+ " " : acceptOperationBody.toString());
}
- protected void generateImpl(ObjectModelClass input,
- ObjectModelClass output) {
- setDocumentation(output, "Implantation des operations pour l'entité " +
- input.getName() + ".");
- setSuperClass(output, input.getQualifiedName() + "Abstract");
- }
+ ///////////////////////////////// OLD
-
// -------------------------------------------------------------------------
- // Interface generation
- // -------------------------------------------------------------------------
-
- @Deprecated
- private void generateInterfaceStaticColumnNames(ObjectModelClass input,
- ObjectModelInterface output) {
-
- for (ObjectModelAttribute attr : input.getAttributes()) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.isNavigable() &&
- !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
- reverse, model)
- && !attr.hasAssociationClass()) {
- continue;
- }
- String attrName;
- if (!attr.hasAssociationClass()) {
- attrName = attr.getName();
- } else {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- attrName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- }
- String attrColName = getConstantName(attrName);
- addAttribute(output,
- attrColName,
- String.class,
- "\"" + attrName + "\"",
- ObjectModelModifier.PACKAGE);
- }
-
- //Déclaration des noms des champs des attributs d'une classe d'associations
- if (input instanceof ObjectModelAssociationClass) {
- ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) input;
- for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) {
- if (attr != null) {
- String attrName = attr.getName();
- String attrColName = getConstantName(attrName);
- addAttribute(output,
- attrColName,
- String.class,
- "\"" + attrName + "\"",
- ObjectModelModifier.PACKAGE);
- }
- }
- }
- }
-
- @Deprecated
- private void generateInterfaceOperation(ObjectModelOperation op,
- ObjectModelInterface output) {
-
-
- String visibility = op.getVisibility();
- if (op.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO) ||
- !visibility.equals(ObjectModelModifier.PUBLIC.toString())) {
- // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
- return;
- }
-
- String opName = op.getName();
- String opType = op.getReturnType();
-
- ObjectModelOperation op2 = addOperation(output, opName, opType, ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(op)) {
- setDocumentation(op2, op.getDocumentation());
- }
-
- for (ObjectModelParameter param : op.getParameters()) {
- String paramName = param.getName();
- String paramType = param.getType();
- ObjectModelParameter param2 = addParameter(op2, paramType, paramName);
- if (TopiaGeneratorUtil.hasDocumentation(param)) {
- setDocumentation(param2, param.getDocumentation());
- }
- }
- for (String exception : op.getExceptions()) {
- addException(op2, exception);
- }
- }
-
- @Deprecated
- private void generateInterfaceAssociationAccessors(ObjectModelInterface output,
- String attrName,
- String attrType) {
-
- ObjectModelOperation op;
- ObjectModelParameter param;
-
- op = addOperation(output,
- "set" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- param = addParameter(op, attrType, "value");
- setDocumentation(param, "La valeur de l'attribut " + attrName + " à positionner.");
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(attrName),
- attrType,
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Retourne la valeur de l'attribut " + attrName + ".");
- }
-
- // -------------------------------------------------------------------------
// Abstract generation
// -------------------------------------------------------------------------
@@ -1598,6 +1381,7 @@
setOperationBody(op, body.length() == 0 ? " " : body.toString());
}
+ @Deprecated
protected void generateAcceptMethod(ObjectModelClass output,
ObjectModelClass clazz) {
@@ -1694,40 +1478,6 @@
setOperationBody(op, body.length() == 0 ? " " : body.toString());
}
-
- private void generateAssociationAccessors(ObjectModelClass output,
- String name, String type) {
- ObjectModelOperation op;
- op = addOperation(output,
- "set" + StringUtils.capitalize(name),
- "void",
- ObjectModelModifier.PUBLIC);
- addAnnotation(output, op, Override.class.getSimpleName());
- ObjectModelParameter param = addParameter(op, type, "value");
- setDocumentation(param, "La valeur de l'attribut " + name +
- " à positionner.");
- setOperationBody(op, ""
-/*{
- <%=type%> _oldValue = this.<%=GeneratorUtil.toLowerCaseFirstLetter(name)%>;
- fireOnPreWrite("<%=name%>", _oldValue, value);
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(name)%> = value;
- fireOnPostWrite("<%=name%>", _oldValue, value);
-}*/
- );
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(name),
- type,
- ObjectModelModifier.PUBLIC);
- addAnnotation(output, op, Override.class.getSimpleName());
- setOperationBody(op, ""
-/*{
- return <%=GeneratorUtil.toLowerCaseFirstLetter(name)%>;
-}*/
- );
-
- }
-
/**
* Generate entity methods which have not a public visibility. In this case, they will not be
* generated in the EntityInterface, so they will be generated here, in the EntityAbstract
@@ -1780,9 +1530,8 @@
buffer.append("\");");
}
-
// -------------------------------------------------------------------------
- // Impl generation
+ // Helpers
// -------------------------------------------------------------------------
protected boolean isAbstract(ObjectModelClass clazz) {
@@ -1820,11 +1569,14 @@
return false;
}
+ protected String getCollectionType(ObjectModelAttribute attribute) {
+ String result = null;
+ if (!associationClass && TopiaGeneratorUtil.isNMultiplicity(attribute)) {
+ result = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attribute);
+ }
+ return result;
+ }
- // -------------------------------------------------------------------------
- // Helpers
- // -------------------------------------------------------------------------
-
protected String getPropertyName(ObjectModelAttribute attribute) {
String propertyName = attribute.getName();
if (!associationClass && attribute.hasAssociationClass()) {
@@ -1841,6 +1593,13 @@
return propertyType;
}
+ protected ObjectModelOperation createImplOperation(ObjectModelOperation interfaceOperation) {
+ ObjectModelOperation implOperation =
+ cloneOperationSignature(interfaceOperation, outputAbstract);
+ addAnnotation(outputAbstract, implOperation, Override.class.getSimpleName());
+ return implOperation;
+ }
+
/**
* TODO-fdesbois-2010-06-25 : This method can be put in JavaBuilder or ObjectModelTransformerToJava
*
1
0
Author: tchemit
Date: 2010-06-27 08:36:23 +0200 (Sun, 27 Jun 2010)
New Revision: 2036
Url: http://nuiton.org/repositories/revision/topia/2036
Log:
Utilisation de mavenpom4redmine 2.2.1
Modified:
trunk/pom.xml
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-25 18:03:00 UTC (rev 2035)
+++ trunk/pom.xml 2010-06-27 06:36:23 UTC (rev 2036)
@@ -33,7 +33,7 @@
<parent>
<groupId>org.nuiton</groupId>
<artifactId>mavenpom4redmine</artifactId>
- <version>2.2</version>
+ <version>2.2.1</version>
</parent>
<artifactId>topia</artifactId>
1
0
r2035 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
Author: fdesbois
Date: 2010-06-25 20:03:00 +0200 (Fri, 25 Jun 2010)
New Revision: 2035
Url: http://nuiton.org/repositories/revision/topia/2035
Log:
Evo #609 : Refactor constant generation + clean generate header for interface
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-25 17:14:37 UTC (rev 2034)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-25 18:03:00 UTC (rev 2035)
@@ -95,6 +95,8 @@
protected ObjectModelClass outputImpl;
+ private boolean associationClass;
+
protected void clean() {
outputInterface = null;
outputAbstract = null;
@@ -140,10 +142,21 @@
outputInterface = createInterface(clazzName, packageName);
outputAbstract = createAbstractClass(clazzName + "Abstract", packageName);
- // Generate all methods needed for each entity attribute
- generateOperationsFromAttributes(input.getAttributes());
+ generateHeaders(input);
- generateInterface(input, outputInterface, attributes, operations);
+ generateProperties(input);
+
+ // Case of association class : properties from participants/extremities
+ // of the association class.
+ if (input instanceof ObjectModelAssociationClass) {
+ ObjectModelAssociationClass association = (ObjectModelAssociationClass)input;
+ generatePropertiesFromAssociation(association);
+ }
+
+ generateExtraConstants(input);
+
+ generateExtraOperations(input);
+
generateAbstract(input, outputAbstract, attributes, operations);
boolean generateImpl = isGenerateImpl(input, operations);
@@ -169,54 +182,104 @@
clean();
}
- protected boolean isGenerateImpl(ObjectModelClass input,
- Collection<ObjectModelOperation> operations) {
+ protected void generateHeaders(ObjectModelClass input) {
- String fqn = input.getQualifiedName() + "Impl";
+ ////// For Interface
+ addImport(outputInterface, TopiaEntity.class);
- URL fileLocation = getFileInClassPath(fqn);
+ if (TopiaGeneratorUtil.hasDocumentation(input)) {
+ setDocumentation(outputInterface, input.getDocumentation());
+ }
- if (fileLocation != null) {
+ // super interfaces
+ for (ObjectModelClassifier parent : input.getInterfaces()) {
+ addInterface(outputInterface, parent.getQualifiedName());
+ }
- // there is already a existing file in class-path, skip
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], found existing file in class-path : " + fileLocation);
+ boolean needTopiaEntity = true;
+ for (ObjectModelClassifier parent : input.getSuperclasses()) {
+ if (parent.hasStereotype(STEREOTYPE_ENTITY)) {
+ addInterface(outputInterface, parent.getQualifiedName());
+ needTopiaEntity = false;
+ break;
}
- return false;
}
- // On ne génère pas le impl si l'entité a des opérations qui ne sont
- // pas seulement pour le DAO
- if (!operations.isEmpty()) {
+ if (needTopiaEntity) {
+ addInterface(outputInterface, TopiaEntity.class);
+ }
+ }
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], there is some operations and not only DAO ones");
+ /**
+ * Generate properties from {@code input} entity class. Generate
+ * constant and operations for each property.
+ *
+ * @param input Input entity class
+ */
+ protected void generateProperties(ObjectModelClass input) {
+ for (ObjectModelAttribute attribute : input.getAttributes()) {
+
+ // FIXME-fdesbois-2010-06-25 : Stupid case, need to be removed
+ if (!attribute.isNavigable() && attribute.hasAssociationClass()) {
+ generatePropertyConstant(attribute);
}
- return false;
- }
- //De même, on ne génère pas le impl si il y a des opérations venant des
- // superclasses non implémentées
- for (ObjectModelOperation otherOp : input.getAllOtherOperations(false)) {
- if (otherOp.isAbstract()) {
- if (isVerbose()) {
- log.info("Will not generate [" + fqn + "], there is a abstract operation [" + otherOp.getName() + "] in allOtherOperations.");
- }
- return false;
+ if (!attribute.isNavigable() &&
+ !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
+ attribute.getReverseAttribute(), model)) {
+ continue;
}
+
+ generatePropertyConstant(attribute);
+
+ generatePropertyOperations(attribute);
}
+ }
- return true;
+ /**
+ * Generate properties from {@code input} entity assocation class. Generate
+ * constant and operations for each property.
+ *
+ * @param association Input entity association class
+ */
+ protected void generatePropertiesFromAssociation(ObjectModelAssociationClass association) {
+ associationClass = true;
+ for (ObjectModelAttribute attribute : association.getParticipantsAttributes()) {
+
+ generatePropertyConstant(attribute);
+
+ addSingleSetOperation(attribute);
+
+ addSingleGetOperation(attribute, null);
+ }
+ associationClass = false;
}
/**
- * Generation operations for each attribute from {@code attributes} collection.
- * One method is created for each operation to generate. Methods starting
+ * Generate constant in interface for {@code attribute}.
+ *
+ * @param attribute Input attribute to treate
+ * @see #getPropertyName(ObjectModelAttribute)
+ */
+ protected void generatePropertyConstant(ObjectModelAttribute attribute) {
+ String attrName = getPropertyName(attribute);
+
+ if (isVerbose()) {
+ log.info("Generate constant for property : " + attrName);
+ }
+
+ addAttribute(outputInterface, getConstantName(attrName), String.class,
+ "\"" + attrName + "\"");
+ }
+
+ /**
+ * Generation operations for {@code attributes}.
+ * One method exists for each operation to generate. Methods starting
* with 'addSingle' is for maxMultiplicity attribute = 1 and for collection
* case, methods start with 'addMultiple'. Other case are take care in each
* method (association class, reverse, entity reference, ...).
*
- * @param attributes Input attributes to treate
+ * @param attribute Input attribute to treate
* @see #addSingleGetOperation(ObjectModelAttribute, String)
* @see #addSingleSetOperation(ObjectModelAttribute)
* @see #addMultipleAddOperation(ObjectModelAttribute, String)
@@ -230,79 +293,154 @@
* @see #addMultipleSizeOperation(ObjectModelAttribute)
* @see #addMultipleIsEmptyOperation(ObjectModelAttribute)
*/
- protected void generateOperationsFromAttributes(Collection<ObjectModelAttribute> attributes) {
+ protected void generatePropertyOperations(ObjectModelAttribute attribute) {
- for (ObjectModelAttribute attribute : attributes) {
+ if (attribute.getMaxMultiplicity() == 1) {
- if (!attribute.isNavigable() &&
- !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
- attribute.getReverseAttribute(), model)) {
- continue;
- }
+ // setXXX
+ addSingleSetOperation(attribute);
- if (attribute.getMaxMultiplicity() == 1) {
+ // getXXX
+ addSingleGetOperation(attribute, null);
- // setXXX
- addSingleSetOperation(attribute);
+ } else {
- // getXXX
- addSingleGetOperation(attribute, null);
+ // List, Set or Collection ?
+ String collectionInterface =
+ TopiaGeneratorUtil.getNMultiplicityInterfaceType(attribute);
+ String collectionImpl =
+ TopiaGeneratorUtil.getNMultiplicityObjectType(attribute);
- } else {
+ addImport(outputInterface, collectionInterface);
+ addImport(outputAbstract, collectionInterface);
+ addImport(outputAbstract, collectionImpl);
- // List, Set or Collection ?
- String collectionInterface =
- TopiaGeneratorUtil.getNMultiplicityInterfaceType(attribute);
- String collectionImpl =
- TopiaGeneratorUtil.getNMultiplicityObjectType(attribute);
+ collectionInterface =
+ TopiaGeneratorUtil.getSimpleName(collectionInterface);
+ collectionImpl =
+ TopiaGeneratorUtil.getSimpleName(collectionImpl);
- addImport(outputInterface, collectionInterface);
- addImport(outputAbstract, collectionInterface);
- addImport(outputAbstract, collectionImpl);
+ // addXXX
+ addMultipleAddOperation(attribute, collectionImpl);
- collectionInterface =
- TopiaGeneratorUtil.getSimpleName(collectionInterface);
- collectionImpl =
- TopiaGeneratorUtil.getSimpleName(collectionImpl);
+ // addAllXXX
+ addMultipleAddAllOperation(attribute, collectionInterface);
- // addXXX
- addMultipleAddOperation(attribute, collectionImpl);
+ // setXXX
+ addMultipleSetOperation(attribute, collectionInterface, collectionImpl);
- // addAllXXX
- addMultipleAddAllOperation(attribute, collectionInterface);
+ // removeXXX
+ addMultipleRemoveOperation(attribute);
- // setXXX
- addMultipleSetOperation(attribute, collectionInterface, collectionImpl);
+ // clearXXX
+ addMultipleClearOperation(attribute, collectionInterface, collectionImpl);
- // removeXXX
- addMultipleRemoveOperation(attribute);
+ // getXXX
+ addMultipleGetOperation(attribute, collectionInterface);
- // clearXXX
- addMultipleClearOperation(attribute, collectionInterface, collectionImpl);
+ if (!TopiaGeneratorUtil.isPrimitiveType(attribute) &&
+ !TopiaGeneratorUtil.isDateType(attribute)) {
- // getXXX
- addMultipleGetOperation(attribute, collectionInterface);
+ // getXXXByTopiaId
+ addMultipleGetTopiaIdOperation(attribute);
+ }
- if (!TopiaGeneratorUtil.isPrimitiveType(attribute) &&
- !TopiaGeneratorUtil.isDateType(attribute)) {
+ if (attribute.hasAssociationClass()) {
+ // getXXX with entity parameter
+ addMultipleGetOperationFromEntity(attribute);
+ }
- // getXXXByTopiaId
- addMultipleGetTopiaIdOperation(attribute);
- }
+ // sizeXXX
+ addMultipleSizeOperation(attribute);
- if (attribute.hasAssociationClass()) {
- // getXXX with entity parameter
- addMultipleGetOperationFromEntity(attribute);
+ // isXXXEmpty
+ addMultipleIsEmptyOperation(attribute);
+ }
+ }
+
+ /**
+ * Generate extra constants if {@code input} has dependencies on
+ * enum used as constant injector.
+ *
+ * @param input Entity class to treate
+ */
+ protected void generateExtraConstants(ObjectModelClass input) {
+ Set<String> constants = addConstantsFromDependency(input, outputInterface);
+
+ if (log.isDebugEnabled()) {
+ log.debug("Add constants from dependency : " + constants);
+ }
+ }
+
+ protected void generateExtraOperations(ObjectModelClass input) {
+ for (ObjectModelOperation operation : input.getOperations()) {
+ String visibility = operation.getVisibility();
+ if (operation.hasStereotype(TopiaGeneratorUtil.STEREOTYPE_DAO) ||
+ !visibility.equals(ObjectModelModifier.PUBLIC.toString())) {
+ // Pas de génération des signatures de méthodes pour celles à intégrer au DAO de l'entité
+ return;
+ }
+
+ String opName = operation.getName();
+ String opType = operation.getReturnType();
+
+ ObjectModelOperation op2 = addOperation(outputInterface, opName, opType, ObjectModelModifier.PACKAGE);
+ if (TopiaGeneratorUtil.hasDocumentation(operation)) {
+ setDocumentation(op2, operation.getDocumentation());
+ }
+
+ for (ObjectModelParameter param : operation.getParameters()) {
+ String paramName = param.getName();
+ String paramType = param.getType();
+ ObjectModelParameter param2 = addParameter(op2, paramType, paramName);
+ if (TopiaGeneratorUtil.hasDocumentation(param)) {
+ setDocumentation(param2, param.getDocumentation());
}
+ }
+ for (String exception : operation.getExceptions()) {
+ addException(op2, exception);
+ }
+ }
+ }
- // sizeXXX
- addMultipleSizeOperation(attribute);
+ protected boolean isGenerateImpl(ObjectModelClass input,
+ Collection<ObjectModelOperation> operations) {
- // isXXXEmpty
- addMultipleIsEmptyOperation(attribute);
+ String fqn = input.getQualifiedName() + "Impl";
+
+ URL fileLocation = getFileInClassPath(fqn);
+
+ if (fileLocation != null) {
+
+ // there is already a existing file in class-path, skip
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], found existing file in class-path : " + fileLocation);
}
+ return false;
+ }
+ // On ne génère pas le impl si l'entité a des opérations qui ne sont
+ // pas seulement pour le DAO
+ if (!operations.isEmpty()) {
+
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], there is some operations and not only DAO ones");
+ }
+ return false;
}
+
+ //De même, on ne génère pas le impl si il y a des opérations venant des
+ // superclasses non implémentées
+ for (ObjectModelOperation otherOp : input.getAllOtherOperations(false)) {
+ if (otherOp.isAbstract()) {
+ if (isVerbose()) {
+ log.info("Will not generate [" + fqn + "], there is a abstract operation [" + otherOp.getName() + "] in allOtherOperations.");
+ }
+ return false;
+ }
+ }
+
+ return true;
}
protected void addSingleSetOperation(ObjectModelAttribute attribute) {
@@ -310,6 +448,11 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
+ if (isVerbose()) {
+ log.info("Generate single 'set' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
createPropertySetterSignature(outputInterface, attrType, attrName,
@@ -351,9 +494,9 @@
operationPrefix = TopiaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX;
}
- if (log.isDebugEnabled()) {
- log.debug("Add getter operation for " + attrName +
- " prefix = " + operationPrefix);
+ if (isVerbose()) {
+ log.info("Generate single '" + operationPrefix + "' operation for property : "
+ + attrName + " [" + attrType + "]");
}
// Interface operation
@@ -395,6 +538,11 @@
String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
+ if (isVerbose()) {
+ log.info("Generate multiple 'add' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "add" + StringUtils.capitalize(attrName),
@@ -461,6 +609,11 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
+ if (isVerbose()) {
+ log.info("Generate multiple 'addAll' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "addAll" + StringUtils.capitalize(attrName),
@@ -498,6 +651,11 @@
String referenceType = getPropertyType(attribute);
String attrType = collectionInterface + "<" + referenceType + ">";
+ if (isVerbose()) {
+ log.info("Generate multiple 'set' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
createPropertySetterSignature(outputInterface, attrType, attrName,
@@ -527,6 +685,11 @@
String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
+ if (isVerbose()) {
+ log.info("Generate 'remove' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "remove" + StringUtils.capitalize(attrName),
@@ -591,6 +754,11 @@
String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
+ if (isVerbose()) {
+ log.info("Generate multiple 'clear' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "clear" + StringUtils.capitalize(attrName),
@@ -655,6 +823,11 @@
String attrName = getPropertyName(attribute);
String attrType = collectionInterface + "<" + getPropertyType(attribute) + ">";
+ if (isVerbose()) {
+ log.info("Generate multiple 'get' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "get" + StringUtils.capitalize(attrName),
@@ -679,6 +852,11 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
+ if (isVerbose()) {
+ log.info("Generate multiple 'getByTopiaId' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "get" + StringUtils.capitalize(attrName) + "ByTopiaId",
@@ -714,6 +892,11 @@
String attrName = getPropertyName(attribute);
String attrType = getPropertyType(attribute);
+ if (isVerbose()) {
+ log.info("Generate multiple 'getFromEntity' operation for property : " + attrName +
+ " [" + attrType + "]");
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface,
@@ -749,6 +932,10 @@
String attrName = getPropertyName(attribute);
+ if (isVerbose()) {
+ log.info("Generate multiple 'size' operation for property : " + attrName);
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "size" + StringUtils.capitalize(attrName),
@@ -775,6 +962,10 @@
String attrName = getPropertyName(attribute);
+ if (isVerbose()) {
+ log.info("Generate multiple 'isEmpty' operation for property : " + attrName);
+ }
+
// Interface operation
ObjectModelOperation interfaceOperation =
addOperation(outputInterface, "is" + StringUtils.capitalize(attrName) + "Empty",
@@ -798,6 +989,7 @@
///////////////////////////////// OLD
+ @Deprecated
protected void generateInterface(ObjectModelClass input,
ObjectModelInterface output,
Collection<ObjectModelAttribute> attributes,
@@ -862,6 +1054,7 @@
}
}
+ @Deprecated
protected void generateAbstract(ObjectModelClass input,
ObjectModelClass output,
Collection<ObjectModelAttribute> attributes,
@@ -1057,20 +1250,20 @@
// transformAttribute(output, attr, reverse);
// }
-
+ // DONE
//Méthodes d'accès aux attributs d'une classe d'associations
- if (input instanceof ObjectModelAssociationClass) {
+// if (input instanceof ObjectModelAssociationClass) {
+//
+// for (ObjectModelAttribute attr :
+// ((ObjectModelAssociationClass) input).getParticipantsAttributes()) {
+// if (attr != null) {
+// String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
+// String attrName = attr.getName();
+// generateAssociationAccessors(output, attrName, attrType);
+// }
+// }
+// }
- for (ObjectModelAttribute attr :
- ((ObjectModelAssociationClass) input).getParticipantsAttributes()) {
- if (attr != null) {
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- String attrName = attr.getName();
- generateAssociationAccessors(output, attrName, attrType);
- }
- }
- }
-
generateAbstractMethods(output, input);
boolean doGenerateToString = TopiaGeneratorUtil.generateToString(input,
@@ -1100,15 +1293,16 @@
// Interface generation
// -------------------------------------------------------------------------
+ @Deprecated
private void generateInterfaceStaticColumnNames(ObjectModelClass input,
ObjectModelInterface output) {
for (ObjectModelAttribute attr : input.getAttributes()) {
ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!(attr.isNavigable() ||
- TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
+ if (!attr.isNavigable() &&
+ !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
reverse, model)
- || attr.hasAssociationClass())) {
+ && !attr.hasAssociationClass()) {
continue;
}
String attrName;
@@ -1143,6 +1337,7 @@
}
}
+ @Deprecated
private void generateInterfaceOperation(ObjectModelOperation op,
ObjectModelInterface output) {
@@ -1175,6 +1370,7 @@
}
}
+ @Deprecated
private void generateInterfaceAssociationAccessors(ObjectModelInterface output,
String attrName,
String attrType) {
@@ -1631,7 +1827,7 @@
protected String getPropertyName(ObjectModelAttribute attribute) {
String propertyName = attribute.getName();
- if (attribute.hasAssociationClass()) {
+ if (!associationClass && attribute.hasAssociationClass()) {
propertyName = TopiaGeneratorUtil.getAssocAttrName(attribute);
}
return propertyName;
@@ -1639,7 +1835,7 @@
protected String getPropertyType(ObjectModelAttribute attribute) {
String propertyType = attribute.getType();
- if (attribute.hasAssociationClass()) {
+ if (!associationClass && attribute.hasAssociationClass()) {
propertyType = attribute.getAssociationClass().getQualifiedName();
}
return propertyType;
1
0
Author: fdesbois
Date: 2010-06-25 19:14:37 +0200 (Fri, 25 Jun 2010)
New Revision: 2034
Url: http://nuiton.org/repositories/revision/topia/2034
Log:
Remove goal copyVersionFiles + add EntityTransformer template
Modified:
trunk/topia-service-security/pom.xml
Modified: trunk/topia-service-security/pom.xml
===================================================================
--- trunk/topia-service-security/pom.xml 2010-06-25 13:12:59 UTC (rev 2033)
+++ trunk/topia-service-security/pom.xml 2010-06-25 17:14:37 UTC (rev 2034)
@@ -119,18 +119,26 @@
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
- <templates>org.nuiton.topia.generator.TopiaMetaTransformer</templates>
+ <templates>
+ org.nuiton.topia.generator.TopiaMetaTransformer,
+ org.nuiton.topia.generator.EntityTransformer
+ </templates>
+ <excludeTemplates>
+ <excludeTemplate>org.nuiton.topia.generator.EntityAbstractTransformer</excludeTemplate>
+ <excludeTemplate>org.nuiton.topia.generator.EntityImplTransformer</excludeTemplate>
+ <excludeTemplate>org.nuiton.topia.generator.EntityInterfaceTransformer</excludeTemplate>
+ </excludeTemplates>
<defaultPackage>org.nuiton.topia</defaultPackage>
<fullPackagePath>org.nuiton.topia</fullPackagePath>
- <includes>**/*.objectmodel</includes>
- <copyVersionDir>${maven.src.dir}/main/resources/oldmappings/%MODELNAME%</copyVersionDir>
- <copyVersionFiles>**/*.hbm.xml</copyVersionFiles>
+ <!--<includes>**/*.objectmodel</includes>-->
+ <!--<copyVersionDir>${maven.src.dir}/main/resources/oldmappings/%MODELNAME%</copyVersionDir>-->
+ <!--<copyVersionFiles>**/*.hbm.xml</copyVersionFiles>-->
<overwrite>true</overwrite>
</configuration>
<goals>
<goal>smart-generate</goal>
- <goal>copyVersionFiles</goal>
+ <!--<goal>copyVersionFiles</goal>-->
</goals>
</execution>
</executions>
1
0
r2033 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
Author: fdesbois
Date: 2010-06-25 15:12:59 +0200 (Fri, 25 Jun 2010)
New Revision: 2033
Url: http://nuiton.org/repositories/revision/topia/2033
Log:
Evo #609 : Remove old ugly code + add some javadoc
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-25 12:41:09 UTC (rev 2032)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-25 13:12:59 UTC (rev 2033)
@@ -140,7 +140,8 @@
outputInterface = createInterface(clazzName, packageName);
outputAbstract = createAbstractClass(clazzName + "Abstract", packageName);
- //generateOperationsFromAttributes(input.getAttributes()); is executed in generateInterface
+ // Generate all methods needed for each entity attribute
+ generateOperationsFromAttributes(input.getAttributes());
generateInterface(input, outputInterface, attributes, operations);
generateAbstract(input, outputAbstract, attributes, operations);
@@ -208,6 +209,27 @@
return true;
}
+ /**
+ * Generation operations for each attribute from {@code attributes} collection.
+ * One method is created for each operation to generate. Methods starting
+ * with 'addSingle' is for maxMultiplicity attribute = 1 and for collection
+ * case, methods start with 'addMultiple'. Other case are take care in each
+ * method (association class, reverse, entity reference, ...).
+ *
+ * @param attributes Input attributes to treate
+ * @see #addSingleGetOperation(ObjectModelAttribute, String)
+ * @see #addSingleSetOperation(ObjectModelAttribute)
+ * @see #addMultipleAddOperation(ObjectModelAttribute, String)
+ * @see #addMultipleAddAllOperation(ObjectModelAttribute, String)
+ * @see #addMultipleSetOperation(ObjectModelAttribute, String, String)
+ * @see #addMultipleRemoveOperation(ObjectModelAttribute)
+ * @see #addMultipleClearOperation(ObjectModelAttribute, String, String)
+ * @see #addMultipleGetOperation(ObjectModelAttribute, String)
+ * @see #addMultipleGetTopiaIdOperation(ObjectModelAttribute)
+ * @see #addMultipleGetOperationFromEntity(ObjectModelAttribute)
+ * @see #addMultipleSizeOperation(ObjectModelAttribute)
+ * @see #addMultipleIsEmptyOperation(ObjectModelAttribute)
+ */
protected void generateOperationsFromAttributes(Collection<ObjectModelAttribute> attributes) {
for (ObjectModelAttribute attribute : attributes) {
@@ -283,44 +305,6 @@
}
}
- protected String getPropertyName(ObjectModelAttribute attribute) {
- String propertyName = attribute.getName();
- if (attribute.hasAssociationClass()) {
- propertyName = TopiaGeneratorUtil.getAssocAttrName(attribute);
- }
- return propertyName;
- }
-
- protected String getPropertyType(ObjectModelAttribute attribute) {
- String propertyType = attribute.getType();
- if (attribute.hasAssociationClass()) {
- propertyType = attribute.getAssociationClass().getQualifiedName();
- }
- return propertyType;
- }
-
- // 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 addSingleSetOperation(ObjectModelAttribute attribute) {
String attrName = getPropertyName(attribute);
@@ -677,10 +661,6 @@
attrType, ObjectModelModifier.PACKAGE);
// Documentation
-// if (TopiaGeneratorUtil.hasDocumentation(attribute)) {
-// // ??
-// setDocumentation(interfaceOperation, "Retourne la collection.");
-// }
setDocumentation(interfaceOperation, "Retourne la collection.");
// Implementation
@@ -856,28 +836,6 @@
generateInterfaceStaticColumnNames(input, output);
- // attributes
-
- generateOperationsFromAttributes(attributes);
-
-// for (ObjectModelAttribute attr : attributes) {
-// ObjectModelAttribute reverse = attr.getReverseAttribute();
-// if (!attr.isNavigable() &&
-// !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
-// reverse, model)) {
-// continue;
-// }
-//
-// if (attr.hasAssociationClass()) {
-//
-// addInterfaceAssociationAttribute(output, attr);
-//
-// } else {
-// //addInterfaceNoneAssociationAttribute(output, attr);
-// }
-// }
-
-
//Méthodes d'accès aux attributs d'une classe d'associations
if (input instanceof ObjectModelAssociationClass) {
@@ -1185,129 +1143,6 @@
}
}
- @Deprecated
- protected void addInterfaceAssociationAttribute(ObjectModelInterface output,
- ObjectModelAttribute attr) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- String assocClassName = attr.getAssociationClass().getName();
-
- ObjectModelOperation op;
- ObjectModelParameter attr2;
-
- // Ok
- if (!GeneratorUtil.isNMultiplicity(attr) && false) {
-
- // setXXX
-
- op = addOperation(output,
- "set" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- attr2 = addParameter(op, assocClassFQN, GeneratorUtil.toLowerCaseFirstLetter(assocClassName));
- setDocumentation(attr2, "La valeur de l'attribut " + assocClassName + " à positionner");
-
- // getXXX : getter interface for association attribute with unique multiplicity
-
- addOperation(output,
- "get" + StringUtils.capitalize(assocAttrName),
- assocClassFQN,
- ObjectModelModifier.PACKAGE);
-
- } else if (GeneratorUtil.isNMultiplicity(attr)) {
- String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
-
- // addXXX
-
- op = addOperation(output,
- "add" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- attr2 = addParameter(op, assocClassFQN, GeneratorUtil.toLowerCaseFirstLetter(assocClassName));
- setDocumentation(attr2, "L'instance de " + assocClassName + " à ajouter");
-
- // addAllXXX
-
- op = addOperation(output,
- "addAll" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- attr2 = addParameter(op, collectionInterface + "<" + assocClassFQN + ">", GeneratorUtil.toLowerCaseFirstLetter(assocClassName));
- setDocumentation(attr2, "Les instances de " + assocClassName + " à ajouter");
-
- // setXXX
-
- op = addOperation(output,
- "set" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- attr2 = addParameter(op, collectionInterface + "<" + assocClassFQN + ">", GeneratorUtil.toLowerCaseFirstLetter(assocClassName));
- setDocumentation(attr2, "La Collection de " + assocClassName + " à ajouter");
-
- // removeXXX
-
- op = addOperation(output,
- "remove" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- attr2 = addParameter(op, assocClassFQN, GeneratorUtil.toLowerCaseFirstLetter(assocClassName));
- setDocumentation(attr2, "L'instance de " + assocClassName + " à retirer");
-
- // clearXXX
-
- op = addOperation(output,
- "clear" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Vide la Collection de " + assocClassName + " .");
-
- // getXXX
-
- addOperation(output,
- "get" + StringUtils.capitalize(assocAttrName),
- collectionInterface + "<" + assocClassFQN + ">",
- ObjectModelModifier.PACKAGE);
-
- if (!TopiaGeneratorUtil.isPrimitiveType(attr) && !TopiaGeneratorUtil.isDateType(attr)) {
-
- // getXXXByTopiaId
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(assocAttrName) + "ByTopiaId",
- assocClassFQN,
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Recupère l'attribut " + attrName + " à partir de son topiaId");
- attr2 = addParameter(op, String.class, "topiaId");
- setDocumentation(attr2, "le topia id de l'entité recherchée");
- }
-
- // getXXX
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(assocAttrName),
- assocClassFQN);
- addParameter(op, attrType, "value");
-
-
- // sizeXXX
-
- addOperation(output,
- "size" + StringUtils.capitalize(assocAttrName),
- int.class,
- ObjectModelModifier.PACKAGE);
-
-
- // isXXXEmpty
-
- addOperation(output,
- "is" + StringUtils.capitalize(assocAttrName) + "Empty",
- boolean.class,
- ObjectModelModifier.PACKAGE);
- }
- }
-
private void generateInterfaceOperation(ObjectModelOperation op,
ObjectModelInterface output) {
@@ -1365,566 +1200,6 @@
// Abstract generation
// -------------------------------------------------------------------------
- @Deprecated
- protected void transformAttribute(ObjectModelClass result,
- ObjectModelAttribute attr,
- ObjectModelAttribute reverse) {
-
- String attrName = attr.getName();
- String attrType = TopiaGeneratorUtil.getSimpleName(attr.getType());
- addImport(result, attrType);
-
- attrType = TopiaGeneratorUtil.getSimpleName(attrType);
-
- ObjectModelOperation op;
-
- // Ok for both
- if (!GeneratorUtil.isNMultiplicity(attr) && false) {
-
- if (attr.hasAssociationClass()) {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
- addImport(result, assocClassFQN);
- assocClassFQN = TopiaGeneratorUtil.getSimpleName(assocClassFQN);
- String name = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
-
- // setXXX : DONE
-
- op = addOperation(result,
- "set" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, assocClassFQN, "association");
- setOperationBody(op, ""
-/*{
- <%=assocClassFQN%> _oldValue = this.<%=name%>;
- fireOnPreWrite(<%=getConstantName(name)%>, _oldValue, association);
- this.<%=name%> = association;
- fireOnPostWrite(<%=getConstantName(name)%>, _oldValue, association);
-}*/
- );
-
- // getXXX : getter for association attribute with unique multiplicity : DONE
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(assocAttrName),
- assocClassFQN, ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- return <%=name%>;
-}*/
- );
- // Code is refactored and generated with correct methods, see generateOperationsFromAttributes
- } else if (false) {
- // DONE
-
- // setXXX
-
- op = addOperation(result,
- "set" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, attrType, "value");
- setOperationBody(op, ""
-/*{
- <%=attrType%> _oldValue = this.<%=attrName%>;
- fireOnPreWrite(<%=getConstantName(attrName)%>, _oldValue, value);
- this.<%=attrName%> = value;
- fireOnPostWrite(<%=getConstantName(attrName)%>, _oldValue, value);
-}*/
-
- );
-
- // getXXX : getter for simple attribute (as bean convention)
-
- // Getter is already set in abstract when added in interface
- // see {@link #addSimpleGetterOperation(ObjectModelAttribute, String)}
-
- }
- } else if (GeneratorUtil.isNMultiplicity(attr)) { //NMultiplicity
- String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
- String collectionObject = TopiaGeneratorUtil.getNMultiplicityObjectType(attr);
- addImport(result, collectionInterface);
- addImport(result, collectionObject);
- collectionInterface = TopiaGeneratorUtil.getSimpleName(collectionInterface);
- collectionObject = TopiaGeneratorUtil.getSimpleName(collectionObject);
-
- // 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 : DONE
-
- op = addOperation(result,
- "add" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, attrType, attrName);
- StringBuilder body = new StringBuilder();
-
- body.append(""
-/*{
- fireOnPreWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>);
- if (this.<%=attrName%> == null) {
- this.<%=attrName%> = new <%=collectionObject%><<%=attrType%>>();
- }
-}*/
- );
-
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- String reverseAttrType = TopiaGeneratorUtil.getSimpleName(reverse.getType());
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
- body.append(""
-/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(this);
-}*/
- );
- } else {
- body.append(""
-/*{ if (<%=attrName%>.get<%=StringUtils.capitalize(reverseAttrName)%>() == null) {
- <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(new <%=collectionObject%><<%=reverseAttrType%>>());
- }
- <%=attrName%>.get<%=StringUtils.capitalize(reverseAttrName)%>().add(this);
-}*/
- );
- }
- }
- body.append(""
-/*{ this.<%=attrName%>.add(<%=attrName%>);
- fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size(), null, <%=attrName%>);
-}*/
- );
- setOperationBody(op, body.toString());
-
- // addAllXXX : DONE
-
- op = addOperation(result,
- "addAll" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + '<' + attrType + '>', "values");
-
- setOperationBody(op, ""
-/*{
- if (values == null) {
- return;
- }
- for (<%=attrType%> item : values) {
- add<%=StringUtils.capitalize(attrName)%>(item);
- }
-}*/
- );
-
- // getXXXByTopiaId : DONE
-
- if (!TopiaGeneratorUtil.isPrimitiveType(attr) &&
- !TopiaGeneratorUtil.isDateType(attr)) {
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(attrName) + "ByTopiaId",
- attrType,
- ObjectModelModifier.PUBLIC);
- addParameter(op, String.class, "topiaId");
- setOperationBody(op, ""
-/*{
- return org.nuiton.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=attrName%>, topiaId);
- }*/
- );
-
- }
-
- // setXXX : DONE
-
- op = addOperation(result,
- "set" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + '<' + attrType + '>', "values");
-
- setOperationBody(op, ""
-/*{
- <%=collectionInterface%><<%=attrType%>> _oldValue = <%=attrName%>;
- fireOnPreWrite(<%=getConstantName(attrName)%>, _oldValue, values);
- <%=attrName%> = values;
- fireOnPostWrite(<%=getConstantName(attrName)%>, _oldValue, values);
-}*/
- );
-
-
- // removeXXX : DONE
-
-
- op = addOperation(result,
- "remove" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, attrType, "value");
- body = new StringBuilder();
-
- body.append(""
-/*{
- fireOnPreWrite(<%=getConstantName(attrName)%>, value, null);
- if ((this.<%=attrName%> == null) || (!this.<%=attrName%>.remove(value))) {
- throw new IllegalArgumentException("List does not contain given element");
- }
-}*/
- );
-
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
- body.append(""
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- );
- } else {
- body.append(""
-/*{ value.get<%=StringUtils.capitalize(reverseAttrName)%>().remove(this);
-}*/
- );
- }
- }
- body.append(""
-/*{ fireOnPostWrite(<%=getConstantName(attrName)%>, this.<%=attrName%>.size()+1, value, null);
-}*/
- );
- setOperationBody(op, body.toString());
-
-
- // clearXXX : DONE
-
- op = addOperation(result,
- "clear" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PUBLIC);
-
- body = new StringBuilder();
-
- body.append(""
-/*{
- if (this.<%=attrName%> == null) {
- return;
- }
-}*/
- );
-
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- body.append(""
-/*{ for (<%=attrType%> item : this.<%=attrName%>) {
-}*/
- );
- if (!GeneratorUtil.isNMultiplicity(reverse)) {
- body.append(""
-/*{ item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- );
- } else {
- body.append(""
-/*{ item.get<%=StringUtils.capitalize(reverseAttrName)%>().remove(this);
-}*/
- );
- }
- body.append(""
-/*{ }
-}*/
- );
- }
- body.append(""
-/*{ <%=collectionInterface%><<%=attrType%>> _oldValue = new <%=collectionObject%><<%=attrType%>>(this.<%=attrName%>);
- fireOnPreWrite(<%=getConstantName(attrName)%>, _oldValue, this.<%=attrName%>);
- this.<%=attrName%>.clear();
- fireOnPostWrite(<%=getConstantName(attrName)%>, _oldValue, this.<%=attrName%>);
-}*/
- );
-
- setOperationBody(op, body.toString());
-
- } else if (attr.hasAssociationClass()) {
-
-
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-// String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
-
- // addXXX
-
- op = addOperation(result,
- "add" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
-
- StringBuilder body = new StringBuilder();
-
- body.append(""
-/*{
- fireOnPreWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, null, value);
- if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = new <%=collectionObject%><<%=assocClassFQN%>>();
- }
-}*/
- );
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- body.append(""
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(this);
-}*/
- );
- }
- body.append(""
-/*{ this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.add(value);
- fireOnPostWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size(), null, value);
-}*/
- );
- setOperationBody(op, body.toString());
-
-
- if (!TopiaGeneratorUtil.isPrimitiveType(attr) &&
- !TopiaGeneratorUtil.isDateType(attr)) {
-
- // getXXXByTopiaId
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(assocAttrName) + "ByTopiaId",
- assocClassFQN,
- ObjectModelModifier.PUBLIC);
- addParameter(op, String.class, "topiaId");
- setOperationBody(op, ""
-/*{
- return org.nuiton.topia.persistence.util.TopiaEntityHelper.getEntityByTopiaId(<%=assocAttrName%>, topiaId);
-}*/
- );
-
- }
-
- // addAllXXX
-
- op = addOperation(result,
- "addAll" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + '<' + assocClassFQN + '>', "values");
- setOperationBody(op, ""
-/*{
- if (values == null) {
- return;
- }
- for (<%=assocClassFQN%> item : values) {
- add<%=StringUtils.capitalize(assocAttrName)%>(item);
- }
-}*/
- );
-
- // setXXX
-
- op = addOperation(result,
- "set" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, collectionInterface + '<' + assocClassFQN + '>', "values");
- setOperationBody(op, ""
-/*{
-// clear<%=StringUtils.capitalize(assocAttrName)%>();
-// addAll<%=StringUtils.capitalize(assocAttrName)%>(values);
-// FIXME
- <%=collectionInterface%><<%=assocClassFQN%>> _oldValue = <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
- fireOnPreWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, _oldValue, values);
- <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values;
- fireOnPostWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, _oldValue, values);
-}*/
- );
-
- // removeXXX
-
- op = addOperation(result,
- "remove" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
- addParameter(op, assocClassFQN, "value");
-
- body = new StringBuilder();
-
- body.append(""
-/*{
- fireOnPreWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, value, null);
- if ((this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) || (!this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.remove(value))) {
- throw new IllegalArgumentException("List does not contain given element");
- }
-}*/
- );
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- body.append(""
-/*{ value.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
-}*/
- );
- }
- body.append(""
-/*{ fireOnPostWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size()+1, value, null);
-}*/
- );
-
- setOperationBody(op, body.toString());
-
- // clearXXX
-
- op = addOperation(result,
- "clear" + StringUtils.capitalize(assocAttrName),
- "void",
- ObjectModelModifier.PUBLIC);
-
- body = new StringBuilder();
-
- body.append(""
-/*{
- if (this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return;
- }
-}*/
- );
-
- if (reverse != null && (reverse.isNavigable() ||
- hasUnidirectionalRelationOnAbstractType(attr, model))) {
- String reverseAttrName = reverse.getName();
- body.append(""
-/*{ for (<%=assocClassFQN%> item : this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>) {
- item.set<%=StringUtils.capitalize(reverseAttrName)%>(null);
- }
-}*/
- );
- }
- body.append(""
-/*{ <%=collectionInterface%><<%=assocClassFQN%>> _oldValue = new <%=collectionObject%><<%=assocClassFQN%>>(this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>);
- fireOnPreWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, _oldValue, null);
- this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.clear();
- fireOnPostWrite(<%=getConstantName(GeneratorUtil.toLowerCaseFirstLetter(assocAttrName))%>, _oldValue, null);
-}*/
- );
- setOperationBody(op, body.toString());
- }
-
- // Code is refactored and generated with correct methods, see generateOperationsFromAttributes
- if (!attr.hasAssociationClass() && false) {
-
- // getXXX : getter for collection entity attribute (N multiplicity) : DONE
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(attrName),
- collectionInterface + '<' + attrType + '>',
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- return <%=attrName%>;
-}*/
- );
-
- // sizeXXX : DONE
-
- op = addOperation(result,
- "size" + StringUtils.capitalize(attrName),
- int.class,
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- if (<%=attrName%> == null) {
- return 0;
- }
- return <%=attrName%>.size();
-}*/
- );
-
- // isXXXEmpty : DONE
-
- op = addOperation(result,
- "is" + StringUtils.capitalize(attrName) + "Empty",
- boolean.class,
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- int size = size<%=StringUtils.capitalize(attrName)%>();
- return size == 0;
-}*/
- );
-
- } else if (attr.hasAssociationClass()) {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
- String assocClassFQN = attr.getAssociationClass().getQualifiedName();
-// String assocClassFQN = TopiaGeneratorUtil.getSimpleName(attr.getAssociationClass().getQualifiedName());
-
- // getXXX : getter for association attribute with no parameter
- // (return a collection)
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(assocAttrName),
- collectionInterface + '<' + assocClassFQN + '>',
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>;
-}*/
- );
-
- // getXXX : getter for association attribute with one parameter
- // (return a single element)
-
- op = addOperation(result,
- "get" + StringUtils.capitalize(assocAttrName),
- assocClassFQN,
- ObjectModelModifier.PUBLIC);
- addParameter(op, attrType, "value");
- setOperationBody(op, ""
-/*{
- if (value == null || <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return null;
- }
- for (<%=assocClassFQN%> item : <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>) {
- if (value.equals(item.get<%=StringUtils.capitalize(attrName)%>())) {
- return item;
- }
- }
- return null;
-}*/
- );
-
-
- // sizeXXX
-
- op = addOperation(result,
- "size" + StringUtils.capitalize(assocAttrName),
- int.class,
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- if (<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> == null) {
- return 0;
- }
- return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>.size();
-}*/
- );
-
- //isXXXEmpty
-
- op = addOperation(result,
- "is" + StringUtils.capitalize(assocAttrName) + "Empty",
- boolean.class,
- ObjectModelModifier.PUBLIC);
- setOperationBody(op, ""
-/*{
- int size = size<%=StringUtils.capitalize(assocAttrName)%>();
- return size == 0;
-}*/
- );
-
- }
- }
- }
-
protected void generateToStringMethod(ObjectModelClass output,
ObjectModelClass clazz) {
if (log.isDebugEnabled()) {
@@ -2349,4 +1624,61 @@
return false;
}
+
+ // -------------------------------------------------------------------------
+ // Helpers
+ // -------------------------------------------------------------------------
+
+ protected String getPropertyName(ObjectModelAttribute attribute) {
+ String propertyName = attribute.getName();
+ if (attribute.hasAssociationClass()) {
+ propertyName = TopiaGeneratorUtil.getAssocAttrName(attribute);
+ }
+ return propertyName;
+ }
+
+ protected String getPropertyType(ObjectModelAttribute attribute) {
+ String propertyType = attribute.getType();
+ if (attribute.hasAssociationClass()) {
+ propertyType = attribute.getAssociationClass().getQualifiedName();
+ }
+ return propertyType;
+ }
+
+ /**
+ * TODO-fdesbois-2010-06-25 : This method can be put in JavaBuilder or ObjectModelTransformerToJava
+ *
+ * This method create an set operation in {@code classifier} with
+ * {@code propertyType} as return type and {@code propertyName} used for
+ * operation name ('set[propertyName]'). {@code operationDocument} can
+ * also be added to the operation created. Only signature with default
+ * visibility will be added.
+ *
+ * @param classifier Classifier where the operation will be added
+ * @param propertyType Type of the property (better if qualified name)
+ * @param propertyName Name of the property to set
+ * @param operationDocumentation Documentation for the operation
+ * @return the created operation
+ */
+ protected ObjectModelOperation createPropertySetterSignature(ObjectModelClassifier classifier,
+ String propertyType,
+ String propertyName,
+ String operationDocumentation) {
+ // Operation
+ ObjectModelOperation operation =
+ addOperation(classifier,
+ "set" + StringUtils.capitalize(propertyName), void.class);
+
+ ObjectModelParameter param =
+ addParameter(operation, propertyType, propertyName);
+
+ // Documentation
+ if (StringUtils.isNotEmpty(operationDocumentation)) {
+ setDocumentation(operation, operationDocumentation);
+ }
+ setDocumentation(param, "La valeur de l'attribut à positionner.");
+
+ return operation;
+ }
+
}
1
0
r2032 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
Author: fdesbois
Date: 2010-06-25 14:41:09 +0200 (Fri, 25 Jun 2010)
New Revision: 2032
Url: http://nuiton.org/repositories/revision/topia/2032
Log:
Evo #609 : Refactor generation for properties operations for association class case.
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-25 12:40:15 UTC (rev 2031)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/EntityTransformer.java 2010-06-25 12:41:09 UTC (rev 2032)
@@ -140,7 +140,7 @@
outputInterface = createInterface(clazzName, packageName);
outputAbstract = createAbstractClass(clazzName + "Abstract", packageName);
- // generateOperationsFromAttributes(input.getAttributes()); is executed in generateInterface
+ //generateOperationsFromAttributes(input.getAttributes()); is executed in generateInterface
generateInterface(input, outputInterface, attributes, operations);
generateAbstract(input, outputAbstract, attributes, operations);
@@ -218,18 +218,13 @@
continue;
}
- // Don't manage association class for instance
- if (attribute.hasAssociationClass()) {
- continue;
- }
-
if (attribute.getMaxMultiplicity() == 1) {
// setXXX
- addSimpleSetOperation(attribute);
+ addSingleSetOperation(attribute);
// getXXX
- addSimpleGetOperation(attribute, null);
+ addSingleGetOperation(attribute, null);
} else {
@@ -255,7 +250,7 @@
addMultipleAddAllOperation(attribute, collectionInterface);
// setXXX
- addMultipleSetOperation(attribute, collectionInterface);
+ addMultipleSetOperation(attribute, collectionInterface, collectionImpl);
// removeXXX
addMultipleRemoveOperation(attribute);
@@ -273,6 +268,11 @@
addMultipleGetTopiaIdOperation(attribute);
}
+ if (attribute.hasAssociationClass()) {
+ // getXXX with entity parameter
+ addMultipleGetOperationFromEntity(attribute);
+ }
+
// sizeXXX
addMultipleSizeOperation(attribute);
@@ -283,6 +283,22 @@
}
}
+ protected String getPropertyName(ObjectModelAttribute attribute) {
+ String propertyName = attribute.getName();
+ if (attribute.hasAssociationClass()) {
+ propertyName = TopiaGeneratorUtil.getAssocAttrName(attribute);
+ }
+ return propertyName;
+ }
+
+ protected String getPropertyType(ObjectModelAttribute attribute) {
+ String propertyType = attribute.getType();
+ if (attribute.hasAssociationClass()) {
+ propertyType = attribute.getAssociationClass().getQualifiedName();
+ }
+ return propertyType;
+ }
+
// TODO-fdesbois-2010-06-25 : This method can be put in JavaBuilder or ObjectModelTransformerToJava
protected ObjectModelOperation createPropertySetterSignature(ObjectModelClassifier classifier,
String propertyType,
@@ -305,10 +321,10 @@
return operation;
}
- protected void addSimpleSetOperation(ObjectModelAttribute attribute) {
+ protected void addSingleSetOperation(ObjectModelAttribute attribute) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -319,6 +335,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
setOperationBody(implOperation, ""
/*{
<%=attrType%> oldValue = this.<%=attrName%>;
@@ -339,11 +357,11 @@
* @param operationPrefix Operation prefix : 'get' by default, if prefix
* is null
*/
- protected void addSimpleGetOperation(ObjectModelAttribute attribute,
+ protected void addSingleGetOperation(ObjectModelAttribute attribute,
String operationPrefix) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
if (operationPrefix == null) {
operationPrefix = TopiaGeneratorUtil.OPERATION_GETTER_DEFAULT_PREFIX;
@@ -368,6 +386,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
setOperationBody(implOperation, ""
/*{
fireOnPreRead(<%=getConstantName(attrName)%>, <%=attrName%>);
@@ -380,15 +400,15 @@
// Generate 'is' getter for boolean attributes
if (attrType.toLowerCase().contains("boolean") &&
!operationPrefix.equals(TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX)) {
- addSimpleGetOperation(attribute,
+ addSingleGetOperation(attribute,
TopiaGeneratorUtil.OPERATION_GETTER_BOOLEAN_PREFIX);
}
}
protected void addMultipleAddOperation(ObjectModelAttribute attribute, String collectionImpl) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
// Interface operation
@@ -408,6 +428,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
StringBuilder body = new StringBuilder();
body.append(""
@@ -429,6 +451,7 @@
<%=attrName%>.set<%=reverseAttrName%>(this);
}*/
);
+ // WARN-fdesbois-2010-06-25 : in previous code no else for association class
} else {
body.append(""
/*{
@@ -451,8 +474,8 @@
protected void addMultipleAddAllOperation(ObjectModelAttribute attribute, String collectionInterface) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -471,6 +494,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
setOperationBody(implOperation, ""
/*{
if (<%=attrName%> == null) {
@@ -483,10 +508,11 @@
);
}
- protected void addMultipleSetOperation(ObjectModelAttribute attribute, String collectionInterface) {
+ protected void addMultipleSetOperation(ObjectModelAttribute attribute, String collectionInterface, String collectionImpl) {
- String attrName = attribute.getName();
- String attrType = collectionInterface + "<" + attribute.getType() + ">";
+ String attrName = getPropertyName(attribute);
+ String referenceType = getPropertyType(attribute);
+ String attrType = collectionInterface + "<" + referenceType + ">";
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -496,20 +522,25 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+ referenceType = TopiaGeneratorUtil.getSimpleName(referenceType);
+
// Force fire for collection
setOperationBody(implOperation, ""
/*{
- fireOnPreWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>);
+ // Copy elements to keep data for fire with new reference
+ <%=attrType%> oldValue = this.<%=attrName%> != null ? new <%=collectionImpl%><<%=referenceType%>>(this.<%=attrName%>) : null;
+ fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
this.<%=attrName%> = <%=attrName%>;
- fireOnPostWrite(<%=getConstantName(attrName)%>, null, <%=attrName%>);
+ fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, <%=attrName%>);
}*/
);
}
protected void addMultipleRemoveOperation(ObjectModelAttribute attribute) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
// Interface operation
@@ -529,6 +560,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
StringBuilder body = new StringBuilder();
body.append(""
@@ -549,6 +582,7 @@
<%=attrName%>.set<%=reverseAttrName%>(null);
}*/
);
+ // WARN-fdesbois-2010-06-25 : in previous code no else for association class
} else {
body.append(""
/*{
@@ -569,8 +603,8 @@
String collectionInterface,
String collectionImpl) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
ObjectModelAttribute reverse = attribute.getReverseAttribute();
// Interface operation
@@ -587,6 +621,8 @@
ObjectModelOperation implOperation =
cloneOperationSignature(interfaceOperation, outputAbstract);
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
StringBuilder body = new StringBuilder(""
/*{
if (this.<%=attrName%> == null) {
@@ -607,6 +643,7 @@
/*{ item.set<%=reverseAttrName%>(null);
}*/
);
+ // WARN-fdesbois-2010-06-25 : in previous code no else for association class
} else {
body.append(""
/*{ item.get<%=reverseAttrName%>().remove(this);
@@ -618,12 +655,11 @@
}*/
);
}
- // 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%>);
+/*{ <%=collectionInterface%><<%=attrType%>> oldValue = new <%=collectionImpl%><<%=attrType%>>(this.<%=attrName%>);
+ fireOnPreWrite(<%=getConstantName(attrName)%>, oldValue, this.<%=attrName%>);
this.<%=attrName%>.clear();
- fireOnPostWrite(<%=getConstantName(attrName)%>, _oldValue, this.<%=attrName%>);
+ fireOnPostWrite(<%=getConstantName(attrName)%>, oldValue, this.<%=attrName%>);
}*/
);
setOperationBody(implOperation, body.toString());
@@ -632,8 +668,8 @@
protected void addMultipleGetOperation(ObjectModelAttribute attribute,
String collectionInterface) {
- String attrName = attribute.getName();
- String attrType = collectionInterface + "<" + attribute.getType() + ">";
+ String attrName = getPropertyName(attribute);
+ String attrType = collectionInterface + "<" + getPropertyType(attribute) + ">";
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -660,8 +696,8 @@
protected void addMultipleGetTopiaIdOperation(ObjectModelAttribute attribute) {
- String attrName = attribute.getName();
- String attrType = attribute.getType();
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -688,9 +724,50 @@
);
}
+ protected void addMultipleGetOperationFromEntity(ObjectModelAttribute attribute) {
+
+ // reference to the real attribute name
+ String referenceName = attribute.getName();
+ String referenceType = attribute.getType();
+
+ // association attribute name
+ String attrName = getPropertyName(attribute);
+ String attrType = getPropertyType(attribute);
+
+ // Interface operation
+ ObjectModelOperation interfaceOperation =
+ addOperation(outputInterface,
+ "get" + StringUtils.capitalize(attrName), attrType);
+
+ addParameter(interfaceOperation, referenceType, referenceName);
+
+ // Documentation
+ // no doc from previous code
+
+ // Implementation
+ ObjectModelOperation implOperation =
+ cloneOperationSignature(interfaceOperation, outputAbstract);
+
+ attrType = TopiaGeneratorUtil.getSimpleName(attrType);
+
+ setOperationBody(implOperation, ""
+/*{
+ if (<%=referenceName%> == null || <%=attrName%> == null) {
+ return null;
+ }
+ for (<%=attrType%> item : <%=attrName%>) {
+ if (<%=referenceName%>.equals(item.get<%=StringUtils.capitalize(referenceName)%>())) {
+ return item;
+ }
+ }
+ return null;
+}*/
+ );
+ }
+
protected void addMultipleSizeOperation(ObjectModelAttribute attribute) {
- String attrName = attribute.getName();
+ String attrName = getPropertyName(attribute);
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -716,7 +793,7 @@
protected void addMultipleIsEmptyOperation(ObjectModelAttribute attribute) {
- String attrName = attribute.getName();
+ String attrName = getPropertyName(attribute);
// Interface operation
ObjectModelOperation interfaceOperation =
@@ -783,24 +860,24 @@
generateOperationsFromAttributes(attributes);
- for (ObjectModelAttribute attr : attributes) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!attr.isNavigable() &&
- !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
- reverse, model)) {
- continue;
- }
+// for (ObjectModelAttribute attr : attributes) {
+// ObjectModelAttribute reverse = attr.getReverseAttribute();
+// if (!attr.isNavigable() &&
+// !TopiaGeneratorUtil.hasUnidirectionalRelationOnAbstractType(
+// reverse, model)) {
+// continue;
+// }
+//
+// if (attr.hasAssociationClass()) {
+//
+// addInterfaceAssociationAttribute(output, attr);
+//
+// } else {
+// //addInterfaceNoneAssociationAttribute(output, attr);
+// }
+// }
- if (attr.hasAssociationClass()) {
- addInterfaceAssociationAttribute(output, attr);
-
- } else {
- //addInterfaceNoneAssociationAttribute(output, attr);
- }
- }
-
-
//Méthodes d'accès aux attributs d'une classe d'associations
if (input instanceof ObjectModelAssociationClass) {
@@ -1010,19 +1087,19 @@
generateCompositeMethod(output, input);
+ // DONE
+// for (ObjectModelAttribute attr : attributes) {
+// ObjectModelAttribute reverse = attr.getReverseAttribute();
+//
+// if (!(attr.isNavigable()
+// || hasUnidirectionalRelationOnAbstractType(reverse, model))) {
+// continue;
+// }
+//
+// transformAttribute(output, attr, reverse);
+// }
- for (ObjectModelAttribute attr : attributes) {
- ObjectModelAttribute reverse = attr.getReverseAttribute();
- if (!(attr.isNavigable()
- || hasUnidirectionalRelationOnAbstractType(reverse, model))) {
- continue;
- }
-
- transformAttribute(output, attr, reverse);
- }
-
-
//Méthodes d'accès aux attributs d'une classe d'associations
if (input instanceof ObjectModelAssociationClass) {
@@ -1109,153 +1186,6 @@
}
@Deprecated
- protected void addInterfaceNoneAssociationAttribute(ObjectModelInterface output,
- ObjectModelAttribute attr) {
- String attrName = attr.getName();
- String attrType = attr.getType();
- ObjectModelOperation op;
- ObjectModelParameter attr2;
-
- if (!GeneratorUtil.isNMultiplicity(attr)) {
- // DONE
-
- // setXXX
-
- op = addOperation(output,
- "set" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- attr2 = addParameter(op, attrType,
- GeneratorUtil.toLowerCaseFirstLetter(attrName));
- setDocumentation(attr2, "La valeur de l'attribut " + attrName
- + " à positionner.");
-
- // getXXX
-
- // 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
- addSimpleGetOperation(attr, null);
-
- } else {
- String collectionInterface =
- TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
-
- // addXXX : DONE
-
- op = addOperation(output,
- "add" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- attr2 = addParameter(op, attrType,
- GeneratorUtil.toLowerCaseFirstLetter(attrName));
- setDocumentation(attr2,
- "L'instance de " + attrName + " à ajouter");
-
- // addAllXXX : DONE
-
- op = addOperation(output,
- "addAll" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- attr2 = addParameter(op,
- collectionInterface + "<" + attrType + ">",
- GeneratorUtil.toLowerCaseFirstLetter(attrName));
- setDocumentation(attr2,
- "Les instances de " + attrName + " à ajouter");
-
- // setXXX : DONE
-
- op = addOperation(output,
- "set" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- attr2 = addParameter(op,
- collectionInterface + "<" + attrType + ">",
- GeneratorUtil.toLowerCaseFirstLetter(attrName));
- setDocumentation(attr2,
- "La Collection de " + attrName + " à ajouter");
-
- // removeXXX : DONE
-
- op = addOperation(output,
- "remove" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- attr2 = addParameter(op,
- attrType,
- GeneratorUtil.toLowerCaseFirstLetter(attrName));
- setDocumentation(attr2,
- "L'instance de " + attrName + " à retirer");
-
- // clearXXX : DONE
-
- op = addOperation(output,
- "clear" + StringUtils.capitalize(attrName),
- "void",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, attr.getDocumentation());
- }
- setDocumentation(attr2, "Vide la Collection de " + attrName);
-
- // getXXX : DONE
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(attrName),
- collectionInterface + "<" + attrType + ">",
- ObjectModelModifier.PACKAGE);
- if (TopiaGeneratorUtil.hasDocumentation(attr)) {
- setDocumentation(op, "Retourne la collection.");
- }
-
- if (!TopiaGeneratorUtil.isPrimitiveType(attr) &&
- !TopiaGeneratorUtil.isDateType(attr)) {
-
- // getXXXByTopiaId : DONE
-
- op = addOperation(output,
- "get" + StringUtils.capitalize(attrName) + "ByTopiaId",
- attrType,
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Recupère l'attribut " + attrName + " à partir de son topiaId");
- attr2 = addParameter(op, String.class, "topiaId");
- setDocumentation(attr2, "le topia id de l'entité recherchée");
- }
-
- // sizeXXX : DONE
-
- op = addOperation(output,
- "size" + StringUtils.capitalize(attrName),
- int.class,
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Retourne le nombre d'éléments de la collection " + attrName);
-
- // isXXXEmpty : DONE
-
- op = addOperation(output,
- "is" + StringUtils.capitalize(attrName) + "Empty",
- boolean.class,
- ObjectModelModifier.PACKAGE);
- setDocumentation(op, "Retourne {@code true} si la collection " + attrName + " est vide.");
- }
- }
-
protected void addInterfaceAssociationAttribute(ObjectModelInterface output,
ObjectModelAttribute attr) {
String attrName = attr.getName();
@@ -1267,7 +1197,8 @@
ObjectModelOperation op;
ObjectModelParameter attr2;
- if (!GeneratorUtil.isNMultiplicity(attr)) {
+ // Ok
+ if (!GeneratorUtil.isNMultiplicity(attr) && false) {
// setXXX
@@ -1285,7 +1216,7 @@
assocClassFQN,
ObjectModelModifier.PACKAGE);
- } else {
+ } else if (GeneratorUtil.isNMultiplicity(attr)) {
String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
// addXXX
@@ -1434,6 +1365,7 @@
// Abstract generation
// -------------------------------------------------------------------------
+ @Deprecated
protected void transformAttribute(ObjectModelClass result,
ObjectModelAttribute attr,
ObjectModelAttribute reverse) {
@@ -1446,7 +1378,8 @@
ObjectModelOperation op;
- if (!GeneratorUtil.isNMultiplicity(attr)) {
+ // Ok for both
+ if (!GeneratorUtil.isNMultiplicity(attr) && false) {
if (attr.hasAssociationClass()) {
String assocAttrName = GeneratorUtil.getAssocAttrName(attr);
@@ -1455,7 +1388,7 @@
assocClassFQN = TopiaGeneratorUtil.getSimpleName(assocClassFQN);
String name = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName);
- // setXXX
+ // setXXX : DONE
op = addOperation(result,
"set" + StringUtils.capitalize(assocAttrName),
@@ -1471,7 +1404,7 @@
}*/
);
- // getXXX : getter for association attribute with unique multiplicity
+ // getXXX : getter for association attribute with unique multiplicity : DONE
op = addOperation(result,
"get" + StringUtils.capitalize(assocAttrName),
@@ -1508,7 +1441,7 @@
// see {@link #addSimpleGetterOperation(ObjectModelAttribute, String)}
}
- } else { //NMultiplicity
+ } else if (GeneratorUtil.isNMultiplicity(attr)) { //NMultiplicity
String collectionInterface = TopiaGeneratorUtil.getNMultiplicityInterfaceType(attr);
String collectionObject = TopiaGeneratorUtil.getNMultiplicityObjectType(attr);
addImport(result, collectionInterface);
1
0
r2031 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
Author: fdesbois
Date: 2010-06-25 14:40:15 +0200 (Fri, 25 Jun 2010)
New Revision: 2031
Url: http://nuiton.org/repositories/revision/topia/2031
Log:
Remove useless call to uncapitalize
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/QueryHelperTransformer.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/QueryHelperTransformer.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/QueryHelperTransformer.java 2010-06-25 12:39:46 UTC (rev 2030)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/QueryHelperTransformer.java 2010-06-25 12:40:15 UTC (rev 2031)
@@ -550,8 +550,7 @@
protected String getReferenceAttributeName(ObjectModelAttribute attrReference) {
String attrName = attrReference.getName();
if(attrReference.hasAssociationClass()) {
- String assocAttrName = GeneratorUtil.getAssocAttrName(attrReference);
- attrName = StringUtils.uncapitalize(assocAttrName);
+ attrName = GeneratorUtil.getAssocAttrName(attrReference);
}
return attrName;
}
1
0
r2030 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
Author: fdesbois
Date: 2010-06-25 14:39:46 +0200 (Fri, 25 Jun 2010)
New Revision: 2030
Url: http://nuiton.org/repositories/revision/topia/2030
Log:
Remove deprecated method, no change anywhere because of inheritance
Modified:
trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
Modified: trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java
===================================================================
--- trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-06-25 10:28:33 UTC (rev 2029)
+++ trunk/topia-persistence/src/main/java/org/nuiton/topia/generator/TopiaGeneratorUtil.java 2010-06-25 12:39:46 UTC (rev 2030)
@@ -580,29 +580,6 @@
(!GeneratorUtil.isFirstAttribute(attr));
}
- /**
- * Renvoie le nom de l'attribut de classe d'association en fonction des cas:
- * Si l'attribut porte le même nom que le type (extrémité inverse de
- * l'association), on lui ajoute le nom de la classe d'association
- *
- * @param attr l'attribut a traiter
- * @return le nom de l'attribut de classe d'association
- * @deprecated since 2.3.4, prefer use the
- * {@link GeneratorUtil#getAssocAttrName(ObjectModelAttribute)}
- */
- @Deprecated
- public static String getAssocAttrName(ObjectModelAttribute attr) {
- String result = GeneratorUtil.getAssocAttrName(attr);
-// String typeName = attr.getType().substring(
-// attr.getType().lastIndexOf(".") + 1);
-// String result = attr.getName();
-// if (attr.getName().equalsIgnoreCase(typeName)) {
-// result += StringUtils.capitalize(
-// attr.getAssociationClass().getName());
-// }
- return result;
- }
-
public static String getDOType(ObjectModelElement elem, ObjectModel model) {
String type = elem.getName();
if (elem instanceof ObjectModelAttribute) {
1
0
r2029 - trunk/topia-persistence/src/main/java/org/nuiton/topia/generator
by fdesbois@users.nuiton.org 25 Jun '10
by fdesbois@users.nuiton.org 25 Jun '10
25 Jun '10
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()) {
1
0