001package org.andromda.cartridges.ejb.metafacades; 002 003import java.util.Collection; 004import java.util.List; 005import org.andromda.cartridges.ejb.EJBGlobals; 006import org.andromda.cartridges.ejb.EJBProfile; 007import org.apache.commons.collections.CollectionUtils; 008import org.apache.commons.collections.Predicate; 009import org.apache.commons.lang.StringUtils; 010 011/** 012 * MetafacadeLogic implementation. 013 * 014 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade 015 */ 016public class EJBSessionFacadeLogicImpl 017 extends EJBSessionFacadeLogic 018{ 019 private static final long serialVersionUID = 34L; 020 // ---------------- constructor ------------------------------- 021 022 /** 023 * @param metaObject 024 * @param context 025 */ 026 public EJBSessionFacadeLogicImpl(Object metaObject, String context) 027 { 028 super(metaObject, context); 029 } 030 031 /** 032 * @param follow 033 * @return getCreateMethods 034 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getCreateMethods(boolean) 035 */ 036 protected java.util.Collection handleGetCreateMethods(boolean follow) 037 { 038 return EJBMetafacadeUtils.getCreateMethods(this, follow); 039 } 040 041 /** 042 * @return EJBMetafacadeUtils.getHomeInterfaceName(this) 043 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getHomeInterfaceName() 044 */ 045 protected String handleGetHomeInterfaceName() 046 { 047 return EJBMetafacadeUtils.getHomeInterfaceName(this); 048 } 049 050 /** 051 * @return EJBMetafacadeUtils.getViewType(this) 052 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getViewType() 053 */ 054 protected String handleGetViewType() 055 { 056 return EJBMetafacadeUtils.getViewType(this); 057 } 058 059 /** 060 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#handleGetInheritedInstanceAttributes() 061 */ 062 protected List handleGetInheritedInstanceAttributes() 063 { 064 return EJBMetafacadeUtils.getInheritedInstanceAttributes(this); 065 } 066 067 /** 068 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacadeLogic#handleGetAllInstanceAttributes() 069 */ 070 protected List handleGetAllInstanceAttributes() 071 { 072 return EJBMetafacadeUtils.getAllInstanceAttributes(this); 073 } 074 075 /** 076 * @param follow 077 * @return getEnvironmentEntries 078 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getEnvironmentEntries(boolean) 079 */ 080 protected Collection handleGetEnvironmentEntries(boolean follow) 081 { 082 return EJBMetafacadeUtils.getEnvironmentEntries(this, follow); 083 } 084 085 /** 086 * @param follow 087 * @return getConstants 088 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getConstants(boolean) 089 */ 090 protected Collection handleGetConstants(boolean follow) 091 { 092 return EJBMetafacadeUtils.getConstants(this, follow); 093 } 094 095 /** 096 * @return jndiName 097 * @see org.andromda.cartridges.ejb.metafacades.EJBSessionFacade#getJndiName() 098 */ 099 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}