1 22 package org.jboss.ejb3.metamodel; 23 24 import java.util.ArrayList ; 25 import java.util.Collection ; 26 import java.util.HashMap ; 27 import java.util.Iterator ; 28 import java.util.List ; 29 import org.jboss.logging.Logger; 30 31 import org.jboss.metamodel.descriptor.EjbLocalRef; 32 import org.jboss.metamodel.descriptor.EjbRef; 33 import org.jboss.metamodel.descriptor.InjectionTarget; 34 import org.jboss.metamodel.descriptor.JndiRef; 35 import org.jboss.metamodel.descriptor.MessageDestinationRef; 36 import org.jboss.metamodel.descriptor.ResourceEnvRef; 37 import org.jboss.metamodel.descriptor.ResourceRef; 38 import org.jboss.metamodel.descriptor.ServiceRef; 39 40 49 public class EnterpriseBeans 50 { 51 private static final Logger log = Logger.getLogger(EnterpriseBeans.class); 52 53 private HashMap <String , EnterpriseBean> enterpriseBeans = new HashMap (); 54 55 private EnterpriseBean currentEjb; 56 57 public void setPoolConfig(PoolConfig config) 58 { 59 currentEjb.setPoolConfig(config); 60 } 61 62 public void setDefaultActivationConfig(ActivationConfig config) 63 { 64 ((MessageDrivenBean)currentEjb).setDefaultActivationConfig(config); 65 } 66 67 public void setCacheConfig(CacheConfig config) 68 { 69 ((SessionEnterpriseBean)currentEjb).setCacheConfig(config); 70 } 71 72 public void setClustered(String clustered) 73 { 74 ((SessionEnterpriseBean)currentEjb).setClustered(clustered); 75 } 76 77 public void setConcurrent(String concurrent) 78 { 79 ((SessionEnterpriseBean)currentEjb).setConcurrent(concurrent); 80 } 81 82 public void addJndiRef(JndiRef ref) 83 { 84 currentEjb.addJndiRef(ref); 85 } 86 87 public void addXmlAnnotation(XmlAnnotation xmlAnnotation) 88 { 89 currentEjb.addXmlAnnotation(xmlAnnotation); 90 } 91 92 public void addRemoteBinding(RemoteBinding binding) 93 { 94 currentEjb.addRemoteBinding(binding); 95 } 96 97 public void addIgnoreDependency(InjectionTarget ignore) 98 { 99 currentEjb.addIgnoreDependency(ignore); 100 } 101 102 public void addResourceRef(ResourceRef ref) 103 { 104 currentEjb.mergeResourceRef(ref); 105 } 106 107 public void addResourceEnvRef(ResourceEnvRef ref) 108 { 109 currentEjb.mergeResourceEnvRef(ref); 110 } 111 112 public void addMessageDestinationRef(MessageDestinationRef ref) 113 { 114 currentEjb.mergeMessageDestinationRef(ref); 115 } 116 117 public void addServiceRef(ServiceRef ref) 118 { 119 currentEjb.addServiceRef(ref); 120 } 121 122 public void setMethodAttributes(MethodAttributes attributes) 123 { 124 currentEjb.setMethodAttributes(attributes); 125 } 126 127 public void setCurrentEjbName(String currentEjbName, Class ejbClass) 128 { 129 currentEjb = createEjbByEjbName(currentEjbName, ejbClass); 130 } 131 132 public void addDependency(String depends) 133 { 134 currentEjb.addDependency(depends); 135 } 136 137 public void updateEjbRef(EjbRef ref) 138 { 139 currentEjb.updateEjbRef(ref); 140 } 141 142 public void updateEjbLocalRef(EjbLocalRef ref) 143 { 144 currentEjb.updateEjbLocalRef(ref); 145 } 146 147 public void updateResourceRef(ResourceRef ref) 148 { 149 currentEjb.updateResourceRef(ref); 150 } 151 152 public void updateResourceEnvRef(ResourceEnvRef ref) 153 { 154 currentEjb.updateResourceEnvRef(ref); 155 } 156 157 public void updateMessageDestinationRef(MessageDestinationRef ref) 158 { 159 currentEjb.updateMessageDestinationRef(ref); 160 } 161 162 public void setResourceAdapterName(String name) 163 { 164 ((MessageDrivenBean)currentEjb).setResourceAdaptorName(name); 165 } 166 167 public void setDestinationJndiName(String name) 168 { 169 ((MessageDrivenBean)currentEjb).setDestinationJndiName(name); 170 } 171 172 public void setMdbUser(String name) 173 { 174 ((MessageDrivenBean)currentEjb).setMdbUser(name); 175 } 176 177 public void setMdbPassword(String name) 178 { 179 ((MessageDrivenBean)currentEjb).setMdbPassword(name); 180 } 181 182 public void setMdbSubscriptionId(String id) 183 { 184 ((MessageDrivenBean)currentEjb).setMdbSubscriptionId(id); 185 } 186 187 public void setAopDomainName(String aopDomainName) 188 { 189 currentEjb.setAopDomainName(aopDomainName); 190 } 191 192 public void setRunAsPrincipal(String principal) 193 { 194 currentEjb.setRunAsPrincipal(principal); 195 } 196 197 public void setClusterConfig(ClusterConfig config) 198 { 199 ((SessionEnterpriseBean)currentEjb).setClusterConfig(config); 200 } 201 202 public void setCallByValue(boolean callByValue) 203 { 204 currentEjb.setCallByValue(callByValue); 205 } 206 207 public void setJndiName(String jndiName) 208 { 209 currentEjb.setJndiName(jndiName); 210 } 211 212 public void setSecurityDomain(String securityDomain) 213 { 214 currentEjb.setSecurityDomain(securityDomain); 215 } 216 217 public void setLocalJndiName(String jndiName) 218 { 219 currentEjb.setLocalJndiName(jndiName); 220 } 221 222 public EnterpriseBean createEjbByEjbName(String ejbName, Class ejbClass) 223 { 224 EnterpriseBean ejb = (EnterpriseBean) enterpriseBeans.get(ejbName); 225 if (ejb != null) 226 return ejb; 227 228 try 229 { 230 ejb = (EnterpriseBean)ejbClass.newInstance(); 231 ejb.setEjbName(ejbName); 232 enterpriseBeans.put(ejbName, ejb); 233 } 234 catch (Exception e){} 235 236 return ejb; 237 } 238 239 public EnterpriseBean findEjbByEjbName(String ejbName) 240 { 241 return enterpriseBeans.get(ejbName); 242 } 243 244 public List <EnterpriseBean> findEjbsByClass(String className) 245 { 246 ArrayList <EnterpriseBean> result = new ArrayList <EnterpriseBean>(); 247 248 Iterator ejbs = enterpriseBeans.values().iterator(); 249 while (ejbs.hasNext()) 250 { 251 EnterpriseBean ejb = (EnterpriseBean) ejbs.next(); 252 String ejbClassName = ejb.getEjbClass(); 253 if (ejbClassName != null && ejbClassName.equals(className)) 254 result.add(ejb); 255 } 256 return result; 257 } 258 259 public EnterpriseBean findEjbByRemote(String remote) 260 { 261 Iterator ejbs = enterpriseBeans.values().iterator(); 262 while (ejbs.hasNext()) 263 { 264 EnterpriseBean ejb = (EnterpriseBean) ejbs.next(); 265 if (ejb.getRemote() != null && ejb.getRemote().equals(remote)) 266 return ejb; 267 } 268 return null; 269 } 270 271 public EnterpriseBean findEjbByLocal(String local) 272 { 273 Iterator ejbs = enterpriseBeans.values().iterator(); 274 while (ejbs.hasNext()) 275 { 276 EnterpriseBean ejb = (EnterpriseBean) ejbs.next(); 277 if (ejb.getLocal() != null && ejb.getLocal().equals(local)) 278 return ejb; 279 } 280 return null; 281 } 282 283 public Collection <EnterpriseBean> getEnterpriseBeans() 284 { 285 return enterpriseBeans.values(); 286 } 287 288 292 293 public void addEnterpriseBean(EnterpriseBean ejb) 294 { 295 enterpriseBeans.put(ejb.getEjbName(), ejb); 296 } 297 298 public String toString() 299 { 300 StringBuffer sb = new StringBuffer (100); 301 sb.append("["); 302 sb.append("enterpriseBeans=").append(enterpriseBeans); 303 sb.append("]"); 304 return sb.toString(); 305 } 306 307 public boolean equals(Object o) 308 { 309 if (this == o) 310 return true; 311 if (!(o instanceof EnterpriseBeans)) 312 return false; 313 314 final EnterpriseBeans ejbs = (EnterpriseBeans) o; 315 316 if (enterpriseBeans != null ? !enterpriseBeans 317 .equals(ejbs.enterpriseBeans) : ejbs.enterpriseBeans != null) 318 return false; 319 320 return true; 321 } 322 323 public int hashCode() 324 { 325 int result; 326 result = (enterpriseBeans != null ? enterpriseBeans.hashCode() : 0); 327 return result; 329 } 330 } 331 | Popular Tags |