View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.Collection;
4   import org.andromda.metafacades.uml.AssociationEndFacade;
5   import org.andromda.metafacades.uml.Entity;
6   import org.andromda.metafacades.uml.EntityMetafacadeUtils;
7   import org.andromda.metafacades.uml.UMLMetafacadeProperties;
8   import org.andromda.metafacades.uml.UMLProfile;
9   import org.apache.commons.lang.ObjectUtils;
10  import org.apache.commons.lang.StringUtils;
11  
12  /**
13   * MetafacadeLogic implementation for org.andromda.metafacades.uml.EntityAssociationFacade.
14   *
15   * @see org.andromda.metafacades.uml.EntityAssociation
16   * @author Bob Fields
17   */
18  public class EntityAssociationLogicImpl
19      extends EntityAssociationLogic
20  {
21      private static final long serialVersionUID = -908730666308510791L;
22  
23      /**
24       * @param metaObject
25       * @param context
26       */
27      public EntityAssociationLogicImpl(
28          Object metaObject,
29          String context)
30      {
31          super(metaObject, context);
32      }
33  
34      /**
35       * @see org.andromda.metafacades.uml.EntityAssociation#getTableName()
36       */
37      @Override
38      public String handleGetTableName()
39      {
40          String tableName = null;
41          final Collection<AssociationEndFacade> ends = this.getAssociationEnds();
42          if (ends != null && !ends.isEmpty())
43          {
44              final AssociationEndFacade end = ends.iterator().next();
45              // prevent ClassCastException if the association isn't an
46              // Entity
47              if (Entity.class.isAssignableFrom(end.getType().getClass()))
48              {
49                  final String prefixProperty = UMLMetafacadeProperties.TABLE_NAME_PREFIX;
50                  final String tableNamePrefix =
51                      this.isConfiguredProperty(prefixProperty)
52                      ? ObjectUtils.toString(this.getConfiguredProperty(prefixProperty)) : null;
53                  tableName =
54                      EntityMetafacadeUtils.getSqlNameFromTaggedValue(
55                          tableNamePrefix,
56                          this,
57                          UMLProfile.TAGGEDVALUE_PERSISTENCE_TABLE,
58                          ((Entity)end.getType()).getMaxSqlNameLength(),
59                          this.getConfiguredProperty(UMLMetafacadeProperties.SQL_NAME_SEPARATOR),
60                          this.getConfiguredProperty(UMLMetafacadeProperties.SHORTEN_SQL_NAMES_METHOD));
61              }
62          }
63          return tableName;
64      }
65  
66      /**
67       * @see org.andromda.metafacades.uml.EntityAssociation#getSchema()
68       */
69      @Override
70      protected String handleGetSchema()
71      {
72          String schemaName = ObjectUtils.toString(this.findTaggedValue(UMLProfile.TAGGEDVALUE_PERSISTENCE_SCHEMA));
73          if (StringUtils.isBlank(schemaName))
74          {
75              schemaName = ObjectUtils.toString(this.getConfiguredProperty(UMLMetafacadeProperties.SCHEMA_NAME));
76          }
77          return schemaName;
78      }
79  
80      /**
81       *  @see org.andromda.metafacades.uml.EntityAssociation#isEntityAssociation()
82       */
83      @Override
84      protected boolean handleIsEntityAssociation()
85      {
86          boolean isEntityAssociation = false;
87          if (getAssociationEndA().isAssociationEndFacadeMetaType())
88          {
89              isEntityAssociation = true;
90          }
91          return isEntityAssociation;
92      }
93  }