View Javadoc
1   package org.andromda.cartridges.ejb3.metafacades;
2   
3   import java.text.MessageFormat;
4   import org.andromda.cartridges.ejb3.EJB3Globals;
5   import org.andromda.cartridges.ejb3.EJB3Profile;
6   import org.andromda.metafacades.uml.UMLProfile;
7   import org.apache.commons.lang.StringUtils;
8   
9   /**
10   * MetafacadeLogic implementation for org.andromda.cartridges.ejb3.metafacades.EJB3OperationFacade.
11   *
12   * @see EJB3OperationFacade
13   */
14  public class EJB3OperationFacadeLogicImpl
15      extends EJB3OperationFacadeLogic
16  {
17      private static final long serialVersionUID = 34L;
18  
19      // ---------------- constructor -------------------------------
20      /**
21       * @param metaObject
22       * @param context
23       */
24      public EJB3OperationFacadeLogicImpl(final Object metaObject, final String context)
25      {
26          super (metaObject, context);
27      }
28  
29      // ---------------- methods -------------------------------
30  
31      /**
32       * @see EJB3OperationFacade#isBusinessOperation()
33       */
34      @Override
35      protected boolean handleIsBusinessOperation()
36      {
37          return !this.isCreateMethod() &&
38                  !this.isFinderMethod() &&
39                  !this.isSelectMethod();
40      }
41  
42      /**
43       * @see EJB3OperationFacade#isSelectMethod()
44       */
45      @Override
46      protected boolean handleIsSelectMethod()
47      {
48          return this.hasStereotype(EJB3Profile.STEREOTYPE_SELECT_METHOD);
49      }
50  
51      /**
52       * @see EJB3OperationFacadeLogic#handleIsCreateMethod()
53       */
54      @Override
55      protected boolean handleIsCreateMethod()
56      {
57          return this.hasStereotype(EJB3Profile.STEREOTYPE_CREATE_METHOD);
58      }
59  
60      /**
61       * @see EJB3OperationFacadeLogic#handleIsFinderMethod()
62       */
63      @Override
64      protected boolean handleIsFinderMethod()
65      {
66          return this.hasStereotype(UMLProfile.STEREOTYPE_FINDER_METHOD) || this.isQuery();
67      }
68  
69      /**
70       * @see EJB3OperationFacadeLogic#handleIsPrePersist()
71       */
72      @Override
73      protected boolean handleIsPrePersist()
74      {
75          return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_PERSIST);
76      }
77  
78      /**
79       * @see EJB3OperationFacadeLogic#handleIsPostPersist()
80       */
81      @Override
82      protected boolean handleIsPostPersist()
83      {
84          return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_PERSIST);
85      }
86  
87      /**
88       * @see EJB3OperationFacadeLogic#handleIsPreRemove()
89       */
90      @Override
91      protected boolean handleIsPreRemove()
92      {
93          return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_REMOVE);
94      }
95  
96      /**
97       * @see EJB3OperationFacadeLogic#handleIsPostRemove()
98       */
99      @Override
100     protected boolean handleIsPostRemove()
101     {
102         return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_REMOVE);
103     }
104 
105     /**
106      * @see EJB3OperationFacadeLogic#handleIsPreUpdate()
107      */
108     @Override
109     protected boolean handleIsPreUpdate()
110     {
111         return this.hasStereotype(EJB3Profile.STEREOTYPE_PRE_UPDATE);
112     }
113 
114     /**
115      * @see EJB3OperationFacadeLogic#handleIsPostUpdate()
116      */
117     @Override
118     protected boolean handleIsPostUpdate()
119     {
120         return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_UPDATE);
121     }
122 
123     /**
124      * @see EJB3OperationFacadeLogic#handleIsPostLoad()
125      */
126     @Override
127     protected boolean handleIsPostLoad()
128     {
129         return this.hasStereotype(EJB3Profile.STEREOTYPE_POST_LOAD);
130     }
131 
132     /**
133      * @see EJB3OperationFacadeLogic#handleIsLifecycleCallback()
134      */
135     @Override
136     protected boolean handleIsLifecycleCallback()
137     {
138         return this.isPostLoad() ||
139                 this.isPostPersist() ||
140                 this.isPostRemove() ||
141                 this.isPostUpdate() ||
142                 this.isPrePersist() ||
143                 this.isPreRemove() ||
144                 this.isPreUpdate();
145     }
146 
147     /**
148      * @see EJB3OperationFacadeLogic#handleGetImplementationName()
149      */
150     @Override
151     protected String handleGetImplementationName()
152     {
153         return this.getImplementationOperationName(StringUtils.capitalize(this.getName()));
154     }
155 
156     /**
157      * @see EJB3OperationFacadeLogic#handleGetImplementationCall()
158      */
159     @Override
160     protected String handleGetImplementationCall()
161     {
162         return this.getImplementationOperationName(StringUtils.capitalize(this.getCall()));
163     }
164 
165     /**
166      * @see EJB3OperationFacadeLogic#handleGetImplementationSignature()
167      */
168     @Override
169     protected String handleGetImplementationSignature()
170     {
171         return this.getImplementationOperationName(StringUtils.capitalize(this.getSignature()));
172     }
173 
174     /**
175      * Retrieves the implementationOperatName by replacing the <code>replacement</code> in the {@link
176      * EJB3Globals#IMPLEMENTATION_OPERATION_NAME_PATTERN}
177      *
178      * @param replacement the replacement string for the pattern.
179      * @return the operation name
180      */
181     private String getImplementationOperationName(final String replacement)
182     {
183         String implementationNamePattern =
184             (String)this.getConfiguredProperty(EJB3Globals.IMPLEMENTATION_OPERATION_NAME_PATTERN);
185 
186         return MessageFormat.format(
187                 implementationNamePattern,
188                 StringUtils.trimToEmpty(replacement));
189     }
190 }