KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > ejb3 > metamodel > EnterpriseBeans


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.ejb3.metamodel;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Collection JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.List JavaDoc;
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 /**
41  * Represents EJB elements of the ejb-jar.xml deployment descriptor for the 1.4
42  * schema
43  *
44  * @author <a HREF="mailto:bdecoste@jboss.com">William DeCoste</a>
45  * ejbs.setCurrentEjbName(value); } else if
46  * (localName.equals("jndi-name")){ ejbs.setJndiName(value);
47  * @version <tt>$Revision: 58121 $</tt>
48  */

49 public class EnterpriseBeans
50 {
51    private static final Logger log = Logger.getLogger(EnterpriseBeans.class);
52
53    private HashMap JavaDoc<String JavaDoc, EnterpriseBean> enterpriseBeans = new HashMap JavaDoc();
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 JavaDoc clustered)
73    {
74       ((SessionEnterpriseBean)currentEjb).setClustered(clustered);
75    }
76    
77    public void setConcurrent(String JavaDoc 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 JavaDoc currentEjbName, Class JavaDoc ejbClass)
128    {
129       currentEjb = createEjbByEjbName(currentEjbName, ejbClass);
130    }
131
132    public void addDependency(String JavaDoc 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 JavaDoc name)
163    {
164       ((MessageDrivenBean)currentEjb).setResourceAdaptorName(name);
165    }
166
167    public void setDestinationJndiName(String JavaDoc name)
168    {
169       ((MessageDrivenBean)currentEjb).setDestinationJndiName(name);
170    }
171
172    public void setMdbUser(String JavaDoc name)
173    {
174       ((MessageDrivenBean)currentEjb).setMdbUser(name);
175    }
176
177    public void setMdbPassword(String JavaDoc name)
178    {
179       ((MessageDrivenBean)currentEjb).setMdbPassword(name);
180    }
181    
182    public void setMdbSubscriptionId(String JavaDoc id)
183    {
184       ((MessageDrivenBean)currentEjb).setMdbSubscriptionId(id);
185    }
186
187    public void setAopDomainName(String JavaDoc aopDomainName)
188    {
189       currentEjb.setAopDomainName(aopDomainName);
190    }
191
192    public void setRunAsPrincipal(String JavaDoc 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 JavaDoc jndiName)
208    {
209       currentEjb.setJndiName(jndiName);
210    }
211
212    public void setSecurityDomain(String JavaDoc securityDomain)
213    {
214       currentEjb.setSecurityDomain(securityDomain);
215    }
216
217    public void setLocalJndiName(String JavaDoc jndiName)
218    {
219       currentEjb.setLocalJndiName(jndiName);
220    }
221
222    public EnterpriseBean createEjbByEjbName(String JavaDoc ejbName, Class JavaDoc 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 JavaDoc e){}
235       
236       return ejb;
237    }
238    
239    public EnterpriseBean findEjbByEjbName(String JavaDoc ejbName)
240    {
241       return enterpriseBeans.get(ejbName);
242    }
243
244    public List JavaDoc<EnterpriseBean> findEjbsByClass(String JavaDoc className)
245    {
246       ArrayList JavaDoc<EnterpriseBean> result = new ArrayList JavaDoc<EnterpriseBean>();
247
248       Iterator JavaDoc ejbs = enterpriseBeans.values().iterator();
249       while (ejbs.hasNext())
250       {
251          EnterpriseBean ejb = (EnterpriseBean) ejbs.next();
252          String JavaDoc 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 JavaDoc remote)
260    {
261       Iterator JavaDoc 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 JavaDoc local)
272    {
273       Iterator JavaDoc 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 JavaDoc<EnterpriseBean> getEnterpriseBeans()
284    {
285       return enterpriseBeans.values();
286    }
287
288 /* public void setEnterpriseBeans(List enterpriseBeans)
289    {
290       this.enterpriseBeans = enterpriseBeans;
291    }*/

292
293    public void addEnterpriseBean(EnterpriseBean ejb)
294    {
295       enterpriseBeans.put(ejb.getEjbName(), ejb);
296    }
297
298    public String JavaDoc toString()
299    {
300       StringBuffer JavaDoc sb = new StringBuffer JavaDoc(100);
301       sb.append("[");
302       sb.append("enterpriseBeans=").append(enterpriseBeans);
303       sb.append("]");
304       return sb.toString();
305    }
306
307    public boolean equals(Object JavaDoc 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       // result = 29 * result + (version != null ? version.hashCode() : 0);
328
return result;
329    }
330 }
331
Popular Tags