View Javadoc
1   // license-header java merge-point
2   //
3   // Attention: generated code (by MetafacadeLogic.vsl) - do not modify!
4   //
5   package org.andromda.metafacades.uml14;
6   
7   import java.util.Collection;
8   import org.andromda.core.common.Introspector;
9   import org.andromda.core.metafacade.MetafacadeBase;
10  import org.andromda.core.metafacade.ModelValidationMessage;
11  import org.andromda.metafacades.uml.ModelElementFacade;
12  import org.andromda.metafacades.uml.TemplateArgumentFacade;
13  import org.apache.log4j.Logger;
14  import org.omg.uml.foundation.core.TemplateArgument;
15  
16  /**
17   * Represents the model object 'Template Parameter Substitution'. Relates the actual parameter(s) to
18   * a formal template parameter as part of a template binding.
19   * MetafacadeLogic for TemplateArgumentFacade
20   *
21   * @see TemplateArgumentFacade
22   */
23  public abstract class TemplateArgumentFacadeLogic
24      extends MetafacadeBase
25      implements TemplateArgumentFacade
26  {
27      /**
28       * The underlying UML object
29       * @see TemplateArgument
30       */
31      protected TemplateArgument metaObject;
32  
33      /** Create Metafacade implementation instance using the MetafacadeFactory from the context
34       * @param metaObjectIn
35       * @param context
36       */
37      protected TemplateArgumentFacadeLogic(TemplateArgument metaObjectIn, String context)
38      {
39          super(metaObjectIn, getContext(context));
40          this.metaObject = metaObjectIn;
41      }
42  
43      /**
44       * The logger instance.
45       */
46      private static final Logger logger = Logger.getLogger(TemplateArgumentFacadeLogic.class);
47  
48      /**
49       * Gets the context for this metafacade logic instance.
50       * @param context String. Set to TemplateArgumentFacade if null
51       * @return context String
52       */
53      private static String getContext(String context)
54      {
55          if (context == null)
56          {
57              context = "org.andromda.metafacades.uml.TemplateArgumentFacade";
58          }
59          return context;
60      }
61  
62      /** Reset context only for non-root metafacades
63       * @param context
64       */
65      @Override
66      public void resetMetafacadeContext(String context)
67      {
68          if (!this.contextRoot) // reset context only for non-root metafacades
69          {
70              context = getContext(context);  // to have same value as in original constructor call
71              setMetafacadeContext (context);
72          }
73      }
74  
75      /**
76       * @return boolean true always
77       * @see TemplateArgumentFacade
78       */
79      public boolean isTemplateArgumentFacadeMetaType()
80      {
81          return true;
82      }
83  
84      // ------------- associations ------------------
85  
86      /**
87       * Represents the model object 'Template Parameter Substitution'. Relates the actual
88       * parameter(s) to a
89       * formal template parameter as part of a template binding.
90       * @return (ModelElementFacade)handleGetElement()
91       */
92      public final ModelElementFacade getElement()
93      {
94          ModelElementFacade getElement1r = null;
95          // templateArgumentFacade has no pre constraints
96          Object result = handleGetElement();
97          MetafacadeBase shieldedResult = this.shieldedElement(result);
98          try
99          {
100             getElement1r = (ModelElementFacade)shieldedResult;
101         }
102         catch (ClassCastException ex)
103         {
104             // Bad things happen if the metafacade type mapping in metafacades.xml is wrong - Warn
105             TemplateArgumentFacadeLogic.logger.warn("incorrect metafacade cast for TemplateArgumentFacadeLogic.getElement ModelElementFacade " + result + ": " + shieldedResult);
106         }
107         // templateArgumentFacade has no post constraints
108         return getElement1r;
109     }
110 
111     /**
112      * UML Specific type is transformed by shieldedElements to AndroMDA Metafacade type
113      * @return Object
114      */
115     protected abstract Object handleGetElement();
116 
117     /**
118      * @param validationMessages Collection<ModelValidationMessage>
119      * @see MetafacadeBase#validateInvariants(Collection validationMessages)
120      */
121     @Override
122     public void validateInvariants(Collection<ModelValidationMessage> validationMessages)
123     {
124     }
125 
126     /**
127      * The property that stores the name of the metafacade.
128      */
129     private static final String NAME_PROPERTY = "name";
130     private static final String FQNAME_PROPERTY = "fullyQualifiedName";
131 
132     /**
133      * @see Object#toString()
134      */
135     @Override
136     public String toString()
137     {
138         final StringBuilder toString = new StringBuilder(this.getClass().getName());
139         toString.append("[");
140         try
141         {
142             toString.append(Introspector.instance().getProperty(this, FQNAME_PROPERTY));
143         }
144         catch (final Throwable tryAgain)
145         {
146             try
147             {
148                 toString.append(Introspector.instance().getProperty(this, NAME_PROPERTY));
149             }
150             catch (final Throwable ignore)
151             {
152                 // - just ignore when the metafacade doesn't have a name or fullyQualifiedName property
153             }
154         }
155         toString.append("]");
156         return toString.toString();
157     }
158 }