View Javadoc
1   package org.andromda.cartridges.ejb.metafacades;
2   
3   import java.util.Collection;
4   import java.util.List;
5   import org.andromda.cartridges.ejb.EJBGlobals;
6   import org.andromda.cartridges.ejb.EJBProfile;
7   import org.apache.commons.collections.CollectionUtils;
8   import org.apache.commons.collections.Predicate;
9   import org.apache.commons.lang.StringUtils;
10  
11  /**
12   * MetafacadeLogic implementation.
13   *
14   * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade
15   */
16  public class EJBSessionFacadeLogicImpl
17          extends EJBSessionFacadeLogic
18  {
19      private static final long serialVersionUID = 34L;
20      // ---------------- constructor -------------------------------
21  
22      /**
23       * @param metaObject
24       * @param context
25       */
26      public EJBSessionFacadeLogicImpl(Object metaObject, String context)
27      {
28          super(metaObject, context);
29      }
30  
31      /**
32       * @param follow
33       * @return getCreateMethods
34       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getCreateMethods(boolean)
35       */
36      protected java.util.Collection handleGetCreateMethods(boolean follow)
37      {
38          return EJBMetafacadeUtils.getCreateMethods(this, follow);
39      }
40  
41      /**
42       * @return EJBMetafacadeUtils.getHomeInterfaceName(this)
43       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getHomeInterfaceName()
44       */
45      protected String handleGetHomeInterfaceName()
46      {
47          return EJBMetafacadeUtils.getHomeInterfaceName(this);
48      }
49  
50      /**
51       * @return EJBMetafacadeUtils.getViewType(this)
52       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getViewType()
53       */
54      protected String handleGetViewType()
55      {
56          return EJBMetafacadeUtils.getViewType(this);
57      }
58  
59      /**
60       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#handleGetInheritedInstanceAttributes()
61       */
62      protected List handleGetInheritedInstanceAttributes()
63      {
64          return EJBMetafacadeUtils.getInheritedInstanceAttributes(this);
65      }
66  
67      /**
68       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#handleGetAllInstanceAttributes()
69       */
70      protected List handleGetAllInstanceAttributes()
71      {
72          return EJBMetafacadeUtils.getAllInstanceAttributes(this);
73      }
74  
75      /**
76       * @param follow
77       * @return getEnvironmentEntries
78       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getEnvironmentEntries(boolean)
79       */
80      protected Collection handleGetEnvironmentEntries(boolean follow)
81      {
82          return EJBMetafacadeUtils.getEnvironmentEntries(this, follow);
83      }
84  
85      /**
86       * @param follow
87       * @return getConstants
88       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getConstants(boolean)
89       */
90      protected Collection handleGetConstants(boolean follow)
91      {
92          return EJBMetafacadeUtils.getConstants(this, follow);
93      }
94  
95      /**
96       * @return jndiName
97       * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getJndiName()
98       */
99      protected String handleGetJndiName()
100     {
101         StringBuilder jndiName = new StringBuilder();
102         String jndiNamePrefix = StringUtils.trimToEmpty(this.getJndiNamePrefix());
103         if (StringUtils.isNotBlank(jndiNamePrefix))
104         {
105             jndiName.append(jndiNamePrefix);
106             jndiName.append('/');
107         }
108         jndiName.append("ejb/");
109         jndiName.append(this.getFullyQualifiedName());
110         return jndiName.toString();
111     }
112 
113     /**
114      * Gets the <code>jndiNamePrefix</code> for this EJB.
115      *
116      * @return the EJB Jndi name prefix.
117      */
118     protected String getJndiNamePrefix()
119     {
120         String prefix = null;
121         if (this.isConfiguredProperty(EJBGlobals.JNDI_NAME_PREFIX))
122         {
123             prefix = (String)this.getConfiguredProperty(EJBGlobals.JNDI_NAME_PREFIX);
124         }
125         return prefix;
126     }
127 
128     /**
129      * @return !isStateless
130      * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#isStateful()
131      */
132     protected boolean handleIsStateful()
133     {
134         return !isStateless();
135     }
136 
137     /**
138      * @return getAllInstanceAttributes().isEmpty()
139      * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#isStateless()
140      */
141     protected boolean handleIsStateless()
142     {
143         return this.getAllInstanceAttributes() == null || this.getAllInstanceAttributes().isEmpty();
144     }
145 
146     /**
147      * @return type Stateful/Stateless
148      * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getType()
149      */
150     protected String handleGetType()
151     {
152         String type = "Stateful";
153         if (this.isStateless())
154         {
155             type = "Stateless";
156         }
157         return type;
158     }
159 
160     /**
161      * EJBMetafacadeUtils.allowSyntheticCreateMethod(this)
162      * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#handleIsSyntheticCreateMethodAllowed()
163      * @return EJBMetafacadeUtils.allowSyntheticCreateMethod(this)
164      */
165     protected boolean handleIsSyntheticCreateMethodAllowed()
166     {
167         return EJBMetafacadeUtils.allowSyntheticCreateMethod(this);
168     }
169 
170     /**
171      * @return businessOperation
172      * @see org.andromda.metafacades.uml.Entity#getBusinessOperations()
173      */
174     protected Collection handleGetBusinessOperations()
175     {
176         Collection operations = super.getOperations();
177         CollectionUtils.filter(operations, new Predicate()
178         {
179             public boolean evaluate(Object object)
180             {
181                 boolean businessOperation = false;
182                 if (EJBOperationFacade.class.isAssignableFrom(object.getClass()))
183                 {
184                     businessOperation = ((EJBOperationFacade)object).isBusinessOperation();
185                 }
186                 return businessOperation;
187             }
188         });
189         return operations;
190     }
191 
192     /**
193      * @return transactionType
194      * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getTransactionType()
195      */
196     protected String handleGetTransactionType()
197     {
198         String transactionType = (String)this.findTaggedValue(EJBProfile.TAGGEDVALUE_EJB_TRANSACTION_TYPE);
199         if (StringUtils.isBlank(transactionType))
200         {
201             transactionType = String.valueOf(this.getConfiguredProperty(EJBGlobals.TRANSACTION_TYPE));
202         }
203         if (StringUtils.isBlank(transactionType))
204         {
205             transactionType = "Required";
206         }
207         return transactionType;
208     }
209 }