From: Wouter Z. <dra...@us...> - 2006-09-20 12:11:46
|
User: draftdog Date: 06/09/20 05:11:44 Modified: andromda-spring/src/test/expected Tag: V3_x_HEAD cartridge-output.zip uml/common/src/java/org/andromda/metafacades/uml Tag: V3_x_HEAD EntityMetafacadeUtils.java uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2 Tag: V3_x_HEAD EntityLogicImpl.java GeneralizableElementFacadeLogicImpl.java UmlUtilities.java uml/uml14/src/java/org/andromda/metafacades/uml14 Tag: V3_x_HEAD EntityLogicImpl.java Log: identifiers are only added to inheritance hierarchy roots, this fixes an outstanding bug which has affected crud users since the beginning, we could do without this constraint if no facades would be called during the initialization phase (see my comment in the committed EntityLogicImpl.java files); minor coding improvements and simplifications Revision Changes Path No revision No revision 1.269.2.66 +260 -281 cartridges/andromda-spring/src/test/expected/cartridge-output.zip <<Binary file>> No revision No revision 1.11.2.3 +17 -21 metafacades/uml/common/src/java/org/andromda/metafacades/uml/EntityMetafacadeUtils.java Index: EntityMetafacadeUtils.java =================================================================== RCS file: /cvsroot/andromda/metafacades/uml/common/src/java/org/andromda/metafacades/uml/EntityMetafacadeUtils.java,v retrieving revision 1.11.2.2 retrieving revision 1.11.2.3 diff -u -w -r1.11.2.2 -r1.11.2.3 --- EntityMetafacadeUtils.java 6 Jan 2006 17:35:20 -0000 1.11.2.2 +++ EntityMetafacadeUtils.java 20 Sep 2006 12:11:44 -0000 1.11.2.3 @@ -227,34 +227,30 @@ } /** - * Retrieves the identifiers for the given <code>entity</code>. If - * <code>follow</code> is true then the inheritance hierachy will also be - * searched. + * Gets all identifiers for an entity. If 'follow' is true, and if + * no identifiers can be found on the entity, a search up the + * inheritance chain will be performed, and the identifiers from + * the first super class having them will be used. If no + * identifiers exist, a default identifier will be created if the + * allowDefaultIdentifiers property is set to true. * + * @param entity the entity for which to retrieve the identifiers * @param follow a flag indicating whether or not the inheritance hiearchy * should be followed * @return the collection of identifiers. */ public static Collection getIdentifiers( - Entity entity, - boolean follow) + final Entity entity, + final boolean follow) { - Collection identifiers = entity.getAttributes(); + final Collection identifiers = entity.getAttributes(); MetafacadeUtils.filterByStereotype( identifiers, UMLProfile.STEREOTYPE_IDENTIFIER); - for (ClassifierFacade superClass = (ClassifierFacade)entity.getGeneralization(); - superClass != null && identifiers.isEmpty() && follow; - superClass = (ClassifierFacade)superClass.getGeneralization()) - { - if (superClass.hasStereotype(UMLProfile.STEREOTYPE_ENTITY)) - { - Entity facade = (Entity)superClass; - identifiers.addAll(facade.getIdentifiers(follow)); - } - } - return identifiers; + return identifiers.isEmpty() && follow && entity.getGeneralization() instanceof Entity + ? getIdentifiers((Entity)entity.getGeneralization(), follow) + : identifiers; } /** @@ -273,10 +269,10 @@ String value = typeName; if (StringUtils.isNotEmpty(typeName)) { - char beginChar = '('; - char endChar = ')'; - int beginIndex = value.indexOf(beginChar); - int endIndex = value.indexOf(endChar); + final char beginChar = '('; + final char endChar = ')'; + final int beginIndex = value.indexOf(beginChar); + final int endIndex = value.indexOf(endChar); if (beginIndex != -1 && endIndex != -1 && endIndex > beginIndex) { String replacement = value.substring( No revision No revision 1.5.2.10 +25 -11 metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/EntityLogicImpl.java Index: EntityLogicImpl.java =================================================================== RCS file: /cvsroot/andromda/metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/EntityLogicImpl.java,v retrieving revision 1.5.2.9 retrieving revision 1.5.2.10 diff -u -w -r1.5.2.9 -r1.5.2.10 --- EntityLogicImpl.java 25 Aug 2006 04:07:08 -0000 1.5.2.9 +++ EntityLogicImpl.java 20 Sep 2006 12:11:44 -0000 1.5.2.10 @@ -1,12 +1,5 @@ package org.andromda.metafacades.emf.uml2; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Iterator; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Set; - import org.andromda.core.metafacade.MetafacadeConstants; import org.andromda.core.metafacade.MetafacadeException; import org.andromda.metafacades.uml.AssociationEndFacade; @@ -36,6 +29,13 @@ import org.eclipse.uml2.Type; import org.eclipse.uml2.VisibilityKind; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; + /** * MetafacadeLogic implementation for org.andromda.metafacades.uml.Entity. @@ -66,7 +66,7 @@ super.initialize(); // if there are no identifiers on this entity, create and add one. - // enumeration don't have identifiers since they are not entities + // enumerations don't have identifiers since they are not entities if (!this.isIdentifiersPresent() && this.isAllowDefaultIdentifiers()) { this.createIdentifier(); @@ -168,7 +168,20 @@ final String type, final String visibility) { - org.eclipse.uml2.Class umlClass = (org.eclipse.uml2.Class)this.metaObject; + final org.eclipse.uml2.Class umlClass = (org.eclipse.uml2.Class)this.metaObject; + + // if we auto-create entity identifiers it will only be on hierarchy roots, + // problems would arise when calls to #checkForAndAddForeignIdentifiers() + // navigate over associated entities, effectively initializing their facade instances: + // this results in subclasses having an identifier generated before their ancestors + // ideally the method mentioned above would not make use of facades but meta-classes only, + // if one is to refactor it that way this comment may be removed together with the line of code under it + // + // notice how the next line of code does not make use of facades, this is done on purpose in order + // to avoid using uninitialized facades + // + // (Wouter, Sept. 20 2006) also see other UML implementations + if (!umlClass.getGeneralizations().isEmpty()) return; if (umlClass.getAttribute(name) == null) { @@ -187,6 +200,7 @@ element, 1, 1); + logger.info(" " + this.getName() + " " + System.identityHashCode(this) + " x created!!!"); VisibilityKind kind = VisibilityKind.PUBLIC_LITERAL; if (visibility.equalsIgnoreCase("package")) { @@ -842,7 +856,7 @@ } /** - * @see org.andromda.metafacades.uml.Entity#getAssociationEndsIdentifiers() + * @see org.andromda.metafacades.uml.Entity#getIdentifierAssociationEnds() */ protected Collection handleGetIdentifierAssociationEnds() { Collection associationEnds = this.getAssociationEnds(); @@ -863,7 +877,7 @@ identifiers = identifiers + (!this.getIdentifierAssociationEnds().isEmpty() ? this.getIdentifierAssociationEnds().size() : 0); - return (identifiers < 2) ? false : true; + return identifiers >= 2; } } \ No newline at end of file 1.2.2.6 +4 -9 metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/GeneralizableElementFacadeLogicImpl.java Index: GeneralizableElementFacadeLogicImpl.java =================================================================== RCS file: /cvsroot/andromda/metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/GeneralizableElementFacadeLogicImpl.java,v retrieving revision 1.2.2.5 retrieving revision 1.2.2.6 diff -u -w -r1.2.2.5 -r1.2.2.6 --- GeneralizableElementFacadeLogicImpl.java 5 Jul 2006 14:56:23 -0000 1.2.2.5 +++ GeneralizableElementFacadeLogicImpl.java 20 Sep 2006 12:11:44 -0000 1.2.2.6 @@ -55,14 +55,10 @@ protected java.lang.Object handleGetGeneralization() { Object parent = null; - Collection generalizations = ((Classifier)this.metaObject).getGeneralizations(); - if (generalizations != null) - { - Iterator iterator = generalizations.iterator(); - if (iterator.hasNext()) + final Collection generalizations = ((Classifier)this.metaObject).getGeneralizations(); + if (generalizations != null && !generalizations.isEmpty()) { - parent = ((Generalization)iterator.next()).getGeneral(); - } + parent = ((Generalization)generalizations.iterator().next()).getGeneral(); } return parent; } @@ -72,8 +68,7 @@ */ protected java.util.Collection handleGetSpecializations() { - Collection specializations = UmlUtilities.getSpecializations((Classifier)this.metaObject); - return specializations; + return UmlUtilities.getSpecializations((Classifier)this.metaObject); } /** 1.4.2.25 +0 -1 metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/UmlUtilities.java Index: UmlUtilities.java =================================================================== RCS file: /cvsroot/andromda/metafacades/uml/emf/uml2/src/main/java/org/andromda/metafacades/emf/uml2/UmlUtilities.java,v retrieving revision 1.4.2.24 retrieving revision 1.4.2.25 diff -u -w -r1.4.2.24 -r1.4.2.25 --- UmlUtilities.java 27 Aug 2006 11:30:19 -0000 1.4.2.24 +++ UmlUtilities.java 20 Sep 2006 12:11:44 -0000 1.4.2.25 @@ -3,7 +3,6 @@ import org.andromda.core.common.ExceptionUtils; import org.andromda.core.metafacade.MetafacadeConstants; import org.andromda.metafacades.uml.ClassifierFacade; -import org.andromda.metafacades.uml.StereotypeFacade; import org.andromda.metafacades.uml.UMLProfile; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; No revision No revision 1.32.2.9 +20 -5 metafacades/uml/uml14/src/java/org/andromda/metafacades/uml14/EntityLogicImpl.java Index: EntityLogicImpl.java =================================================================== RCS file: /cvsroot/andromda/metafacades/uml/uml14/src/java/org/andromda/metafacades/uml14/EntityLogicImpl.java,v retrieving revision 1.32.2.8 retrieving revision 1.32.2.9 diff -u -w -r1.32.2.8 -r1.32.2.9 --- EntityLogicImpl.java 25 Aug 2006 04:07:06 -0000 1.32.2.8 +++ EntityLogicImpl.java 20 Sep 2006 12:11:44 -0000 1.32.2.9 @@ -159,10 +159,25 @@ final String type, final String visibility) { + final Classifier classifier = (Classifier)this.metaObject; + + // if we auto-create entity identifiers it will only be on hierarchy roots, + // problems would arise when calls to #checkForAndAddForeignIdentifiers() + // navigate over associated entities, effectively initializing their facade instances: + // this results in subclasses having an identifier generated before their ancestors + // ideally the method mentioned above would not make use of facades but meta-classes only, + // if one is to refactor it that way this comment may be removed together with the line of code under it + // + // notice how the next line of code does not make use of facades, this is done on purpose in order + // to avoid using uninitialized facades + // + // (Wouter, Sept. 20 2006) also see other UML implementations + if (!classifier.getGeneralization().isEmpty()) return; + // only create the identifier if an identifer with the name doesn't // already exist if (!UML14MetafacadeUtils.attributeExists( - this.metaObject, + classifier, name)) { final Attribute identifier = @@ -175,7 +190,7 @@ identifier.getStereotype().add( UML14MetafacadeUtils.findOrCreateStereotype(UMLProfile.STEREOTYPE_IDENTIFIER)); - ((Classifier)this.metaObject).getFeature().add(identifier); + classifier.getFeature().add(identifier); } } @@ -786,11 +801,11 @@ } /** - * @see org.andromda.metafacades.uml.Entity#identifierAssociationEnds() + * @see org.andromda.metafacades.uml.Entity#getIdentifierAssociationEnds() */ protected Collection handleGetIdentifierAssociationEnds() { - Collection associationEnds = this.getAssociationEnds(); + final Collection associationEnds = this.getAssociationEnds(); if (associationEnds != null) { MetafacadeUtils.filterByStereotype( @@ -809,6 +824,6 @@ identifiers = identifiers + (!this.getIdentifierAssociationEnds().isEmpty() ? this.getIdentifierAssociationEnds().size() : 0); - return (identifiers < 2) ? false : true; + return identifiers >= 2; } } \ No newline at end of file |