Index: topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java diff -u topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.17 topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.18 --- topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java:1.17 Tue Jun 21 17:00:43 2005 +++ topia/src/java/org/codelutin/topia/generators/ObjectModelToEntityImplGenerator.java Wed Jul 6 17:51:24 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.17 $ + * @version $Revision: 1.18 $ * - * Mise a jour: $Date: 2005/06/21 17:00:43 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/07/06 17:51:24 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -49,8 +49,8 @@ public class ObjectModelToEntityImplGenerator extends TopiaAbstractObjectModelGenerator { // ObjectModelToEntityImplGenerator - private long currentHashCode = 0; - + // private long currentHashCode = 0; + public ObjectModelToEntityImplGenerator(){ super(); } @@ -98,8 +98,8 @@ // Attribute <%=attribute.getName()%> ////////////////////////////////////////////////////////////////////// }*/ - currentHashCode += Math.abs(attribute.getType().hashCode()); - currentHashCode += Math.abs(attribute.getName().hashCode()); + // currentHashCode += Math.abs(attribute.getType().hashCode()); + // currentHashCode += Math.abs(attribute.getName().hashCode()); if (Util.isAttributeEntity(attribute)) { /*{ //On ne génère pas de méthode d'accès, on utilisera le TopiaAssociationManager }*/ @@ -145,7 +145,7 @@ protected boolean _<%=attribute.getName()%>Modified_ = false; }*/ } - + ////////////////////////////////////////////////////////////////////// // G E T A T T R I B U T E S A C C E S S O R S ////////////////////////////////////////////////////////////////////// @@ -181,7 +181,7 @@ return this._<%=attribute.getName()%>Modified_; } }*/ - + if (attribute.hasAssociationClass()) { /*{ public <%=attribute.getAssociationClass().getQualifiedName()%> get<%=Util.capitalize(attribute.getAssociationClass().getName())%>() throws TopiaException { @@ -205,27 +205,27 @@ } if (attribute.hasAssociationClass()) { /*{ List list = new ArrayList(); - for (Iterator it = <%=attribute.getName()%>.iterator(); it.hasNext(); ) - list.add(((<%=attribute.getAssociationClass().getQualifiedName()%>)it.next()).get<%=Util.capitalize(attribute.getName())%>()); - List result = <%=Util.getInitValue(attribute)%>; - result.add(list); - return Collections.unmodifiableList(result); + for (Iterator it = <%=attribute.getName()%>.iterator(); it.hasNext(); ) + list.add(((<%=attribute.getAssociationClass().getQualifiedName()%>)it.next()).get<%=Util.capitalize(attribute.getName())%>()); + List result = <%=Util.getInitValue(attribute)%>; + result.add(list); + return Collections.unmodifiableList(result); }*/ } else { /*{ return Collections.unmodifiableList(<%=attribute.getName()%>); }*/ } -/*{ } +/*{ } public boolean is_<%=attribute.getName()%>Modified_() { return this._<%=attribute.getName()%>Modified_; } - + public int sizeOf<%=Util.capitalize(attribute.getName())%>() throws TopiaException { return <%=attribute.getName()%>.size();}*/ - /*Peut être optimisé en évitant de charger l'objet si ce n'est pas le cas*/ /*{ + /*Peut être optimisé en évitant de charger l'objet si ce n'est pas le cas*/ /*{ } - + public Iterator iteratorOn<%=Util.capitalize(attribute.getName())%>() throws TopiaException { }*/ if (doSecurity()) { @@ -240,7 +240,7 @@ }*/ } /*{ } - + public boolean containsIn<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { }*/ if (doSecurity()) { @@ -304,7 +304,7 @@ } }*/ } - + ////////////////////////////////////////////////////////////////////// // S E T A T T R I B U T E S A C C E S S O R S ////////////////////////////////////////////////////////////////////// @@ -322,13 +322,13 @@ if (!attribute.hasAssociationClass()) { /*{ public void set<%=Util.capitalize(attribute.getName())%>(<%=Util.getAttributeType(attribute)%> value) throws TopiaException { -}*/ +}*/ if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ } if (!Util.isPrimitiveAttributeType(attribute) && Util.isOneMultiplicity(attribute)) - if (attribute.isComposite()) { + if (attribute.isComposite()) { //TODO Pas adapté au composite !!!! /*{ if (value == null) throw new TopiaException("Cannot set <%=attribute.getName()%> to null - Multiplicity 1"); @@ -392,7 +392,7 @@ this.<%=attribute.getName()%>.add(association); this._<%=attribute.getName()%>Modified_ = true; } - + public void add<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> association) throws TopiaException { }*/ if (doSecurity()) { @@ -410,7 +410,7 @@ if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ - } + } if (attribute.isComposite()) { /*{ add_dependentEntities_(value); }*/ @@ -420,8 +420,8 @@ } }*/ } - -/*{ + +/*{ public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getType()%> value) throws TopiaException { }*/ if (attribute.hasAssociationClass()) { @@ -430,17 +430,17 @@ }*/ } /*{ if (value == null) - return; - for (Iterator i = this.<%=attribute.getName()%>.iterator(); i.hasNext(); ) { - <%=attribute.getAssociationClass().getQualifiedName()%> item = (<%=attribute.getAssociationClass().getQualifiedName()%>)i.next(); - if (value.equals(item.get<%=Util.capitalize(attribute.getName())%>())) { - this.<%=attribute.getName()%>.remove(item); + return; + for (Iterator i = this.<%=attribute.getName()%>.iterator(); i.hasNext(); ) { + <%=attribute.getAssociationClass().getQualifiedName()%> item = (<%=attribute.getAssociationClass().getQualifiedName()%>)i.next(); + if (value.equals(item.get<%=Util.capitalize(attribute.getName())%>())) { + this.<%=attribute.getName()%>.remove(item); this._<%=attribute.getName()%>Modified_ = true; - return; - } - } - } - + return; + } + } + } + public void remove<%=Util.capitalize(attribute.getName())%>(<%=attribute.getAssociationClass().getQualifiedName()%> value) throws TopiaException { }*/ } @@ -463,7 +463,7 @@ }*/ } if (attribute.isComposite()) { -/*{ for (Iterator it = this.<%=attribute.getName()%>.iterator(); it.hasNext(); ) +/*{ for (Iterator it = this.<%=attribute.getName()%>.iterator(); it.hasNext(); ) remove_dependentEntities_((TopiaEntity)it.next()); }*/ } @@ -479,7 +479,7 @@ } public void add<%=Util.capitalize(attribute.getName())%>(/*<%=Util.getAttributeType(attribute)%>*)java.util.Collection list, boolean duplicate) throws TopiaException { -}*/ +}*/ if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); }*/ @@ -504,7 +504,7 @@ } /*{ public void set<%=Util.capitalize(attribute.getName())%>(int index, <%=attribute.getType()%> value) throws TopiaException { -}*/ +}*/ if (attribute.hasAssociationClass()) { if (doSecurity()) { /*{ TopiaAccessController.checkPermission(this, "write"); @@ -531,7 +531,7 @@ } }*/ } - + public void generateSetAssociationAttributeAccessor(Writer output, ObjectModelAttribute attribute) throws IOException { /*{ @@ -590,7 +590,7 @@ <%=clazz.getName()%>PersistenceService persistenceService = getPersistenceService(); persistenceService.delete(this); for (Iterator i = iterator_dependentEntities_(); i.hasNext(); ) - ((TopiaEntity)i.next()).remove(); + ((TopiaEntity)i.next()).remove(); } }*/ } @@ -603,15 +603,17 @@ /*{ ////////////////////////////////////////////////////////////////////// - // Other framework methods + // Other framework methods ////////////////////////////////////////////////////////////////////// }*/ - currentHashCode += Math.abs(clazzifier.getQualifiedName().hashCode()); + // currentHashCode += Math.abs(clazzifier.getQualifiedName().hashCode()); + if(clazzifier instanceof ObjectModelClass){ /*{ - protected static final long serialVersionUID = <%=currentHashCode%>L; + protected static final long serialVersionUID = <%=Util.getSerialVersionUID((ObjectModelClass)clazzifier)%>L; }*/ - currentHashCode = 0; - generateSetAllFrameworkProperties(output, (ObjectModelClass)clazzifier); + } + // currentHashCode = 0; + generateSetAllFrameworkProperties(output, (ObjectModelClass)clazzifier); /*{ public <%=clazzifier.getName()%>Impl()throws TopiaException { } @@ -664,17 +666,17 @@ }*/ if(clazzifier instanceof ObjectModelClass) { - ObjectModelClass clazz = (ObjectModelClass)clazzifier; + ObjectModelClass clazz = (ObjectModelClass)clazzifier; /*{ /** * Return the model class for this entity as an entry point in the project entities model *) public ObjectModelClass getModelElement() { - return null; // TODO + return null; // TODO } }*/ - } + } } protected void generateSetAllFrameworkProperties(Writer output, ObjectModelClass clazz) throws IOException { Index: topia/src/java/org/codelutin/topia/generators/Util.java diff -u topia/src/java/org/codelutin/topia/generators/Util.java:1.6 topia/src/java/org/codelutin/topia/generators/Util.java:1.7 --- topia/src/java/org/codelutin/topia/generators/Util.java:1.6 Tue Jun 21 17:00:43 2005 +++ topia/src/java/org/codelutin/topia/generators/Util.java Wed Jul 6 17:51:24 2005 @@ -23,10 +23,10 @@ * * @author Benjamin Poussin * Copyright Code Lutin - * @version $Revision: 1.6 $ + * @version $Revision: 1.7 $ * - * Mise a jour: $Date: 2005/06/21 17:00:43 $ - * par : $Author: thimel $ + * Mise a jour: $Date: 2005/07/06 17:51:24 $ + * par : $Author: bpoussin $ */ package org.codelutin.topia.generators; @@ -74,7 +74,7 @@ public static boolean isEntity(ObjectModelClassifier classifier) { return classifier.hasStereotype("entity"); } - + /** * Returns whether this classifier is a service or not. * @@ -279,16 +279,32 @@ } return result; } - + /** * Return wether the given attribute is an application Entity - * + * * @return a boolean indicationg if the given attribute is an Entity */ public static boolean isAttributeEntity(ObjectModelAttribute attribute) { if (!(attribute.getClassifier() instanceof ObjectModelClassifier)) return false; return isEntity((ObjectModelClassifier)attribute.getClassifier()); + } + + /** + * Genere le le serialVersionUID pour l'objet passé en arguemnt. + * Ce serialVersionUID est generé en fonctione des attributs et de la classe + */ + public static long getSerialVersionUID(ObjectModelClass clazzifier){ + long result = 0; + result += Math.abs(clazzifier.getQualifiedName().hashCode()); + + for(Iterator i=clazzifier.getAttributes().iterator(); i.hasNext();) { + ObjectModelAttribute attribute = (ObjectModelAttribute) i.next(); + result += Math.abs(attribute.getType().hashCode()); + result += Math.abs(attribute.getName().hashCode()); + } + return result; } } // Util