From: Vance K. <va...@us...> - 2005-12-28 00:33:05
|
User: vancek Date: 05/12/27 16:32:57 Added: andromda-ejb3/conf/test andromda.xml andromda-ejb3/src/test/mappings MergeMappings.xml andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades EJB3AssociationFacadeLogicImpl.java EJB3FinderMethodFacadeLogicImpl.java EJB3SessionAttributeFacadeLogicImpl.java EJB3MetafacadeUtils.java EJB3SessionOperationFacadeLogicImpl.java EJB3AssociationEndFacadeLogicImpl.java EJB3OperationFacadeLogicImpl.java EJB3EntityFacadeLogicImpl.java EJB3FinderMethodArgumentFacadeLogicImpl.java EJB3EntityAttributeFacadeLogicImpl.java EJB3SessionFacadeLogicImpl.java andromda-ejb3/src/test/expected cartridge-output.zip andromda-ejb3/src/main/resources/templates/ejb3 SessionBeanImpl.vsl EntityImpl.vsl SessionBean.vsl SessionRemote.vsl Entity.vsl Globals.vm SessionLocal.vsl EntityListener.vsl andromda-ejb3/src/main/resources/META-INF/andromda profile.xml cartridge.xml metafacades.xml namespace.xml andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3 EJB3Profile.java EJB3ScriptHelper.java EJB3Globals.java andromda-ejb3 pom.xml andromda-ejb3/src/main/uml EJB3MetafacadeModel.xml.zip andromda-ejb3/src/test/uml EJB3CartridgeTestModel.xml.zip Log: Initial revision - EJB3 cartridge. Revision Changes Path 1.1 cartridges/andromda-ejb3/conf/test/andromda.xml Index: andromda.xml =================================================================== <andromda> <properties> <property name="failOnValidationErrors">false</property> </properties> <repositories> <repository name="netBeansMDR"> <models> <model> <uri>${test.model.uri}</uri> <moduleSearchLocations> <location patterns="**/*.xml.zip">${settings.localRepository}/org/andromda/profiles</location> </moduleSearchLocations> <modelPackages> <modelPackage process="false">org::andromda::metafacades::uml</modelPackage> </modelPackages> </model> </models> </repository> </repositories> <namespaces> <namespace name="ejb3"> <properties> <property name="overwrite">true</property> <property name="languageMappingsUri">Java</property> <property name="wrapperMappingsUri">JavaWrapper</property> <property name="jdbcMappingsUri">JDBC</property> <property name="sqlMappingsUri">Oracle9i</property> <property name="entity-beans">${test.output.dir}</property> <property name="entity-impls">${test.output.dir}</property> <property name="session-beans">${test.output.dir}</property> <property name="session-impls">${test.output.dir}</property> <property name="value-objects">${test.output.dir}</property> <property name="mergeMappingsUri">file:${pom.basedir}/src/test/mappings/MergeMappings.xml</property> </properties> </namespace> </namespaces> </andromda> 1.1 cartridges/andromda-ejb3/src/test/mappings/MergeMappings.xml Index: MergeMappings.xml =================================================================== <mappings name="EJBMergeMappings"> <mapping> <from><![CDATA[// license-header java merge-point]]></from> <to> <![CDATA[ /** * Example license header for Java files * * http://www.andromda.org/ */ ]]> </to> </mapping> </mappings> 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationFacadeLogicImpl.java Index: EJB3AssociationFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import org.andromda.cartridges.ejb3.EJB3Profile; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3AssociationFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationFacade */ public class EJB3AssociationFacadeLogicImpl extends EJB3AssociationFacadeLogic { // ---------------- constructor ------------------------------- public EJB3AssociationFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // --------------- methods --------------------- /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationFacade#getTransactionType() */ protected java.lang.String handleGetTransactionType() { return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_TYPE); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationFacadeLogic#handleGetTableName() */ public String getTableName() { String tableName = super.getTableName(); if (getName().toLowerCase().startsWith(tableName.toLowerCase())) { tableName = getRelationName().replaceAll("-", "_").toUpperCase(); } return tableName; } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3FinderMethodFacadeLogicImpl.java Index: EJB3FinderMethodFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import java.util.Collection; import java.util.Iterator; import org.andromda.cartridges.ejb3.EJB3Globals; import org.andromda.cartridges.ejb3.EJB3Profile; import org.andromda.metafacades.uml.ParameterFacade; import org.apache.commons.lang.StringUtils; /** * <p/> * Represents an EJB finder method. </p> * * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3FinderMethodFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3FinderMethodFacade */ public class EJB3FinderMethodFacadeLogicImpl extends EJB3FinderMethodFacadeLogic { // ---------------- constructor ------------------------------- public EJB3FinderMethodFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // --------------- methods --------------------- /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3FinderMethodFacade#getQuery() */ protected java.lang.String handleGetQuery() { // first see if there is a query stored as a constraint String queryString = super.getQuery("query.EJB-QL"); // otherwise see if there is a query stored as a tagged value if (StringUtils.isEmpty(queryString)) { Object value = this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_QUERY); queryString = (String)value; if (queryString != null) { // remove any excess whitespace queryString = queryString.replaceAll("[$\\s]+", " "); } } // if there wasn't any stored query, create one by default. if (StringUtils.isEmpty(queryString)) { String variableName = StringUtils.uncapitalize(this.getOwner().getName()); queryString = "FROM " + this.getOwner().getName() + " AS " + variableName; if (this.getArguments().size() > 0) { queryString = queryString + " WHERE"; Collection parameters = this.getArguments(); if (parameters != null && !parameters.isEmpty()) { Iterator parameterIt = parameters.iterator(); for (int ctr = 0; parameterIt.hasNext(); ctr++) { EJB3FinderMethodArgumentFacade param = (EJB3FinderMethodArgumentFacade)parameterIt.next(); if (!param.isFirstResult() && !param.isMaxResults()) { String parameter = "?"; if (this.isUseNamedParameters()) { parameter = ":" + param.getName(); } else { parameter = parameter + ctr; } queryString = queryString + " " + variableName + "." + param.getName() + " = " + parameter; if (parameterIt.hasNext()) { queryString = queryString + " AND"; } } } } } } return queryString; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3FinderMethodFacade#getTransactionType() */ protected java.lang.String handleGetTransactionType() { return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_TYPE, true); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3FinderMethodFacadeLogic#handleIsUseNamedParameters() */ protected boolean handleIsUseNamedParameters() { return Boolean.valueOf(String.valueOf( this.getConfiguredProperty(EJB3Globals.QUERY_USE_NAMED_PARAMETERS))).booleanValue(); } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3SessionAttributeFacadeLogicImpl.java Index: EJB3SessionAttributeFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import org.andromda.cartridges.ejb3.EJB3Profile; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3SessionAttributeFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3SessionAttributeFacade */ public class EJB3SessionAttributeFacadeLogicImpl extends EJB3SessionAttributeFacadeLogic { // ---------------- constructor ------------------------------- public EJB3SessionAttributeFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // ---------------- methods ------------------------------- /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3SessionAttributeFacade#getTransactionType() */ protected java.lang.String handleGetTransactionType() { return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_TYPE, true); } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3MetafacadeUtils.java Index: EJB3MetafacadeUtils.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import org.andromda.cartridges.ejb3.EJB3Profile; import org.andromda.core.common.ExceptionUtils; import org.andromda.metafacades.uml.AttributeFacade; import org.andromda.metafacades.uml.ClassifierFacade; import org.andromda.metafacades.uml.ModelElementFacade; import org.andromda.metafacades.uml.OperationFacade; import org.andromda.metafacades.uml.UMLProfile; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.lang.StringUtils; import java.util.ArrayList; import java.util.Collection; import java.util.Iterator; import java.util.List; /** * Contains utilities for use with EJB metafacades. * * @author Chad Brandon */ class EJB3MetafacadeUtils { /** * Gets all create methods for the given <code>classifier</code>. * * @param classifier The classifier from which to retries the create methods * @param follow if true, all super type create methods are also retrieved * @return Collection of create methods found. */ static Collection getCreateMethods( ClassifierFacade classifier, boolean follow) { final String methodName = "EJBMetafacadeUtils.getCreateMethods"; ExceptionUtils.checkNull(methodName, "classifer", classifier); Collection retval = new ArrayList(); ClassifierFacade entity = classifier; do { Collection ops = entity.getOperations(); for (final Iterator i = ops.iterator(); i.hasNext();) { final OperationFacade op = (OperationFacade)i.next(); if (op.hasStereotype(EJB3Profile.STEREOTYPE_CREATE_METHOD)) { retval.add(op); } } if (follow) { entity = (ClassifierFacade)entity.getGeneralization(); } } while (follow && entity != null); return retval; } /** * Gets the interface name for the passed in <code>classifier</code>. Returns 'LocalHome' if the mode element has * the entity stereotype, returns 'Home' otherwise. * * @return the interface name. */ static String getHomeInterfaceName(ClassifierFacade classifier) { final String methodName = "EJBMetafacadeUtils.getHomeInterfaceName"; ExceptionUtils.checkNull(methodName, "classifer", classifier); String homeInterfaceName; if (classifier.hasStereotype(UMLProfile.STEREOTYPE_ENTITY)) { homeInterfaceName = classifier.getName() + "LocalHome"; } else { homeInterfaceName = classifier.getName() + "Home"; } return homeInterfaceName; } /** * Gets the view type for the passed in <code>classifier</code>. Returns 'local' if the model element has the entity * stereotype, others checks there ejb tagged value and if there is no value defined, returns 'remote'. * * @return String the view type name. */ static String getViewType(ClassifierFacade classifier) { final String methodName = "EJBMetafacadeUtils.getViewType"; ExceptionUtils.checkNull(methodName, "classifer", classifier); String viewType = "local"; if (classifier.hasStereotype(EJB3Profile.STEREOTYPE_SERVICE)) { String viewTypeValue = (String)classifier.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_VIEWTYPE); // if the view type wasn't found, search all super classes if (StringUtils.isEmpty(viewTypeValue)) { viewType = (String)CollectionUtils.find(classifier.getAllGeneralizations(), new Predicate() { public boolean evaluate(Object object) { return ((ModelElementFacade)object).findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_VIEWTYPE) != null; } }); } if (StringUtils.isNotEmpty(viewTypeValue)) { viewType = viewTypeValue; } else { viewType = "remote"; } } return viewType.toLowerCase(); } /** * Gets all the inherited instance attributes, excluding the instance attributes directory from this * <code>classifier</code>. * * @param classifer the ClassifierFacade from which to retrieve the inherited attributes. * @return a list of ordered attributes. */ static List getInheritedInstanceAttributes(ClassifierFacade classifier) { final String methodName = "EJBMetafacadeUtils.getInheritedInstanceAttributes"; ExceptionUtils.checkNull(methodName, "classifer", classifier); ClassifierFacade current = (ClassifierFacade)classifier.getGeneralization(); if (current == null) { return new ArrayList(); } List retval = getInheritedInstanceAttributes(current); if (current.getInstanceAttributes() != null) { retval.addAll(current.getInstanceAttributes()); } return retval; } /** * Gets all instance attributes including those instance attributes belonging to the <code>classifier</code> and any * inherited ones. * * @param classifier the ClassifierFacade from which to retrieve the instance attributes. * @return the list of all instance attributes. */ static List getAllInstanceAttributes(ClassifierFacade classifier) { final String methodName = "EJBMetafacadeUtils.getAllInstanceAttributes"; ExceptionUtils.checkNull(methodName, "classifer", classifier); List retval = getInheritedInstanceAttributes(classifier); retval.addAll(classifier.getInstanceAttributes()); return retval; } /** * Gets all environment entries for the specified <code>classifier</code>. If <code>follow</code> is true, then a * search up the inheritance hierachy will be performed and all super type environment entries will also be * retrieved. * * @param classifier the classifier from which to retrieve the env-entries * @param follow true/false on whether or not to 'follow' the inheritance hierarchy when retrieving the * env-entries. * @return the collection of enviroment entries */ static Collection getEnvironmentEntries( ClassifierFacade classifier, boolean follow) { final String methodName = "EJBMetafacadeUtils.getEnvironmentEntries"; ExceptionUtils.checkNull(methodName, "classifer", classifier); Collection attributes = classifier.getStaticAttributes(); if (follow) { for (classifier = (ClassifierFacade)classifier.getGeneralization(); classifier != null; classifier = (ClassifierFacade)classifier.getGeneralization()) { attributes.addAll(classifier.getStaticAttributes()); } } CollectionUtils.filter(attributes, new Predicate() { public boolean evaluate(Object object) { return ((AttributeFacade)object).hasStereotype(EJB3Profile.STEREOTYPE_ENV_ENTRY); } }); return attributes; } /** * Gets all constants for the specified <code>classifier</code>. If <code>follow</code> is true, then a search up * the inheritance hierachy will be performed and all super type constants will also be retrieved. * * @param classifier the classifier from which to retrieve the constants * @param follow true/false on whether or not to 'follow' the inheritance hierarchy when retrieving the * constants. * @return the collection of enviroment entries */ static Collection getConstants( ClassifierFacade classifier, boolean follow) { final String methodName = "EJBMetafacadeUtils.getEnvironmentEntries"; ExceptionUtils.checkNull(methodName, "classifer", classifier); Collection attributes = classifier.getStaticAttributes(); if (follow) { for (classifier = (ClassifierFacade)classifier.getGeneralization(); classifier != null; classifier = (ClassifierFacade)classifier.getGeneralization()) { attributes.addAll(classifier.getStaticAttributes()); } } CollectionUtils.filter(attributes, new Predicate() { public boolean evaluate(Object object) { return !((AttributeFacade)object).hasStereotype(EJB3Profile.STEREOTYPE_ENV_ENTRY); } }); return attributes; } /** * Returns true/false based on whether or not synthetic or auto generated create methods should be allowed. * * @param classifier the entity or session EJB. * @return true/false */ static boolean allowSyntheticCreateMethod(ClassifierFacade classifier) { final String methodName = "EJBMetafacadeUtils.allowSyntheticCreateMethod"; ExceptionUtils.checkNull(methodName, "classifer", classifier); return !classifier.isAbstract() && classifier.findTaggedValue( EJB3Profile.TAGGEDVALUE_EJB_NO_SYNTHETIC_CREATE_METHOD) == null; } /** * Creates a fully qualified name from the given <code>packageName</code>, * <code>name</code>, and <code>suffix</code>. * * @param packageName the name of the model element package. * @param name the name of the model element. * @param suffix the suffix to append. * @return the new fully qualified name. */ static String getFullyQualifiedName( String packageName, String name, String suffix) { StringBuffer fullyQualifiedName = new StringBuffer(StringUtils.trimToEmpty(packageName)); if (StringUtils.isNotBlank(packageName)) { fullyQualifiedName.append('.'); } fullyQualifiedName.append(StringUtils.trimToEmpty(name)); fullyQualifiedName.append(StringUtils.trimToEmpty(suffix)); return fullyQualifiedName.toString(); } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3SessionOperationFacadeLogicImpl.java Index: EJB3SessionOperationFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3SessionOperationFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3SessionOperationFacade */ public class EJB3SessionOperationFacadeLogicImpl extends EJB3SessionOperationFacadeLogic { public EJB3SessionOperationFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3SessionOperationFacade#getViewType() */ protected java.lang.String handleGetViewType() { // TODO: put your implementation here. return null; } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3AssociationEndFacadeLogicImpl.java Index: EJB3AssociationEndFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; 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.TaggedValueFacade; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; /** * <p/> * Represents an EJB association end. </p> * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade */ public class EJB3AssociationEndFacadeLogicImpl extends EJB3AssociationEndFacadeLogic { /** * Represents the EJB3 <code>ALL</code> cascade option and fully qualified representation. */ private static final String ENTITY_CASCADE_ALL = "ALL"; private static final String ENTITY_CASCADE_ALL_FQN = "javax.persistence.CascadeType.ALL"; /** * Represents the EJB3 <code>PERSIST</code> cascade option. */ private static final String ENTITY_CASCADE_PERSIST = "PERSIST"; private static final String ENTITY_CASCADE_PERSIST_FQN = "javax.persistence.CascadeType.PERSIST"; /** * Represents the EJB3 <code>MERGE</code> cascade option. */ private static final String ENTITY_CASCADE_MERGE = "MERGE"; private static final String ENTITY_CASCADE_MERGE_FQN = "javax.persistence.CascadeType.MERGE"; /** * Represents the EJB3 <code>REMOVE</code> cascade option. */ private static final String ENTITY_CASCADE_REMOVE = "REMOVE"; private static final String ENTITY_CASCADE_REMOVE_FQN = "javax.persistence.CascadeType.REMOVE"; /** * Represents the EJB3 <code>REFRESH</code> cascade option. */ private static final String ENTITY_CASCADE_REFRESH = "REFRESH"; private static final String ENTITY_CASCADE_REFRESH_FQN = "javax.persistence.CascadeType.REFRESH"; /** * Represents the value used to represents NO cascade option. */ private static final String ENTITY_CASCADE_NONE = "NONE"; /** * Stores the cascade map of fully qualified cascade types */ private static final Hashtable cascadeTable = new Hashtable(); static { cascadeTable.put(ENTITY_CASCADE_ALL, ENTITY_CASCADE_ALL_FQN); cascadeTable.put(ENTITY_CASCADE_PERSIST, ENTITY_CASCADE_PERSIST_FQN); cascadeTable.put(ENTITY_CASCADE_MERGE, ENTITY_CASCADE_MERGE_FQN); cascadeTable.put(ENTITY_CASCADE_REMOVE, ENTITY_CASCADE_REMOVE_FQN); cascadeTable.put(ENTITY_CASCADE_REFRESH, ENTITY_CASCADE_REFRESH_FQN); } // ---------------- constructor ------------------------------- public EJB3AssociationEndFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // --------------- methods --------------------- /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade#getRelationType() */ protected java.lang.String handleGetRelationType() { String targetType; if (this.isMany2Many() || this.isOne2Many()) { targetType = "java.util.Collection"; } else { targetType = this.getOtherEnd().getType().getFullyQualifiedName(); } return targetType; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade#getFetchType() * * This method is always called on the target association end. * If a fetch type tagged value is not found on the target end, then compare the association * relationship from the source end to indicate the default fetch types. * <ul> * <li>One-2-Many and Many-2-Many defaults to LAZY loading</li> * <li>Many-2-One and One-2-One default to EAGER loading</li> * </ul> */ protected String handleGetFetchType() { String fetchType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_PERSISTENCE_FETCH_TYPE); if (StringUtils.isBlank(fetchType)) { if (this.getOtherEnd().isOne2Many() || this.getOtherEnd().isMany2Many()) { fetchType = EJB3Profile.FETCHTYPE_LAZY; } else { fetchType = EJB3Profile.FETCHTYPE_EAGER; } } return fetchType; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsEager() */ protected boolean handleIsEager() { boolean isEager = false; if (StringUtils.isNotBlank(this.getFetchType())) { if (this.getFetchType().equalsIgnoreCase(EJB3Profile.FETCHTYPE_EAGER)) { isEager = true; } } return isEager; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsLazy() */ protected boolean handleIsLazy() { boolean isLazy = false; if (StringUtils.isNotBlank(this.getFetchType())) { if (this.getFetchType().equalsIgnoreCase(EJB3Profile.FETCHTYPE_LAZY)) { isLazy = true; } } return isLazy; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsOwning() */ protected boolean handleIsOwning() { boolean owning = false; if (this.isAggregation() || this.isComposition()) { owning = true; } return owning; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleIsOptional() */ protected boolean handleIsOptional() { boolean optional = true; String optionalString = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_PERSISTENCE_OPTIONAL); if (StringUtils.isBlank(optionalString)) { optionalString = String.valueOf(this.getConfiguredProperty(EJB3Globals.ENTITY_DEFAULT_ASSOCIATION_OPTIONAL)); } optional = Boolean.valueOf(optionalString).booleanValue(); return optional; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetOrderByClause() */ protected String handleGetOrderByClause() { return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_PERSISTENCE_ORDERBY); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetColumnDefinition() */ protected String handleGetColumnDefinition() { return (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_PERSISTENCE_COLUMN_DEFINITION); } /** * Returns true if the tagged name exists for this association end. * * @param name The tagged name to lookup. * @return boolean True if the tagged name exists. False otherwise. * * @see org.andromda.cartridges.ejb3.metafacades. * EJB3AssociationEndFacadeLogic#handleHasTaggedValue(java.lang.String) */ protected boolean handleHasTaggedValue(String name) { boolean exists = false; if (StringUtils.isNotBlank(name)) { // trim to remove leading/trailing spaces name = StringUtils.trimToEmpty(name); // loop over tagged values and matche the argument tagged value name for (final Iterator iter = this.getTaggedValues().iterator(); iter.hasNext(); ) { final TaggedValueFacade taggedValue = (TaggedValueFacade)iter.next(); // return with true on the first match found if (name.equals(taggedValue.getName())) { exists = true; break; } } } return exists; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetCascadeType() */ protected String handleGetCascadeType() { String cascade = null; final Collection taggedValues = this.findTaggedValues(EJB3Profile.TAGGEDVALUE_PERSISTENCE_CASCADE_TYPE); if (taggedValues != null && !taggedValues.isEmpty()) { StringBuffer buf = null; for (final Iterator iter = taggedValues.iterator(); iter.hasNext(); ) { if (buf == null) { buf = new StringBuffer(); } else { buf.append(", "); } final String value = (String)iter.next(); if (StringUtils.isNotBlank(value)) { buf.append(cascadeTable.get(value)); } } cascade = buf.toString(); } else if (this.isChild()) { cascade = (String)cascadeTable.get(ENTITY_CASCADE_REMOVE); if (this.getOtherEnd() != null) { if (this.getOtherEnd().isComposition()) { if (StringUtils.isBlank(this.getCompositionCascadeType())) { if (this.getType() instanceof EJB3EntityFacade) { EJB3EntityFacade entity = (EJB3EntityFacade)this.getType(); cascade = (entity.getDefaultCascadeType().equalsIgnoreCase(ENTITY_CASCADE_NONE) ? null : (String)cascadeTable.get(entity.getDefaultCascadeType())); } } else { cascade = (this.getCompositionCascadeType().equalsIgnoreCase(ENTITY_CASCADE_NONE) ? null : (String)cascadeTable.get(this.getCompositionCascadeType())); } } else if (this.getOtherEnd().isAggregation()) { if (StringUtils.isBlank(this.getAggregationCascadeType())) { if (this.getType() instanceof EJB3EntityFacade) { EJB3EntityFacade entity = (EJB3EntityFacade)this.getType(); cascade = (entity.getDefaultCascadeType().equalsIgnoreCase(ENTITY_CASCADE_NONE) ? null : (String)cascadeTable.get(entity.getDefaultCascadeType())); } } else { cascade = (this.getAggregationCascadeType().equalsIgnoreCase(ENTITY_CASCADE_NONE) ? null : (String)cascadeTable.get(this.getAggregationCascadeType())); } } } } else if (this.isComposition()) { /** * On the composite side of the relationship, always enforce no cascade delete * property indicating no cascadable propogation - overriding a default cascade * value */ cascade = null; } else if (this.isAggregation()) { /** * On the aggregation side of the relationship, always enforce no cascade delete * property indicating no cascadable propogation - overriding a default cascade * value */ cascade = null; } return cascade; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetCompositionCascadeType() */ protected String handleGetCompositionCascadeType() { return StringUtils.trimToEmpty( ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.ENTITY_DEFAULT_COMPOSITE_CASCADE))); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacadeLogic#handleGetAggregationCascadeType() */ protected String handleGetAggregationCascadeType() { return StringUtils.trimToEmpty( ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.ENTITY_DEFAULT_AGGREGATION_CASCADE))); } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3OperationFacadeLogicImpl.java Index: EJB3OperationFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import org.andromda.cartridges.ejb3.EJB3Globals; import org.andromda.cartridges.ejb3.EJB3Profile; import org.apache.commons.lang.ObjectUtils; import org.apache.commons.lang.StringUtils; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade */ public class EJB3OperationFacadeLogicImpl extends EJB3OperationFacadeLogic { // ---------------- constructor ------------------------------- public EJB3OperationFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // ---------------- methods ------------------------------- /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade#getTransactionType() */ protected java.lang.String handleGetTransactionType() { String transType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_TYPE, true); if (StringUtils.isNotBlank(transType)) { if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_MANDATORY)) { transType = "MANDATORY"; } else if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_NEVER)) { transType = "NEVER"; } else if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_NOT_SUPPORTED)) { transType = "NOT_SUPPORTED"; } else if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_REQUIRED)) { transType = "REQUIRED"; } else if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_REQUIRES_NEW)) { transType = "REQUIRES_NEW"; } else if (StringUtils.equalsIgnoreCase(transType, EJB3Globals.TRANSACTION_TYPE_SUPPORTS)) { transType = "SUPPORTS"; } } else { transType = StringUtils.trimToEmpty( ObjectUtils.toString(this.getConfiguredProperty(EJB3Globals.TRANSACTION_TYPE))); } return transType; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade#isBusinessOperation() */ protected boolean handleIsBusinessOperation() { return !this.hasStereotype(EJB3Profile.STEREOTYPE_CREATE_METHOD) && !this.hasStereotype(EJB3Profile.STEREOTYPE_FINDER_METHOD) && !this.hasStereotype(EJB3Profile.STEREOTYPE_SELECT_METHOD); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade#isSelectMethod() */ protected boolean handleIsSelectMethod() { return this.hasStereotype(EJB3Profile.STEREOTYPE_SELECT_METHOD); } } 1.1 cartridges/andromda-ejb3/src/main/java/org/andromda/cartridges/ejb3/metafacades/EJB3EntityFacadeLogicImpl.java Index: EJB3EntityFacadeLogicImpl.java =================================================================== package org.andromda.cartridges.ejb3.metafacades; import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.Iterator; import org.andromda.cartridges.ejb3.EJB3Globals; import org.andromda.cartridges.ejb3.EJB3Profile; import org.andromda.cartridges.ejb3.metafacades.EJB3AssociationEndFacade; import org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade; import org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade; import org.andromda.core.common.ExceptionRecorder; import org.andromda.metafacades.uml.AttributeFacade; import org.andromda.metafacades.uml.ClassifierFacade; import org.andromda.metafacades.uml.DependencyFacade; import org.andromda.metafacades.uml.MetafacadeUtils; import org.andromda.metafacades.uml.OperationFacade; import org.andromda.metafacades.uml.TypeMappings; import org.andromda.metafacades.uml.UMLMetafacadeProperties; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.Predicate; import org.apache.commons.lang.BooleanUtils; import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.math.NumberUtils; /** * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade. * * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade */ public class EJB3EntityFacadeLogicImpl extends EJB3EntityFacadeLogic { /** * The default entity access type */ public static final String ENTITY_ACCESS_TYPE = "entityAccessType"; /** * The default entity association cascade property */ public static final String ENTITY_DEFAULT_CASCADE = "entityDefaultCascade"; /** * Stores the default entity inheritance strategy */ private static final String ENTITY_INHERITANCE_STRATEGY = "entityInheritanceStrategy"; /** * Stores the default entity discriminator type used in the inheritance annotation */ private static final String ENTITY_DISCRIMINATOR_TYPE = "entityDiscriminatorType"; /** * Stores the default entity discriminator column name used in the DiscriminatorColumn annotation */ private static final String ENTITY_DISCRIMINATOR_COLUMN_NAME = "entityDiscriminatorColumnName"; /** * Value for one table per root class */ private static final String INHERITANCE_STRATEGY_TABLE_PER_CLASS = "TABLE_PER_CLASS"; /** * Value for a single table for the hierarchy */ private static final String INHERITANCE_STRATEGY_SINGLE_TABLE = "SINGLE_TABLE"; /** * Value for joined subclass */ private static final String INHERITANCE_STRATEGY_JOINED_SUBLCASS = "JOINED"; /** * Stores the valid inheritance strategies */ private static final Collection inheritanceStrategies = new ArrayList(); static { inheritanceStrategies.add(INHERITANCE_STRATEGY_TABLE_PER_CLASS); inheritanceStrategies.add(INHERITANCE_STRATEGY_SINGLE_TABLE); inheritanceStrategies.add(INHERITANCE_STRATEGY_JOINED_SUBLCASS); } /** * Value for string based discriminator type */ public static final String DISCRIMINATORTYPE_STRING = "STRING"; /** * Value for char based discriminator type */ public static final String DISCRIMINATORTYPE_CHAR = "CHAR"; /** * Value for integer based discriminator type */ public static final String DISCRIMINATORTYPE_INTEGER = "INTEGER"; /** * Stores the valid discriminator types */ private static final Collection discriminatorTypes = new ArrayList(); static { discriminatorTypes.add(DISCRIMINATORTYPE_STRING); discriminatorTypes.add(DISCRIMINATORTYPE_CHAR); discriminatorTypes.add(DISCRIMINATORTYPE_INTEGER); } /** * The property which stores the pattern defining the entity name. */ public static final String ENTITY_NAME_PATTERN = "entityNamePattern"; /** * The property which stores the pattern defining the entity implementation name. */ public static final String ENTITY_IMPLEMENTATION_NAME_PATTERN = "entityImplementationNamePattern"; /** * The property that stores the pattern defining the entity listener class name. */ public static final String ENTITY_LISTENER_NAME_PATTERN = "entityListenerNamePattern"; /** * The property that stores the pattern defining the entity embeddable super class name. */ public static final String ENTITY_EMBEDDABLE_NAME_PATTERN = "entityEmbeddableNamePattern"; // ---------------- constructor ------------------------------- public EJB3EntityFacadeLogicImpl (Object metaObject, String context) { super (metaObject, context); } // --------------- methods --------------------- public Collection handleGetIdentifiers() { Collection identifiers = new ArrayList(); for (final Iterator iter = this.getSourceDependencies().iterator(); iter.hasNext();) { final DependencyFacade dep = (DependencyFacade)iter.next(); if (dep.hasStereotype(EJB3Profile.STEREOTYPE_IDENTIFIER)) { identifiers = ((ClassifierFacade)dep.getTargetElement()).getInstanceAttributes(); MetafacadeUtils.filterByStereotype(identifiers, EJB3Profile.STEREOTYPE_IDENTIFIER); return identifiers; } } // No PK dependency found - try a PK attribute if (super.getIdentifiers() != null && !super.getIdentifiers().isEmpty()) { AttributeFacade attr = (AttributeFacade)super.getIdentifiers().iterator().next(); identifiers.add(attr); return identifiers; } // Still nothing found - recurse up the inheritance tree EJB3EntityFacade decorator = (EJB3EntityFacade)this.getGeneralization(); return decorator.getIdentifiers(); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#isSyntheticCreateMethodAllowed() */ protected boolean handleIsSyntheticCreateMethodAllowed() { return EJB3MetafacadeUtils.allowSyntheticCreateMethod(this); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getAllEntityRelations() */ protected java.util.Collection handleGetAllEntityRelations() { // Only concrete entities may have EJB relations. Return // an empty collection for everything else if (this.isAbstract()) { return Collections.EMPTY_LIST; } Collection result = new ArrayList(); result.addAll(getEntityRelations()); ClassifierFacade classifier = (ClassifierFacade)this.getGeneralization(); while (classifier != null && classifier instanceof EJB3EntityFacade && classifier.isAbstract()) { EJB3EntityFacade entity = (EJB3EntityFacade)classifier; result.addAll(entity.getEntityRelations()); classifier = (ClassifierFacade)classifier.getGeneralization(); } return result; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getJndiName() */ protected java.lang.String handleGetJndiName() { StringBuffer jndiName = new StringBuffer(); String jndiNamePrefix = StringUtils.trimToEmpty(this.getJndiNamePrefix()); if (StringUtils.isNotEmpty(jndiNamePrefix)) { jndiName.append(jndiNamePrefix); jndiName.append("/"); } jndiName.append("ejb/"); jndiName.append(this.getFullyQualifiedName()); return jndiName.toString(); } /** * Gets the <code>jndiNamePrefix</code> for this EJB. * * @return the EJB Jndi name prefix. */ protected String getJndiNamePrefix() { String prefix = null; if (this.isConfiguredProperty(EJB3Globals.JNDI_NAME_PREFIX)) { prefix = (String)this.getConfiguredProperty(EJB3Globals.JNDI_NAME_PREFIX); } return prefix; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getViewType() */ protected java.lang.String handleGetViewType() { return EJB3MetafacadeUtils.getViewType(this); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getAllInstanceAttributes() */ protected java.util.List handleGetAllInstanceAttributes() { return EJB3MetafacadeUtils.getAllInstanceAttributes(this); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getInheritedInstanceAttributes() */ protected java.util.List handleGetInheritedInstanceAttributes() { return EJB3MetafacadeUtils.getInheritedInstanceAttributes(this); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getHomeInterfaceName() */ protected java.lang.String handleGetHomeInterfaceName() { return EJB3MetafacadeUtils.getHomeInterfaceName(this); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getValueDependencies() * * NOTE: This is not required since ValueObject no longer exist and replaced with POJOs */ protected java.util.Collection handleGetValueDependencies() { Collection dependencies = super.getSourceDependencies(); CollectionUtils.filter(dependencies, new Predicate() { public boolean evaluate(Object object) { boolean isValueRef = false; if (object instanceof DependencyFacade) { DependencyFacade dep = (DependencyFacade)object; isValueRef = dep.getStereotypeNames().contains(EJB3Profile.STEREOTYPE_VALUE_REF) && dep.getTargetElement().hasExactStereotype(EJB3Profile.STEREOTYPE_VALUE_OBJECT); } return isValueRef; } }); return dependencies; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getEntityRelations() */ protected java.util.Collection handleGetEntityRelations() { Collection result = new ArrayList(); for (final Iterator endIt = this.getAssociationEnds().iterator(); endIt.hasNext();) { final EJB3AssociationEndFacade associationEnd = (EJB3AssociationEndFacade)endIt.next(); ClassifierFacade target = associationEnd.getOtherEnd().getType(); if (target instanceof EJB3EntityFacade && associationEnd.getOtherEnd().isNavigable()) { // Check the integrity constraint Object value = associationEnd.getOtherEnd().getAssociation().findTaggedValue( EJB3Profile.TAGGEDVALUE_GENERATE_CMR); String generateCmr = value == null ? null : value.toString(); if (target.isAbstract() && !"false".equalsIgnoreCase(generateCmr)) { throw new IllegalStateException("Relation '" + associationEnd.getAssociation().getName() + "' has the abstract target '" + target.getName() + "'. Abstract targets are not allowed in EJB."); } result.add(associationEnd); } } return result; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getTransactionType() */ protected java.lang.String handleGetTransactionType() { String transactionType = (String)this.findTaggedValue(EJB3Profile.TAGGEDVALUE_EJB_TRANSACTION_TYPE); if (StringUtils.isBlank(transactionType)) { transactionType = transactionType = String.valueOf(this.getConfiguredProperty(EJB3Globals.TRANSACTION_TYPE)); } return transactionType; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getCreateMethods(boolean) */ protected java.util.Collection handleGetCreateMethods(boolean follow) { return EJB3MetafacadeUtils.getCreateMethods(this, follow); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getSelectMethods(boolean) */ protected java.util.Collection handleGetSelectMethods(boolean follow) { Collection retval = new ArrayList(); EJB3EntityFacade entity = null; do { Collection ops = this.getOperations(); for (final Iterator i = ops.iterator(); i.hasNext();) { final OperationFacade op = (OperationFacade)i.next(); if (op.hasStereotype(EJB3Profile.STEREOTYPE_SELECT_METHOD)) { retval.add(op); } } if (follow) { entity = (EJB3EntityFacade)this.getGeneralization(); } else { break; } } while (entity != null); return retval; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getEnvironmentEntries(boolean) */ protected java.util.Collection handleGetEnvironmentEntries(boolean follow) { return EJB3MetafacadeUtils.getEnvironmentEntries(this, follow); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getConstants(boolean) */ protected java.util.Collection handleGetConstants(boolean follow) { return EJB3MetafacadeUtils.getConstants(this, follow); } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#isOperationPresent(java.lang.String) */ protected boolean handleIsOperationPresent(java.lang.String op) { Collection collOps = this.getOperations(); for (final Iterator it = collOps.iterator(); it.hasNext();) { final OperationFacade operation = (OperationFacade)it.next(); if (operation.getName().equalsIgnoreCase(op)) { return true; } } return false; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#isAttributePresent(java.lang.String) */ protected boolean handleIsAttributePresent(java.lang.String att) { Collection collAttrib = this.getAttributes(true); for (final Iterator it = collAttrib.iterator(); it.hasNext();) { final AttributeFacade attr = (AttributeFacade)it.next(); if (attr.getName().equalsIgnoreCase(att)) { return true; } } return false; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#isIdentifierPresent(java.lang.String) */ protected boolean handleIsIdentifierPresent(java.lang.String id) { Collection collIdentifier = this.getIdentifiers(true); for (final Iterator it = collIdentifier.iterator(); it.hasNext();) { final AttributeFacade attr = (AttributeFacade)it.next(); if (attr.getName().equalsIgnoreCase(id)) { return true; } } return false; } /** * @see org.andromda.cartridges.ejb3.metafacades.EJB3EntityFacade#getSqlType() */ protected java.lang.String handleGetSqlType() { String mpSql = this.getMappingsProperty(UMLMetafacadeProperties.SQL_MAPPINGS_URI).getMappings().getName(); if (mpSql.startsWith("Oracle")) { mpSql = "ORACLE"; } return mpSql; } /** * Gets a Mappings instance from a property registered under the given <code>propertyName</code>. * * @param propertyName the property name to register under. * @return the Mappings instance. */ private TypeMappings getMappingsProperty(final String propertyName) { Object property = this.getConfiguredProperty(propertyName); TypeMappings mappings = null; String uri = null; if (property instanceof String) { uri = (String)property; try { mappings = TypeMappings.getInstance(uri); this.setProperty(propertyName, mappings); } catch (Throwable th) { String errMsg = "Error getting '" + propertyName + "' --> '" + uri + "'"; logger.error(errMsg); // don't throw the exception ExceptionRecorder.instance().record(errMsg, th); } } else { mappings = (TypeMappings)property; } return mappings; } /** * @see org.andromda.metafacades.uml.EntityFacade#getBusinessOperations() */ public Collection getBusinessOperations() { Collection operations = super.getBusinessOperations(); CollectionUtils.filter(operations, new Predicate() { public boolean evaluate(Object object) { boolean businessOperation = false; if (EJB3OperationFacade.class.isAssignableFrom(object .getClass())) { businessOperation = ((EJB3OperationFacade) object) .isBusinessOperation(); } return businessOperation; } }); return operations; } /** * @see org.andromda.metafacades.uml.EntityFacade#getEntityListenerName() */ protected String handleGetEntityListenerName() { String entityListenerPattern = (String)this.getConfiguredProperty(ENTITY_LISTENER_NAME_PATTERN); return MessageFormat.format( entityListenerPattern, new Object[] {StringUtils.trimToEmpty(this.getName())}); } /** * @see org.andromda.metafacades.uml.EntityFacade#getEntityEmbeddableName() */ protected String handleGetEntityEmbeddableName() { String embeddableSuperclassName = (String)this.getConfiguredProperty(ENTITY_EMBEDDABLE_NAME_PATTERN); return MessageFormat.format( embeddableSuperclassName, new Object[] {StringUtils.trimToEmpty(this.getName())}); } ... [truncated message content] |