01: package org.andromda.metafacades.uml14;
02:
03: import java.util.Collection;
04:
05: import org.andromda.metafacades.uml.AssociationEndFacade;
06: import org.andromda.metafacades.uml.Entity;
07: import org.andromda.metafacades.uml.EntityMetafacadeUtils;
08: import org.andromda.metafacades.uml.UMLMetafacadeProperties;
09: import org.andromda.metafacades.uml.UMLProfile;
10: import org.apache.commons.lang.ObjectUtils;
11: import org.apache.commons.lang.StringUtils;
12:
13: /**
14: * MetafacadeLogic implementation for org.andromda.metafacades.uml.EntityAssociationFacade.
15: *
16: * @see org.andromda.metafacades.uml.EntityAssociation
17: */
18: public class EntityAssociationLogicImpl extends EntityAssociationLogic {
19: public EntityAssociationLogicImpl(java.lang.Object metaObject,
20: java.lang.String context) {
21: super (metaObject, context);
22: }
23:
24: /**
25: * @see org.andromda.metafacades.uml.EntityAssociation#getTableName()
26: */
27: public String handleGetTableName() {
28: String tableName = null;
29: final Collection ends = this .getAssociationEnds();
30: if (ends != null && !ends.isEmpty()) {
31: final AssociationEndFacade end = (AssociationEndFacade) ends
32: .iterator().next();
33: if (end.isMany2Many()) {
34: // prevent ClassCastException if the association isn't an
35: // Entity
36: if (Entity.class.isAssignableFrom(end.getType()
37: .getClass())) {
38: final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
39: final String tableNamePrefix = this
40: .isConfiguredProperty(prefixProperty) ? ObjectUtils
41: .toString(this
42: .getConfiguredProperty(prefixProperty))
43: : null;
44: tableName = EntityMetafacadeUtils
45: .getSqlNameFromTaggedValue(
46: tableNamePrefix,
47: this ,
48: UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
49: ((Entity) end.getType())
50: .getMaxSqlNameLength(),
51: this
52: .getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR));
53: }
54: }
55: }
56: return tableName;
57: }
58:
59: /**
60: * @see org.andromda.metafacades.uml.EntityAssociation#getSchema()
61: */
62: protected String handleGetSchema() {
63: String schemaName = ObjectUtils
64: .toString(this
65: .findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));
66: if (StringUtils.isBlank(schemaName)) {
67: schemaName = ObjectUtils
68: .toString(this
69: .getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));
70: }
71: return schemaName;
72: }
73:
74: /**
75: * @see org.andromda.metafacades.uml.EntityAssociation#isEntityAssociation()
76: */
77: protected boolean handleIsEntityAssociation() {
78: boolean isEntityAssociation = false;
79: if (getAssociationEndA().isAssociationEndFacadeMetaType()) {
80: isEntityAssociation = true;
81: }
82: return isEntityAssociation;
83: }
84: }
|