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