From: Vance K. <va...@us...> - 2006-01-26 07:07:40
|
User: vancek Date: 06/01/25 23:07:33 Modified: andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades EJB3AssociationEndFacadeLogicImpl.java Log: added collection type constants, overriden getGetterSetterTypeName and added optional generics, added getSpecificCollectionType, getCollectionType, isList, isMap and isSet Revision Changes Path 1.4 +191 -8 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationEndFacadeLogicImpl.java Index: EJB3AssociationEndFacadeLogicImpl.java =================================================================== RCS file: /cvsroot/andromdaplugins/cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationEndFacadeLogicImpl.java,v retrieving revision 1.3 retrieving revision 1.4 diff -u -w -r1.3 -r1.4 --- EJB3AssociationEndFacadeLogicImpl.java 25 Jan 2006 02:57:29 -0000 1.3 +++ EJB3AssociationEndFacadeLogicImpl.java 26 Jan 2006 07:07:33 -0000 1.4 @@ -1,13 +1,17 @@ package org.andromda.cartridges.ejb3.metafacades; +import java.util.ArrayList; import java.util.Collection; import java.util.Hashtable; import java.util.Iterator; import org.andromda.cartridges.ejb3.EJB3Globals; import org.andromda.cartridges.ejb3.EJB3Profile; +import org.andromda.metafacades.uml.ClassifierFacade; import org.andromda.metafacades.uml.TaggedValueFacade; -import org.apache.commons.lang.BooleanUtils; +import org.andromda.metafacades.uml.TypeMappings; +import org.andromda.metafacades.uml.UMLMetafacadeProperties; +import org.andromda.metafacades.uml.UMLProfile; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; @@ -39,6 +43,26 @@ public static final String ENTITY_DEFAULT_AGGREGATION_CASCADE = "entityAggergationCascade"; /** + * The namespace property storing default collection type for associations + */ + public static final String ASSOCIATION_COLLECTION_TYPE = "associationCollectionType"; + + /** + * A flag indicating whether or not specific (java.util.Set, java.util.List, + * etc) collection interfaces should be used in assocation mutators and + * accessors or whether the generic java.util.Collection interface should be + * used. + */ + public static final String SPECIFIC_COLLECTION_INTERFACES = "specificCollectionInterfaces"; + + /** + * The property that defines the default collection interface, this is the + * interface used if the property defined by + * {@link #SPECIFIC_COLLECTION_INTERFACES} is true. + */ + public static final String DEFAULT_COLLECTION_INTERFACE = "defaultCollectionInterface"; + + /** * Represents the EJB3 <code>ALL</code> cascade option and fully qualified representation. */ private static final String ENTITY_CASCADE_ALL = "ALL"; @@ -87,6 +111,39 @@ cascadeTable.put(ENTITY_CASCADE_REFRESH, ENTITY_CASCADE_REFRESH_FQN); } + /** + * Value for set + */ + private static final String COLLECTION_TYPE_SET = "set"; + + /** + * Value for map + */ + private static final String COLLECTION_TYPE_MAP = "map"; + + /** + * Value for list + */ + private static final String COLLECTION_TYPE_LIST = "list"; + + /** + * Value for collections + */ + private static final String COLLECTION_TYPE_COLLECTION = "collection"; + + /** + * Stores the valid collection types + */ + private static final Collection collectionTypes = new ArrayList(); + + static + { + collectionTypes.add(COLLECTION_TYPE_SET); + collectionTypes.add(COLLECTION_TYPE_MAP); + collectionTypes.add(COLLECTION_TYPE_LIST); + collectionTypes.add(COLLECTION_TYPE_COLLECTION); + } + // ---------------- constructor ------------------------------- public EJB3AssociationEndFacadeLogicImpl (Object metaObject, String context) @@ -96,21 +153,77 @@ // --------------- methods --------------------- + /** - * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade#getRelationType() + * @see org.andromda.metafacades.uml.AssociationEndFacade#getGetterSetterTypeName() */ - protected java.lang.String handleGetRelationType() + public String getGetterSetterTypeName() + { + String getterSetterTypeName = null; + + if (this.isMany()) + { + final boolean specificInterfaces = + Boolean.valueOf( + ObjectUtils.toString(this.getConfiguredProperty(SPECIFIC_COLLECTION_INTERFACES))).booleanValue(); + + final TypeMappings mappings = this.getLanguageMappings(); + if (mappings != null) + { + if (this.isMap()) + { + getterSetterTypeName = mappings.getTo(UMLProfile.MAP_TYPE_NAME); + } + else if (specificInterfaces) + { + if (this.isSet()) { - String targetType; - if (this.isMany2Many() || this.isOne2Many()) + getterSetterTypeName = mappings.getTo(UMLProfile.SET_TYPE_NAME); + } + else if (this.isList()) + { + getterSetterTypeName = mappings.getTo(UMLProfile.LIST_TYPE_NAME); + } + } + else + { + getterSetterTypeName = + ObjectUtils.toString(this.getConfiguredProperty(DEFAULT_COLLECTION_INTERFACE)); + } + } + else { - targetType = "java.util.Collection"; + getterSetterTypeName = ObjectUtils.toString(this.getConfiguredProperty(DEFAULT_COLLECTION_INTERFACE)); + } } else { - targetType = this.getOtherEnd().getType().getFullyQualifiedName(); + final ClassifierFacade type = this.getType(); + if (type instanceof EJB3EntityFacade) + { + final String typeName = ((EJB3EntityFacade)type).getFullyQualifiedEntityName(); + if (StringUtils.isNotEmpty(typeName)) + { + getterSetterTypeName = typeName; + } } - return targetType; + } + + if (getterSetterTypeName == null) + { + getterSetterTypeName = super.getGetterSetterTypeName(); + } + else if (this.isMany()) + { + /** + * Set this association end's type as a template parameter if required + */ + if ("true".equals(this.getConfiguredProperty(UMLMetafacadeProperties.ENABLE_TEMPLATING))) + { + getterSetterTypeName = getterSetterTypeName + "<" + this.getType().getFullyQualifiedName() + ">"; + } + } + return getterSetterTypeName; } /** @@ -363,4 +476,74 @@ ObjectUtils.toString(this.getConfiguredProperty(ENTITY_DEFAULT_AGGREGATION_CASCADE))); } + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetCollectionType() + */ + protected String handleGetCollectionType() + { + String collectionType = this.getSpecificCollectionType(); + if (!collectionTypes.contains(collectionType)) + { + if (this.isOrdered()) + { + collectionType = COLLECTION_TYPE_LIST; + } + else + { + collectionType = + (String)this.getConfiguredProperty(ASSOCIATION_COLLECTION_TYPE); + } + } + return collectionType; + } + + /** + * Gets the collection type defined on this association end. + * + * @return the specific collection type. + */ + private String getSpecificCollectionType() + { + return ObjectUtils.toString( + this.findTaggedValue(EJB3Profile.TAGGEDVALUE_ASSOCIATION_COLLECTION_TYPE)); + } + + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsMap() + */ + protected boolean handleIsMap() + { + boolean isMap = this.getCollectionType().equalsIgnoreCase(COLLECTION_TYPE_MAP); + if (isMap && StringUtils.isBlank(this.getSpecificCollectionType())) + { + isMap = !this.isOrdered(); + } + return isMap; + } + + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsList() + */ + protected boolean handleIsList() + { + boolean isList = this.getCollectionType().equalsIgnoreCase(COLLECTION_TYPE_LIST); + if (!isList && StringUtils.isBlank(this.getSpecificCollectionType())) + { + isList = this.isOrdered(); + } + return isList; + } + + /** + * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsSet() + */ + protected boolean handleIsSet() + { + boolean isSet = this.getCollectionType().equalsIgnoreCase(COLLECTION_TYPE_SET); + if (isSet && StringUtils.isBlank(this.getSpecificCollectionType())) + { + isSet = !this.isOrdered(); + } + return isSet; + } } \ No newline at end of file |