KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfox > ejb > meta > EJBDescriptor


1 /* JFox, the OpenSource J2EE Application Server
2  *
3  * Distributable under GNU LGPL license by gun.org
4  * more details please visit http://www.huihoo.org/jfox
5  */

6 package org.jfox.ejb.meta;
7
8 import java.lang.reflect.Method JavaDoc;
9 import java.util.ArrayList JavaDoc;
10 import java.util.Collections JavaDoc;
11 import java.util.Iterator JavaDoc;
12 import java.util.List JavaDoc;
13
14 import org.jfox.ioc.util.XMLUtils;
15 import org.w3c.dom.Element JavaDoc;
16 import org.w3c.dom.Node JavaDoc;
17
18
19 /**
20  * @author <a HREF="mailto:young_yy@hotmail.com">Young Yang</a>
21  */

22
23 public class EJBDescriptor extends EJBDescriptorBase implements Cloneable JavaDoc {
24     private EJBBundle bundle;
25     private String JavaDoc displayName;
26     private String JavaDoc smallIcon;
27     private String JavaDoc largeIcon;
28     private String JavaDoc ejbClassName;
29     private List JavaDoc containerTransactions = new ArrayList JavaDoc();
30     private List JavaDoc methodPermissions = new ArrayList JavaDoc();
31     private List JavaDoc envEntries = new ArrayList JavaDoc();
32     private List JavaDoc ejbReferences = new ArrayList JavaDoc();
33     private List JavaDoc resourceReferences = new ArrayList JavaDoc();
34     private List JavaDoc resourceEnvReferences = new ArrayList JavaDoc();
35     private List JavaDoc roleReferences = new ArrayList JavaDoc();
36
37     private String JavaDoc transactionType;
38
39     public EJBDescriptor() {
40
41     }
42
43     public void processXML(Node JavaDoc node) throws EJBDescriptionException {
44         super.processXML(node);
45         setDisplayName(XMLUtils.getChildNodeValueOf(node, "display-name"));
46         setSmallIcon(XMLUtils.getChildNodeValueOf(node, "small-icon"));
47         setLargeIcon(XMLUtils.getChildNodeValueOf(node, "large-icon"));
48         setEjbName(XMLUtils.getChildNodeValueOf(node, "ejb-name"));
49         setEjbClassName(XMLUtils.getChildNodeValueOf(node, "ejb-class"));
50         setTransactionType(XMLUtils.getChildNodeValueOf(node, "transaction-type"));
51         
52         Iterator JavaDoc envEntries = XMLUtils.getElementsByTagName((Element JavaDoc) node, "env-entry");
53         while(envEntries.hasNext()) {
54             Element JavaDoc envEntry = (Element JavaDoc) envEntries.next();
55             EnvEntryDescriptor eed = new EnvEntryDescriptor();
56             eed.processXML(envEntry);
57             addEnvtEntry(eed);
58         }
59
60         Iterator JavaDoc ejbRefs = XMLUtils.getElementsByTagName((Element JavaDoc) node, "ejb-ref");
61         while(ejbRefs.hasNext()) {
62             Element JavaDoc ejbRef = (Element JavaDoc) ejbRefs.next();
63             EJBReferenceDescriptor erd = new EJBReferenceDescriptor();
64             erd.processXML(ejbRef);
65             addEJBReference(erd);
66         }
67
68         Iterator JavaDoc resRefs = XMLUtils.getElementsByTagName((Element JavaDoc) node, "resource-ref");
69         while(resRefs.hasNext()) {
70             Element JavaDoc resRef = (Element JavaDoc) resRefs.next();
71             ResourceRefDescriptor rrd = new ResourceRefDescriptor();
72             rrd.processXML(resRef);
73             addResourceRef(rrd);
74         }
75
76         Iterator JavaDoc resourceEnvRefs = XMLUtils.getElementsByTagName((Element JavaDoc) node, "resource-env-ref");
77         while(resourceEnvRefs.hasNext()) {
78             Element JavaDoc resourceEnvRef = (Element JavaDoc) resourceEnvRefs.next();
79             ResourceEnvRefDescriptor rerd = new ResourceEnvRefDescriptor();
80             rerd.processXML(resourceEnvRef);
81             addResourceEnvRef(rerd);
82         }
83
84         // security-role-ref not support now
85
/*
86     Iterator secRefs = XmlUtils.getElementsByTagName((Element)node,"security-role-ref");
87     while(secRefs.hasNext()){
88       Element secRef = (Element)secRefs.next();
89     }
90 */

91     }
92
93     public String JavaDoc getType() {
94         return "Session";
95     }
96
97     public EJBBundle getEJBBundle() {
98         return bundle;
99     }
100
101     public void setEJBBundle(EJBBundle bundle) {
102         this.bundle = bundle;
103     }
104
105     public String JavaDoc getDisplayName() {
106         return displayName;
107     }
108
109     public void setDisplayName(String JavaDoc displayName) {
110         this.displayName = displayName;
111     }
112
113     public String JavaDoc getSmallIcon() {
114         return smallIcon;
115     }
116
117     public void setSmallIcon(String JavaDoc smallIcon) {
118         this.smallIcon = smallIcon;
119     }
120
121     public String JavaDoc getLargeIcon() {
122         return largeIcon;
123     }
124
125     public void setLargeIcon(String JavaDoc largeIcon) {
126         this.largeIcon = largeIcon;
127     }
128
129     public String JavaDoc getEjbClassName() {
130         return ejbClassName;
131     }
132
133     public void setEjbClassName(String JavaDoc ejbClassName) {
134         this.ejbClassName = ejbClassName;
135     }
136
137     public List JavaDoc getContainerTransactions() {
138         return Collections.unmodifiableList(containerTransactions);
139     }
140
141     public List JavaDoc getMethodPermissions() {
142         return Collections.unmodifiableList(methodPermissions);
143     }
144
145     public List JavaDoc getEnvEntries() {
146         return Collections.unmodifiableList(envEntries);
147     }
148
149     public List JavaDoc getEjbReferences() {
150         return Collections.unmodifiableList(ejbReferences);
151     }
152
153     public List JavaDoc getResourceReferences() {
154         return Collections.unmodifiableList(resourceReferences);
155     }
156
157     public List JavaDoc getResourceEnvReferences() {
158         return Collections.unmodifiableList(resourceEnvReferences);
159     }
160
161     public List JavaDoc getRoleReferences() {
162         return Collections.unmodifiableList(roleReferences);
163     }
164
165     // TODO: performance !!!
166
/**
167      * get the Transaction Attribute of the method
168      *
169      * @param method
170      * @return
171      */

172     public byte getMethodTransactionAttribute(Method JavaDoc method) {
173         for(int i = 0; i < containerTransactions.size(); i++) {
174             MethodTransaction mt = (MethodTransaction) containerTransactions.get(i);
175             if(mt.getMethod().match(method)) {
176                 return mt.getTransactionAttr();
177             }
178         }
179         return TransactionAttribute.TX_REQUIRED;
180     }
181
182     public void setTransactionType(String JavaDoc txType) {
183         if(!BEAN_MANAGED_TRANSACTION.equals(txType) && !CONTAINER_MANAGED_TRANSACTION.equals(txType)) {
184             throw new IllegalArgumentException JavaDoc("transaction-type must be one of \"Bean\" and \"Container\"");
185         }
186         transactionType = txType;
187     }
188
189     public String JavaDoc getTransactionType() {
190         return transactionType;
191     }
192
193     public boolean isBeanManagedTransaction() {
194         return BEAN_MANAGED_TRANSACTION.equals(transactionType);
195     }
196
197     void addMethodTransaction(MethodTransaction mt) {
198         containerTransactions.add(mt);
199     }
200
201     void addEnvtEntry(EnvEntryDescriptor eed) {
202         envEntries.add(eed);
203     }
204
205     void addEJBReference(EJBReferenceDescriptor erd) {
206         ejbReferences.add(erd);
207     }
208
209     void addResourceRef(ResourceRefDescriptor rrd) {
210         resourceReferences.add(rrd);
211     }
212
213     void addResourceEnvRef(ResourceEnvRefDescriptor rerd) {
214         resourceEnvReferences.add(rerd);
215     }
216
217     /**
218      * becuase this object will passed to EJBMeta, so give it a clone
219      *
220      * @return
221      * @throws CloneNotSupportedException
222      */

223     public Object JavaDoc clone() throws CloneNotSupportedException JavaDoc {
224         return super.clone();
225     }
226
227     public static void main(String JavaDoc[] args) {
228
229     }
230
231 }
232
Popular Tags