Index: topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java diff -u topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.4 topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.5 --- topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java:1.4 Thu Jul 5 09:51:19 2007 +++ topia2/src/java/org/codelutin/topia/generator/ServiceAbstractGenerator.java Tue Jul 17 16:16:27 2007 @@ -19,6 +19,8 @@ *##%*/ package org.codelutin.topia.generator; +import static org.codelutin.topia.generator.GeneratorUtil.hasUnidirectionalRelationOnAbstractType; + import java.io.File; import java.io.IOException; import java.io.Writer; @@ -46,17 +48,18 @@ * Created: 19 juin 2007 * * @author dupont -* @version $Revision: 1.4 $ +* @version $Revision: 1.5 $ * -* Le service abstrait etend TopiaApplicationServiceAbstract et implement +* Le service abstrait etend TopiaApplicationServiceAbstract et implemente * l'interface du service. * -* Genere l'implantation des methodes qui utilisent les methodes des DAO. +* Genere l'implantation des methodes qui utilisent les methodes des DAO +* et celles des entites. * * @see ServiceInterfaceGenerator * @see TopiaApplicationServiceAbstract * -* Mise a jour: $Date: 2007/07/05 09:51:19 $ +* Mise a jour: $Date: 2007/07/17 16:16:27 $ * par : $Author: ndupont $ */ public class ServiceAbstractGenerator extends ObjectModelGenerator { @@ -65,7 +68,7 @@ private static final Log log = LogFactory .getLog(ServiceInterfaceGenerator.class); - + public ServiceAbstractGenerator(Generator parent) { super(parent); } @@ -82,12 +85,20 @@ return; } - generateInterfaceHeader(output, interfacez); + // générer l'entête du service abstrait + generateInterfaceHeader(output, interfacez); - generateInterfaceOperations(output, interfacez); - - // générer les méthodes étendues en modifiant les signatures pour éviter les doublons (findAllByAdresse héritée de Person et Employee) - generateInheritedInterfaceOperations(output, interfacez); + // générer les signatures des méthodes métier du service + generateInterfaceOperations(output, interfacez); + + // générer les méthodes étendues en modifiant les signatures pour éviter les doublons (findAllByAdresse héritée de Person et Employee) + generateInheritedInterfaceOperations(output, interfacez); + + // générer les signatures des méthodes métier des entités + generateAssociatedClassOperations(output, interfacez); + + // générer les signatures des méthodes des entités (getter/setter) + generateMethodsGetter(output, interfacez); /*{} //<%=interfacez.getName()%> }*/ @@ -131,6 +142,13 @@ public abstract class <%=classifier.getName()+"Abstract"%> extends TopiaApplicationServiceAbstract implements <%=classifier.getName()%>{ }*/ } + private void generateMethodsGetter(Writer output, ObjectModelClassifier classifier) throws IOException { +/*{ public String[] getMethods(){ + return methods; + } +}*/ + } + private void generateInterfaceOperations(Writer output, ObjectModelClassifier classifier) throws IOException { for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) { ObjectModelOperation op = (ObjectModelOperation)it.next(); @@ -206,7 +224,18 @@ <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); List<<%=clazz.getName()%>> result = dao.findAll(); return result; - } + } + + /** + * Retourne le <%=clazz.getName()%> par son TopiaId + * @return le <%=clazz.getName()%> + *) + public <%=clazz.getQualifiedName()%> find<%=clazz.getName()%>ByTopiaId(String v) throws TopiaException { + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(v); + return entity; + } }*/ for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); @@ -333,4 +362,397 @@ }*/ } -} //ServiceInterfaceGenerator + + private void generateAssociatedClassOperations(Writer output, ObjectModelClassifier classifier) throws IOException { + for (Iterator i=classifier.getInterfaces().iterator(); i.hasNext();) { + ObjectModelClassifier parent = (ObjectModelClassifier)i.next(); + // pour tous les DAOInterface + if(parent.hasStereotype(DAO)){ + + // récupérer la classe de l'object model correspondant à la DAO + String entityClassName = null; + entityClassName = parent.getQualifiedName().replace("DAO", ""); + if(getModel().hasClass(entityClassName)){ + ObjectModelClass clazz = getModel().getClass(entityClassName); + generateFromClass(output, clazz); + } + } + } + } + + public void generateFromClass(Writer output, ObjectModelClass clazz) throws IOException { + if (!clazz.hasStereotype(GeneratorUtil.STEREOTYPE_ENTITY)) { + return; + } + + for (Iterator it = clazz.getAttributes().iterator(); it.hasNext();) { + ObjectModelAttribute attr = (ObjectModelAttribute)it.next(); + ObjectModelAttribute reverse = attr.getReverseAttribute(); + if (!attr.isNavigable() + && !hasUnidirectionalRelationOnAbstractType(reverse, model)) { + continue; + } + if (!Util.isNMultiplicity(attr)) { + if (!attr.hasAssociationClass()) { +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La valeur de l'attribut <%=attr.getName()%> à positionner. + *) + public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>); + usedContextImpl.commitTransaction(); + } + +}*/ +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @return La valeur de l'attribut <%=attr.getName()%>. + *) + public <%=attr.getType()%> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + return entity.get<%=Util.capitalize(attr.getName())%>(); + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ /** + * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La valeur de l'attribut <%=attr.getAssociationClass().getName()%> à positionner. + *) + public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>); + } + + /** + * @return La valeur de l'attribut <%=attr.getAssociationClass().getName()%>. + *) + public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + return entity.get<%=Util.capitalize(assocAttrName)%>(); + } + +}*/ + } + } else { //NMultiplicity + if (!attr.hasAssociationClass()) { //Méthodes remplacées par des add/set sur les classes d'assoc +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> à ajouter. + *) + public void add<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.add<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>); + } + + /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> Les instances de <%=attr.getName()%> à ajouter. + *) + public void addAll<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.addAll<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>); + } + + /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> La Collection de <%=attr.getName()%> à positionner. + *) + public void set<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.set<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>); + } + + /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @param <%=Util.toLowerCaseFirstLetter(attr.getName())%> L'instance de <%=attr.getName()%> à retirer. + *) + public void remove<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> <%=Util.toLowerCaseFirstLetter(attr.getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.remove<%=Util.capitalize(attr.getName())%>(<%=Util.toLowerCaseFirstLetter(attr.getName())%>); + } + + /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * Vide la Collection de <%=attr.getName()%>. + *) + public void clear<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.clear<%=Util.capitalize(attr.getName())%>(); + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ /** + * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> à ajouter. + *) + public void add<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.add<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>); + } + + /** + * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> Les instances de <%=attr.getAssociationClass().getName()%> à ajouter. + *) + public void addAll<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.addAll<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>); + } + + /** + * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> La Collection de <%=attr.getAssociationClass().getName()%> à positionner. + *) + public void set<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.set<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>); + } + + /** + * @param <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%> L'instance de <%=attr.getAssociationClass().getName()%> à retirer. + *) + public void remove<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getAssociationClass().getQualifiedName()%> <%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.remove<%=Util.capitalize(assocAttrName)%>(<%=Util.toLowerCaseFirstLetter(attr.getAssociationClass().getName())%>); + } + + /** + * Vide la Collection de <%=attr.getAssociationClass().getName()%>. + *) + public void clear<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.clear<%=Util.capitalize(assocAttrName)%>(); + } + +}*/ + } + + if (!attr.hasAssociationClass()) { +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(attr)) { +/*{ * <%=attr.getName()%> : <%=attr.getDocumentation()%> +}*/ + } +/*{ * @return La Liste de <%=attr.getName()%>. + *) + public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getType()%>> get<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + return entity.get<%=Util.capitalize(attr.getName())%>(); + } + + /** + * @return Le nombre d'éléments de la collection <%=attr.getName()%>. + *) + public int size<%=Util.capitalize(attr.getName())%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + return entity.size<%=Util.capitalize(attr.getName())%>(); + } + +}*/ + } else { + String assocAttrName = GeneratorUtil.getAssocAttrName(attr); + if (log.isTraceEnabled()) { log.trace("assocAttrName: " + assocAttrName); } +/*{ /** + * @return La liste des attributs <%=attr.getAssociationClass().getName()%>. + *) + public <%=(attr.isOrdered()?"java.util.List":"java.util.Collection")%><<%=attr.getAssociationClass().getQualifiedName()%>> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.get<%=Util.capitalize(assocAttrName)%>(); + } + + /** + * @return L'attribut <%=attr.getAssociationClass().getName()%> associé à la valeur value de l'attribut <%=attr.getName()%>. + *) + public <%=attr.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId, <%=attr.getType()%> value) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.get<%=Util.capitalize(assocAttrName)%>(<%=attr.getType()%> value); + } + + /** + * @return Le nombre d'éléments de la collection <%=attr.getName()%>. + *) + public int size<%=Util.capitalize(assocAttrName)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.size<%=Util.capitalize(assocAttrName)%>(); + } + +}*/ + } + } + } + + //Méthodes d'accès aux attributs d'une classe d'associations + if (clazz instanceof ObjectModelAssociationClass) { + ObjectModelAssociationClass assoc = (ObjectModelAssociationClass)clazz; + for (Iterator i = assoc.getParticipantsAttributes().iterator(); i.hasNext(); ) { + ObjectModelAttribute attr = (ObjectModelAttribute) i.next(); + if (attr != null) { + String type = attr.getType(); + String name = attr.getName(); + generateAssociationAccessors(output, clazz, name, type); + if (attr.getReverseAttribute() == null) { + type = ((ObjectModelClassifier)attr.getDeclaringElement()).getQualifiedName(); + name = attr.getDeclaringElement().getName(); + generateAssociationAccessors(output, clazz, name, type); + } + } + } + } + + generateInterfaceOperationsOfClass(output, clazz); + + } + + private void generateInterfaceOperationsOfClass(Writer output, ObjectModelClassifier classifier) throws IOException { + for (Iterator it = classifier.getOperations().iterator(); it.hasNext();) { + ObjectModelOperation op = (ObjectModelOperation)it.next(); +/*{ /** +}*/ + if (GeneratorUtil.hasDocumentation(op)) { +/*{ * <%=op.getName()%> : <%=op.getDocumentation()%> +}*/ + } + Collection params = (Collection)op.getParameters(); + for(ObjectModelParameter param : params) { + if(log.isTraceEnabled()) {log.trace("Param" + param);} +/*{ * @param <%=param.getName()%> <%=param.getDocumentation()%> + }*/ + } +/*{ *) + <%=op.getVisibility()%> <%=op.getReturnType()%> <%=op.getName()%>Of<%=classifier.getName()%>(String topiaId}*/ + String vir = ","; + for(ObjectModelParameter param : params){ + if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);} +/*{<%=vir%><%=param.getType()%> <%=param.getName()%>}*/ + } +/*{)}*/ + Set exceptions = (Set)op.getExceptions(); + if(exceptions.isEmpty()){ +/*{throws TopiaException}*/ + } + vir = " throws "; + for (String exception : exceptions) { + if(log.isTraceEnabled()) {log.trace("exception" + exception + " vir" + vir);} +/*{<%=vir%><%=exception%>}*/ + vir = ", "; + } +/*{{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=classifier.getName()%>DAOAbstract dao = (<%=classifier.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=classifier.getName()%>.class); + <%=classifier.getName()%> entity = (<%=classifier.getName()%>)dao.findByTopiaId(topiaId); +}*/ + if(!op.getReturnType().toString().equalsIgnoreCase("void")){ +/*{ return }*/ + } +/*{ entity.<%=op.getName()%>(}*/ + vir = ""; + for(ObjectModelParameter param : params){ + if(log.isTraceEnabled()) {log.trace("Param" + param + " vir" + vir);} +/*{<%=vir%><%=param.getName()%>}*/ + vir = ", "; + } +/*{); + } +}*/ + +/*{ + +}*/ + } + } + + private void generateAssociationAccessors(Writer output, ObjectModelClass clazz, String name, String type) throws IOException { + /*{ /** + * @param value La valeur de l'attribut <%=name%> à positionner. + *) + public void set<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId, <%=type%> value) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + entity.set<%=Util.capitalize(name)%>( value); + } + + /** + * @return La valeur de l'attribut <%=name%>. + *) + public <%=type%> get<%=Util.capitalize(name)%>Of<%=clazz.getName()%>(String topiaId) throws TopiaException{ + TopiaContextImplementor usedContextImpl = (TopiaContextImplementor) topiaContext; + <%=clazz.getName()%>DAOAbstract dao = (<%=clazz.getName()%>DAOAbstract)usedContextImpl.getDAO(<%=clazz.getName()%>.class); + <%=clazz.getName()%> entity = (<%=clazz.getName()%>)dao.findByTopiaId(topiaId); + return entity.get<%=Util.capitalize(name)%>(); + } + + }*/ + } + +} //ServiceAbstractGenerator