This is an automated email from the git hooks/post-receive script. New commit to branch develop in repository topia. See http://git.nuiton.org/topia.git commit 0b30751c77bac201170ece2eadc55585b5a38863 Author: Brendan Le Ny <bleny@codelutin.com> Date: Fri Oct 3 18:27:08 2014 +0200 Removes usages of 'dto' stereotype (refs #2081) --- .../org/nuiton/topia/templates/DTOTransformer.java | 480 --------------------- .../nuiton/topia/templates/TopiaStereoTypes.java | 21 - 2 files changed, 501 deletions(-) diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/DTOTransformer.java b/topia-templates/src/main/java/org/nuiton/topia/templates/DTOTransformer.java deleted file mode 100644 index 3a2f376..0000000 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/DTOTransformer.java +++ /dev/null @@ -1,480 +0,0 @@ -package org.nuiton.topia.templates; - -/* - * #%L - * ToPIA :: Templates - * $Id$ - * $HeadURL$ - * %% - * Copyright (C) 2004 - 2014 CodeLutin - * %% - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Lesser Public License for more details. - * - * You should have received a copy of the GNU General Lesser Public - * License along with this program. If not, see - * <http://www.gnu.org/licenses/lgpl-3.0.html>. - * #L% - */ - -import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.builder.ToStringBuilder; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.nuiton.eugene.GeneratorUtil; -import org.nuiton.eugene.java.JavaGeneratorUtil; -import org.nuiton.eugene.java.ObjectModelTransformerToJava; -import org.nuiton.eugene.models.object.ObjectModelAssociationClass; -import org.nuiton.eugene.models.object.ObjectModelAttribute; -import org.nuiton.eugene.models.object.ObjectModelClass; -import org.nuiton.eugene.models.object.ObjectModelClassifier; -import org.nuiton.eugene.models.object.ObjectModelInterface; -import org.nuiton.eugene.models.object.ObjectModelJavaModifier; -import org.nuiton.eugene.models.object.ObjectModelOperation; - -import java.beans.PropertyChangeListener; -import java.beans.PropertyChangeSupport; -import java.io.Serializable; -import java.util.Collection; -import java.util.List; - - -/*{generator option: parentheses = false}*/ - -/*{generator option: writeString = +}*/ - -/** - * Created: 20 déc. 2009 - * - * @author Tony Chemit - chemit@codelutin.com - * @plexus.component role="org.nuiton.eugene.Template" role-hint="org.nuiton.topia.templates.DTOTransformer" - * @since 2.3.0 - */ -public class DTOTransformer extends ObjectModelTransformerToJava { - - /** - * Logger - */ - private static final Log log = LogFactory.getLog(DTOTransformer.class); - - protected TopiaTemplateHelper templateHelper; - - protected TopiaTagValues topiaTagValues; - - @Override - public void transformFromClass(ObjectModelClass clazz) { - - if (!TopiaStereoTypes.hasDtoStereotype(clazz)) { - return; - } - - if (templateHelper == null) { - templateHelper = new TopiaTemplateHelper(model); - } - - if (topiaTagValues == null) { - topiaTagValues = templateHelper.getTopiaTagValues(); - } - String clazzName = clazz.getName(); - ObjectModelClass result; - result = createClass(clazzName + "DTO", clazz.getPackageName()); - addImport(result, ToStringBuilder.class); - addImport(result, PropertyChangeListener.class); - - setDocumentation(result, "Implantation DTO pour l'entité " + StringUtils.capitalize(clazzName) + "."); - String extendClass = ""; - for (ObjectModelClass parent : clazz.getSuperclasses()) { - extendClass = parent.getQualifiedName() + "DTO"; - // no multi-inheritance in java - break; - } - if (extendClass.length() > 0) { - setSuperClass(result, extendClass); - } - - addInterface(result, Serializable.class); - for (ObjectModelInterface parentInterface : clazz.getInterfaces()) { - if (TopiaStereoTypes.hasDtoStereotype(parentInterface)) { - addInterface(result, parentInterface.getName() + "DTO"); - } else { - addInterface(result, parentInterface.getName()); - } - } - - addAttributes(result, clazz); - - addOperations(result, clazz); - } - - protected void addAttributes(ObjectModelClass result, ObjectModelClass clazz) { - - String svUID = topiaTagValues.findTagValue("dto-serialVersionUID", clazz, model); - if (StringUtils.isNotEmpty(svUID)) { - addAttribute(result, "serialVersionUID", long.class, svUID, ObjectModelJavaModifier.FINAL, ObjectModelJavaModifier.PUBLIC, ObjectModelJavaModifier.STATIC); - } - - addAttribute(result, "p", PropertyChangeSupport.class, null, ObjectModelJavaModifier.PROTECTED); - -/* -* Définition des attributs -*/ - ObjectModelAttribute attr2; - for (ObjectModelAttribute attr : clazz.getAttributes()) { - ObjectModelAttribute reverse = attr.getReverseAttribute(); - - String attributeName; - String attributeType; - if (!(attr.isNavigable() - || attr.hasAssociationClass())) { - continue; - } - - String attrName = attr.getName(); - String attrVisibility = attr.getVisibility(); - String attrType = attr.getType(); - if (!GeneratorUtil.isNMultiplicity(attr)) { - if (!attr.hasAssociationClass()) { - if (isDTO(attrType)) { - attrType += "DTO"; - } - attributeType = attrType; - attributeName = attrName; - } else { - String assocAttrName = GeneratorUtil.getAssocAttrName(attr); - attributeType = attr.getAssociationClass().getQualifiedName(); - attributeName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - } - } else { - if (!attr.hasAssociationClass()) { - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<"; - } else { - nMultType = Collection.class.getName() + "<"; - } - nMultType += attrType; - if (isDTO(attrType)) { - nMultType += "DTO"; - } - nMultType += ">"; - - attributeType = nMultType; - attributeName = attrName; - } else { - String assocAttrName = GeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<"; - } else { - nMultType = Collection.class.getName() + "<"; - } - nMultType += assocClassFQN; - if (isDTO(attrType)) { - nMultType += "DTO"; - } - nMultType += ">"; - attributeType = nMultType; - attributeName = GeneratorUtil.toLowerCaseFirstLetter(assocAttrName); - } - } - - attr2 = addAttribute(result, attributeName, attributeType, null, ObjectModelJavaModifier.PROTECTED); - - if (attr2 != null) { - if (GeneratorUtil.hasDocumentation(attr)) { - setDocumentation(attr2, attr.getDocumentation()); - } - String annotation = topiaTagValues.getAnnotationTagValue(attr); - if (StringUtils.isNotEmpty(annotation)) { - addAnnotation(result, attr2, annotation); - } - } - } /* end for*/ - - //Déclaration des attributs d'une classe d'associations - if (clazz instanceof ObjectModelAssociationClass) { - ObjectModelAssociationClass assoc = (ObjectModelAssociationClass) clazz; - for (ObjectModelAttribute attr : assoc.getParticipantsAttributes()) { - if (attr != null) { - String attrName = attr.getName(); - String attrVisibility = attr.getVisibility(); - String attrType = attr.getType(); - if (isDTO(attrType)) { - attrType += "DTO"; - } - addAttribute(result, GeneratorUtil.toLowerCaseFirstLetter(attrName), attrType); - } - } - } - - } - - protected void addOperations(ObjectModelClass result, ObjectModelClass clazz) { - ObjectModelOperation op; - op = addOperation(result, "addPostWriteListener", "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, PropertyChangeListener.class, "listener"); - setOperationBody(op, "" -/*{ - p.addPostWriteListener(listener); - }*/ - ); - - op = addOperation(result, "addPostWriteListener", "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, String.class, "propertyName"); - addParameter(op, PropertyChangeListener.class, "listener"); - setOperationBody(op, "" -/*{ - p.addPostWriteListener(propertyName, listener); - }*/ - ); - - op = addOperation(result, "removePostWriteListener", "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, PropertyChangeListener.class, "listener"); - setOperationBody(op, "" -/*{ - p.removePostWriteListener(listener); - }*/ - ); - - op = addOperation(result, "removePostWriteListener", "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, String.class, "propertyName"); - addParameter(op, PropertyChangeListener.class, "listener"); - setOperationBody(op, "" -/*{ - p.removePostWriteListener(propertyName, listener); - }*/ - ); - /* - * Définition des getteurs et setteurs - */ - for (ObjectModelAttribute attr : clazz.getAttributes()) { - - ObjectModelAttribute reverse = attr.getReverseAttribute(); - -// if (!(attr.isNavigable() || hasUnidirectionalRelationOnAbstractType(reverse, model))) { - if (!attr.isNavigable()) { - continue; - } - - String attrName = attr.getName(); - String attrType = attr.getType(); - String attrTypeDTO = attr.getType(); - if (isDTO(attrType)) { - attrTypeDTO += "DTO"; - } - - if (!GeneratorUtil.isNMultiplicity(attr)) { - if (!attr.hasAssociationClass()) { - op = addOperation(result, "set" + StringUtils.capitalize(attrName), "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrTypeDTO, "value"); - setOperationBody(op, "" -/*{ - <%=attrTypeDTO%> oldValue = this.<%=attrName%>; - this.<%=attrName%> = value; - p.firePropertyChange("<%=attrName%>", oldValue, value); - }*/ - ); - - op = addOperation(result, "get" + StringUtils.capitalize(attrName), attrTypeDTO, ObjectModelJavaModifier.PUBLIC); - setOperationBody(op, "" -/*{ - return <%=attrName%>; - }*/ - ); - - } else { - String assocAttrName = GeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - if (log.isTraceEnabled()) { - log.trace("assocAttrName: " + assocAttrName); - } - op = addOperation(result, "set" + StringUtils.capitalize(assocAttrName), "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, assocClassFQN + "DTO", "association"); - setOperationBody(op, "" -/*{ - <%=assocClassFQN%>DTO oldAssocation = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>; - this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = association; - p.firePropertyChange("<%=attrName%>", oldAssocation, assocation); - }*/ - ); - - op = addOperation(result, "get" + StringUtils.capitalize(assocAttrName), assocClassFQN + "DTO", ObjectModelJavaModifier.PUBLIC); - setOperationBody(op, "" -/*{ - return <%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>; - }*/ - ); - } - } else { //NMultiplicity - if (!attr.hasAssociationClass()) { //Méthodes remplacées par des accesseurs sur les classes d'assoc - - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<" + attrTypeDTO + ">"; - } else { - nMultType = Collection.class.getName() + "<" + attrTypeDTO + ">"; - } - op = addOperation(result, "set" + StringUtils.capitalize(attrName), "void", ObjectModelJavaModifier.PUBLIC); - addParameter(op, nMultType, "values"); - setOperationBody(op, "" -/*{ - <%=nMultType%> oldValues = this.<%=attrName%>; - this.<%=attrName%> = values; - p.firePropertyChange("<%=attrName%>", oldValues, values); - }*/ - ); - - op = addOperation(result, "addChild" + StringUtils.capitalize(attrName), attrTypeDTO, ObjectModelJavaModifier.PUBLIC); - addParameter(op, attrTypeDTO, attrName); - StringBuilder buffercode = new StringBuilder(); - - buffercode.append("" -/*{ - this.<%=attrName%>.add(<%=attrName%>); - }*/ - ); - - if (reverse != null && reverse.isNavigable()) { - String reverseAttrName = reverse.getName(); - buffercode.append("" -/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(this); - }*/ - ); - } - buffercode.append("" -/*{ return <%=attrName%>; - }*/ - ); - setOperationBody(op, buffercode.toString()); - - op = addOperation(result, "removeChild", "void"); - addParameter(op, attrTypeDTO, attrName); - - buffercode = new StringBuilder(); - buffercode.append("" -/*{ - this.<%=attrName%>.remove(<%=attrName%>); - }*/ - ); - - if (reverse != null && reverse.isNavigable()) { - String reverseAttrName = reverse.getName(); - buffercode.append("" -/*{ <%=attrName%>.set<%=StringUtils.capitalize(reverseAttrName)%>(null); - }*/ - ); - } - setOperationBody(op, buffercode.toString()); - - } else { - String assocAttrName = GeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<" + assocClassFQN + "DTO>"; - } else { - nMultType = Collection.class.getName() + "<" + assocClassFQN + "DTO>"; - } - if (log.isTraceEnabled()) { - log.trace("assocAttrName: " + assocAttrName); - } - op = addOperation(result, "set" + StringUtils.capitalize(assocAttrName), "void"); - addParameter(op, nMultType, "values"); - setOperationBody(op, "" -/*{ - <%=nMultType%> oldValues = this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>; - this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%> = values; - p.firePropertyChange("<%=attrName%>", oldValues, values); - }*/ - ); - } - if (!attr.hasAssociationClass()) { - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<" + attrTypeDTO + ">"; - } else { - nMultType = Collection.class.getName() + "<" + attrTypeDTO + ">"; - } - op = addOperation(result, "get" + StringUtils.capitalize(attrName), nMultType); - setOperationBody(op, "" -/*{ - return this.<%=attrName%>; - }*/ - ); - } else { - String assocAttrName = GeneratorUtil.getAssocAttrName(attr); - String assocClassFQN = attr.getAssociationClass().getQualifiedName(); - String nMultType; - if (JavaGeneratorUtil.isOrdered(attr)) { - nMultType = List.class.getName() + "<" + assocClassFQN + "DTO>"; - } else { - nMultType = Collection.class.getName() + "<" + assocClassFQN + "DTO>"; - } - if (log.isTraceEnabled()) { - log.trace("assocAttrName: " + assocAttrName); - } - op = addOperation(result, "get" + StringUtils.capitalize(assocAttrName), nMultType); - setOperationBody(op, "" -/*{ - return this.<%=GeneratorUtil.toLowerCaseFirstLetter(assocAttrName)%>; - }*/ - ); - } - } - } - - op = addOperation(result, "toString", String.class, ObjectModelJavaModifier.PUBLIC); - StringBuilder buffer = new StringBuilder(); - - buffer.append("" -/*{ - String result = new ToStringBuilder(this). -}*/ - ); - - for (Object o : clazz.getAttributes()) { - ObjectModelAttribute attr = (ObjectModelAttribute) o; - if (!(attr.isNavigable() - || attr.hasAssociationClass())) { - continue; - } - //FIXME possibilité de boucles (non directes) - ObjectModelClass attrEntity = null; - if (model.hasClass(attr.getType())) { - attrEntity = model.getClass(attr.getType()); - } - boolean isDTO = attrEntity != null && - templateHelper.isEntity(attrEntity); //THIMEL : STEREOTYPE ENTITY ??? - ObjectModelAttribute reverse = attr.getReverseAttribute(); - if (isDTO && (reverse == null || !reverse.isNavigable()) && !attr.hasAssociationClass() || !isDTO) { - String attrName = attr.getName(); - buffer.append("" -/*{ append("<%=attrName%>", this.<%=attrName%>). -}*/ - ); - } - } - buffer.append("" -/*{ toString(); - return result; - }*/ - ); - setOperationBody(op, buffer.toString()); - } - - public boolean isDTO(String type) { - ObjectModelClassifier clazz = model.getClassifier(type); - return clazz != null && TopiaStereoTypes.hasDtoStereotype(clazz); - } - - -} - diff --git a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaStereoTypes.java b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaStereoTypes.java index c13dca6..5744dca 100644 --- a/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaStereoTypes.java +++ b/topia-templates/src/main/java/org/nuiton/topia/templates/TopiaStereoTypes.java @@ -50,15 +50,6 @@ public class TopiaStereoTypes extends StereotypeDefinitionProvider { public static final String STEREOTYPE_ENTITY = "entity"; /** - * Stéréotype pour les objets devant être générées sous forme de DTO. - * - * @see #hasDtoStereotype(ObjectModelClassifier) - */ - @StereotypeDefinition(target = ObjectModelClassifier.class, - documentation = "to specify that a class is a DTO") - public static final String STEREOTYPE_DTO = "dto"; - - /** * Stéréotype pour les attributs étant des clés primaires. * * @see #hasPrimaryKeyStereotype(ObjectModelAttribute) @@ -86,18 +77,6 @@ public class TopiaStereoTypes extends StereotypeDefinitionProvider { } /** - * Check if the given classifier has the {@link TopiaStereoTypes#STEREOTYPE_DTO} stereotype. - * - * @param classifier classifier to test - * @return {@code true} if stereotype was found, {@code false otherwise} - * @see TopiaStereoTypes#STEREOTYPE_DTO - * @since 2.5 - */ - public static boolean hasDtoStereotype(ObjectModelClassifier classifier) { - return classifier.hasStereotype(TopiaStereoTypes.STEREOTYPE_DTO); - } - - /** * Check if the given attribute has the {@link TopiaStereoTypes#STEREOTYPE_PRIMARY_KEY} stereotype. * * @param attribute attribute to test -- To stop receiving notification emails like this one, please contact nuiton.org SCM administrator <admin+scm@nuiton.org>.