View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.Collection;
4   import java.util.Iterator;
5   import java.util.List;
6   import org.andromda.metafacades.uml.AssociationEndFacade;
7   import org.andromda.metafacades.uml.MetafacadeUtils;
8   import org.andromda.metafacades.uml.UMLMetafacadeProperties;
9   import org.apache.commons.collections.CollectionUtils;
10  import org.apache.commons.lang.StringUtils;
11  import org.eclipse.uml2.uml.Association;
12  import org.eclipse.uml2.uml.AssociationClass;
13  
14  /**
15   * MetafacadeLogic implementation for
16   * org.andromda.metafacades.uml.AssociationFacade.
17   *
18   * @see org.andromda.metafacades.uml.AssociationFacade
19   */
20  public class AssociationFacadeLogicImpl
21      extends AssociationFacadeLogic
22  {
23      private static final long serialVersionUID = 34L;
24      /**
25       * @param metaObject
26       * @param context
27       */
28      public AssociationFacadeLogicImpl(
29          final Association metaObject,
30          final String context)
31      {
32          super(metaObject, context);
33      }
34  
35      /**
36       * @see org.andromda.metafacades.uml.AssociationFacade#getRelationName()
37       */
38      @Override
39      protected String handleGetRelationName()
40      {
41          final Collection<AssociationEndFacade> ends = this.getAssociationEnds();
42          final Iterator<AssociationEndFacade> endIt = ends.iterator();
43          final AssociationEndFacade firstEnd = endIt.next();
44          final AssociationEndFacade secondEnd = endIt.next();
45          return MetafacadeUtils.toRelationName(
46              firstEnd==null ? "" :firstEnd.getName(),
47              secondEnd==null ? "" : secondEnd.getName(),
48              String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR)));
49      }
50  
51      /**
52       * Overridden: A name may not have a name, which
53       * is problematic for getSqlName (for an EntityAssociation).
54       * We use the relation name as default
55       * @see org.andromda.metafacades.emf.uml22.ModelElementFacadeLogic#handleGetName()
56       */
57      @Override
58      public String handleGetName()
59      {
60          String name = super.handleGetName();
61  
62          // if the name isn't defined, use the relation name
63          if (StringUtils.isBlank(name))
64          {
65              name = this.getRelationName();
66          }
67          return name;
68      }
69      /**
70       * @see org.andromda.metafacades.uml.AssociationFacade#isMany2Many()
71       */
72      @Override
73      protected boolean handleIsMany2Many()
74      {
75          return (this.getAssociationEnds().iterator().next()).isMany2Many();
76      }
77  
78      /**
79       * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEnds()
80       */
81      @Override
82      protected List<AssociationEndFacade> handleGetAssociationEnds()
83      {
84          return (List)CollectionUtils.collect(
85              this.metaObject.getMemberEnds(),
86              UmlUtilities.ELEMENT_TRANSFORMER);
87      }
88  
89      /**
90       * @see org.andromda.metafacades.uml.AssociationFacade#isAssociationClass()
91       */
92      @Override
93      protected boolean handleIsAssociationClass()
94      {
95          // TODO: Test this if it works.
96          return AssociationClass.class.isAssignableFrom(this.metaObject.getClass());
97      }
98  
99      /**
100      * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEndA()
101      */
102     @Override
103     protected AssociationEndFacade handleGetAssociationEndA()
104     {
105         if (!this.getAssociationEnds().isEmpty())
106         {
107             return this.getAssociationEnds().get(0);
108         }
109         return null;
110     }
111 
112     /**
113      * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEndB()
114      */
115     @Override
116     protected AssociationEndFacade handleGetAssociationEndB()
117     {
118         if (this.getAssociationEnds().size()>1)
119         {
120             return this.getAssociationEnds().get(1);
121         }
122         return null;
123     }
124 
125     /**
126      * @see org.andromda.metafacades.uml.AssociationFacade#isAbstract()
127      */
128     @Override
129     protected boolean handleIsAbstract()
130     {
131         return this.metaObject.isAbstract();
132     }
133 
134     /**
135      * @see org.andromda.metafacades.uml.AssociationFacade#isBinary()
136      */
137     @Override
138     protected boolean handleIsBinary()
139     {
140         return this.metaObject.isBinary();
141     }
142 
143     /**
144      * @see org.andromda.metafacades.uml.AssociationFacade#isDerived()
145      */
146     @Override
147     protected boolean handleIsDerived()
148     {
149         return this.metaObject.isDerived();
150     }
151 
152     /**
153      * @see org.andromda.metafacades.uml.AssociationFacade#isLeaf
154      */
155     @Override
156     protected boolean handleIsLeaf()
157     {
158         return this.metaObject.isLeaf();
159     }
160 }