View Javadoc
1   package org.andromda.metafacades.emf.uml22;
2   
3   import java.util.List;
4   import org.andromda.core.translation.Expression;
5   import org.andromda.core.translation.ExpressionTranslator;
6   import org.andromda.metafacades.uml.UMLMetafacadeUtils;
7   import org.andromda.translation.ocl.ExpressionKinds;
8   import org.eclipse.uml2.uml.Constraint;
9   import org.eclipse.uml2.uml.Element;
10  
11  /**
12   * MetafacadeLogic implementation for
13   * org.andromda.metafacades.uml.ConstraintFacade.
14   *
15   * @see org.andromda.metafacades.uml.ConstraintFacade
16   */
17  public class ConstraintFacadeLogicImpl
18      extends ConstraintFacadeLogic
19  {
20      private static final long serialVersionUID = -8431289709042079686L;
21  
22      /**
23       * @param metaObject
24       * @param context
25       */
26      public ConstraintFacadeLogicImpl(
27          final Constraint metaObject,
28          final String context)
29      {
30          super(metaObject, context);
31      }
32  
33      /**
34       * @see org.andromda.metafacades.uml.ConstraintFacade#getBody()
35       */
36      @Override
37      protected String handleGetBody()
38      {
39          String body = null;
40          if (this.metaObject.getSpecification() != null)
41          {
42              body = this.metaObject.getSpecification().stringValue();
43          }
44          return body;
45      }
46  
47      /**
48       * @see org.andromda.metafacades.uml.ConstraintFacade#isInvariant()
49       */
50      @Override
51      protected boolean handleIsInvariant()
52      {
53          return UMLMetafacadeUtils.isConstraintKind(
54              this.getBody(),
55              ExpressionKinds.INV);
56      }
57  
58      /**
59       * @see org.andromda.metafacades.uml.ConstraintFacade#isPreCondition()
60       */
61      @Override
62      protected boolean handleIsPreCondition()
63      {
64          return UMLMetafacadeUtils.isConstraintKind(
65              this.getBody(),
66              ExpressionKinds.PRE);
67      }
68  
69      /**
70       * @see org.andromda.metafacades.uml.ConstraintFacade#isPostCondition()
71       */
72      @Override
73      protected boolean handleIsPostCondition()
74      {
75          return UMLMetafacadeUtils.isConstraintKind(
76              this.getBody(),
77              ExpressionKinds.POST);
78      }
79  
80      /**
81       * @see org.andromda.metafacades.uml.ConstraintFacade#isDefinition()
82       */
83      @Override
84      protected boolean handleIsDefinition()
85      {
86          return UMLMetafacadeUtils.isConstraintKind(
87              this.getBody(),
88              ExpressionKinds.DEF);
89      }
90  
91      /**
92       * @see org.andromda.metafacades.uml.ConstraintFacade#isBodyExpression()
93       */
94      @Override
95      protected boolean handleIsBodyExpression()
96      {
97          return UMLMetafacadeUtils.isConstraintKind(
98              this.getBody(),
99              ExpressionKinds.BODY);
100     }
101 
102     /**
103      * @see org.andromda.metafacades.uml.ConstraintFacade#getTranslation(String)
104      */
105     @Override
106     protected String handleGetTranslation(final String language)
107     {
108         final Expression expression =
109             ExpressionTranslator.instance().translate(
110                 language,
111                 this.getBody(),
112                 this.getContextElement());
113         return expression == null ? null : expression.getTranslatedExpression();
114     }
115 
116     /**
117      * @see org.andromda.metafacades.uml.ConstraintFacade#getContextElement()
118      */
119     @Override
120     protected Element handleGetContextElement()
121     {
122         Element element = null;
123         final List<Element> elements = this.metaObject.getConstrainedElements();
124         if (elements != null && !elements.isEmpty())
125         {
126             element = elements.get(0);
127         }
128         return element;
129     }
130 }