View Javadoc
1   package org.andromda.metafacades.uml14;
2   
3   import java.util.List;
4   import org.andromda.metafacades.uml.AssociationEndFacade;
5   import org.andromda.metafacades.uml.MetafacadeUtils;
6   import org.andromda.metafacades.uml.UMLMetafacadeProperties;
7   import org.apache.commons.lang.StringUtils;
8   import org.omg.uml.foundation.core.AssociationClass;
9   import org.omg.uml.foundation.core.AssociationEnd;
10  import org.omg.uml.foundation.core.UmlAssociation;
11  
12  /**
13   * Metaclass facade implementation.
14   * @author Bob Fields
15   */
16  public class AssociationFacadeLogicImpl
17      extends AssociationFacadeLogic
18  {
19      private static final long serialVersionUID = 34L;
20      /**
21       * @param metaObject
22       * @param context
23       */
24      public AssociationFacadeLogicImpl(
25          UmlAssociation metaObject,
26          String context)
27      {
28          super(metaObject, context);
29      }
30  
31      /**
32       * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEnds()
33       */
34      @Override
35      public List<AssociationEnd> handleGetAssociationEnds()
36      {
37          return metaObject.getConnection();
38      }
39  
40      /**
41       * @see org.andromda.metafacades.uml14.ModelElementFacadeLogic#handleGetName()
42       */
43      public String handleGetName()
44      {
45          String name = super.handleGetName();
46  
47          // if the name isn't defined, use the relation name
48          if (StringUtils.isEmpty(name))
49          {
50              name = this.handleGetRelationName();
51          }
52          return name;
53      }
54  
55      /**
56       * @see org.andromda.metafacades.uml.AssociationFacade#getRelationName()
57       */
58      @Override
59      public String handleGetRelationName()
60      {
61          //Avoid StackOverflow with getName calling shieldedElements.
62          /* final String firstEnd = this.handleGetAssociationEndA().getName();
63          String secondEnd = "";
64          if (!(metaObject.getConnection().size()>1))
65          {
66              secondEnd = this.handleGetAssociationEndB().getName();
67          }
68          return MetafacadeUtils.toRelationName(
69              (firstEnd==null ? "" : firstEnd),
70              (secondEnd==null ? "" : secondEnd),
71              String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR))); */
72          /*final AssociationEndFacade firstEnd = (AssociationEndFacade)this.shieldedElement(this.handleGetAssociationEndA());
73          final AssociationEndFacade secondEnd = (AssociationEndFacade)this.shieldedElement(this.handleGetAssociationEndB());
74          return MetafacadeUtils.toRelationName(
75              firstEnd.getName(),
76              secondEnd.getName(),
77              String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR))); */
78          final AssociationEndFacade firstEnd = this.getAssociationEndA();
79          final AssociationEndFacade secondEnd = this.getAssociationEndB();
80          //System.out.println("firstEnd=" + firstEnd + " secondEnd=" + secondEnd);
81          final String nameA = firstEnd==null ? "" :firstEnd.getName();
82          final String nameB = secondEnd==null ? "" : secondEnd.getName();
83          //System.out.println("nameA=" + nameA + " nameB=" + nameB);
84          return MetafacadeUtils.toRelationName(
85                  nameA,
86                  nameB,
87              String.valueOf(this.getConfiguredProperty(UMLMetafacadeProperties.RELATION_NAME_SEPARATOR)));
88      }
89  
90      /**
91       * @see org.andromda.metafacades.uml.AssociationFacade#isMany2Many()
92       */
93      @Override
94      protected boolean handleIsMany2Many()
95      {
96          return (this.getAssociationEnds().iterator().next()).isMany2Many();
97      }
98  
99      /**
100      * @see org.andromda.metafacades.uml.AssociationFacade#isAssociationClass()
101      */
102     @Override
103     protected boolean handleIsAssociationClass()
104     {
105         return AssociationClass.class.isAssignableFrom(this.metaObject.getClass());
106     }
107 
108     /**
109      * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEndA()
110      */
111     @Override
112     protected AssociationEnd handleGetAssociationEndA()
113     {
114         List<AssociationEnd> ends = this.handleGetAssociationEnds();
115         if (!ends.isEmpty())
116         {
117             return ends.get(0);
118         }
119         else
120         {
121             return null;
122         }
123     }
124 
125     /**
126      * @see org.andromda.metafacades.uml.AssociationFacade#getAssociationEndB()
127      */
128     @Override
129     protected AssociationEnd handleGetAssociationEndB()
130     {
131         List<AssociationEnd> ends = this.handleGetAssociationEnds();
132         if (ends.size()>1)
133         {
134             return ends.get(1);
135         }
136         else
137         {
138             return null;
139         }
140     }
141 
142     /**
143      * @see org.andromda.metafacades.uml.AssociationFacade#isAbstract()
144      */
145     @Override
146     protected boolean handleIsAbstract()
147     {
148         return this.metaObject.isAbstract();
149     }
150 
151     /**
152      *
153      * @return true always
154      * @see org.andromda.metafacades.uml.AssociationFacade#isBinary()
155      */
156     @Override
157     protected boolean handleIsBinary()
158     {
159         return true;
160     }
161 
162     /**
163      *
164      * @return false always
165      * @see org.andromda.metafacades.uml.AssociationFacade#isDerived()
166      */
167     @Override
168     protected boolean handleIsDerived()
169     {
170         return false;
171     }
172 
173     /**
174      * @see org.andromda.metafacades.uml.AssociationFacade#isLeaf
175      */
176     @Override
177     protected boolean handleIsLeaf()
178     {
179         return this.metaObject.isLeaf();
180     }
181 }