KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > websphere6 > dd > beans > WSEjbBnd


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.j2ee.websphere6.dd.beans;
20
21 import org.w3c.dom.*;
22 import org.netbeans.modules.schema2beans.*;
23 import java.beans.*;
24 import java.util.*;
25 import java.io.*;
26
27 /**
28  *
29  * @author dlm198383
30  */

31 public class WSEjbBnd extends DDXmi{
32     private static final String JavaDoc ROOT=TYPE_EJB_BND_ID;
33
34     private static final String JavaDoc ROOT_NAME="EjbJarBnd";
35
36     /** Creates a new instance of WSEjbBnd */
37     public WSEjbBnd() {
38         this(null, Common.USE_DEFAULT_VALUES);
39     }
40     public WSEjbBnd(org.w3c.dom.Node JavaDoc doc, int options) {
41         this(Common.NO_DEFAULT_VALUES);
42         try {
43             initFromNode(doc, options);
44         } catch (Schema2BeansException e) {
45             throw new RuntimeException JavaDoc(e);
46         }
47     }
48     public WSEjbBnd(int options) {
49         super(options,ROOT);
50         //initOptions(options);
51
}
52     
53     public WSEjbBnd(File f,boolean validate) throws IOException{
54         this(GraphManager.createXmlDocument(new FileInputStream(f), validate), Common.NO_DEFAULT_VALUES);
55     }
56     
57     public WSEjbBnd(InputStream in, boolean validate) {
58         this(GraphManager.createXmlDocument(in, validate), Common.NO_DEFAULT_VALUES);
59     }
60     
61     protected void initFromNode(org.w3c.dom.Node JavaDoc doc, int options) throws Schema2BeansException {
62         if (doc == null) {
63             doc = GraphManager.createRootElementNode(ROOT); // NOI18N
64
if (doc == null)
65                 throw new Schema2BeansException(Common.getMessage(
66                         "CantCreateDOMRoot_msg", ROOT));
67         }
68         Node n = GraphManager.getElementNode(ROOT, doc); // NOI18N
69
if (n == null) {
70             throw new Schema2BeansException(Common.getMessage("DocRootNotInDOMGraph_msg", ROOT, doc.getFirstChild().getNodeName()));
71         }
72         this.graphManager.setXmlDocument(doc);
73         this.createBean(n, this.graphManager());
74         this.initialize(options);
75     };
76     
77     public void initialize(int options) {
78         
79     }
80     
81     public void setDefaults() {
82         setXmiVersion();
83         setNsXmi();
84         setNsEjb();
85         setNsEjbBnd();
86         setNsCommon();
87         setNsCommonBnd();
88         setXmiId("EJBJarBinding");
89         setEjbJar("");
90         setEjbJarHref("ID_ejb_jar");
91         /*
92         EjbBindingsType ejbbind=new EjbBindingsType();
93         
94         ejbbind.setEnterpriseBean("");
95         ejbbind.setXmiType(EJB_ENTERPRISE_BEAN_TYPE_SESSION);
96         ejbbind.setHref("NewSessionBean");
97         ejbbind.setXmiId("Session_EJB_Bnd");
98         ejbbind.setJndiName("NewSessionBean");
99         addEjbBindings(ejbbind);
100          */

101     }
102     
103     protected void initOptions(int options) {
104         this.graphManager = new GraphManager(this);
105         this.createRoot(ROOT, ROOT_NAME, // NOI18N
106
Common.TYPE_1 | Common.TYPE_BEAN, WSEjbBnd.class);
107         this.createAttribute(XMI_ID_ID, XMI_ID, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
108         this.createAttribute(NS_EJB_ID, NS_EJB, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
109         this.createAttribute(NS_EJB_BND_ID, NS_EJB_BND, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
110         this.createAttribute(NS_XMI_ID, NS_XMI, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
111         this.createAttribute(XMI_VERSION_ID, XMI_VERSION, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
112         this.createAttribute(NS_COMMON_ID, NS_COMMON, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
113         this.createAttribute(NS_COMMON_BND_ID, NS_COMMON_BND, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
114         this.createAttribute(CURRENT_BACKEND_ID_ID, CURRENT_BACKEND_ID, AttrProp.CDATA | AttrProp.IMPLIED,null, null);
115         initPropertyTables(3);
116         
117         this.createProperty(EJB_BINDINGS_ID, // NOI18N
118
EJB_BINDINGS,
119                 Common.TYPE_0_N | Common.TYPE_BEAN | Common.TYPE_KEY,
120                 EjbBindingsType.class);
121         
122         this.createAttribute(EJB_BINDINGS,XMI_ID_ID , EJB_BINDINGS_XMI_ID , AttrProp.CDATA | AttrProp.IMPLIED,null, null);
123         this.createAttribute(EJB_BINDINGS,JNDI_NAME_ID , EJB_BINDINGS_JNDI_NAME , AttrProp.CDATA | AttrProp.IMPLIED,null, null);
124         
125         this.createProperty(EJB_JAR_ID, // NOI18N
126
EJB_JAR,
127                 Common.TYPE_1 | Common.TYPE_STRING | Common.TYPE_KEY,
128                 java.lang.String JavaDoc.class);
129         this.createAttribute(EJB_JAR,HREF_ID,EJB_JAR_HREF,AttrProp.CDATA | AttrProp.IMPLIED,null, null);
130         
131         
132         this.createProperty(DEFAULT_CMP_CONNECTION_FACTORY_ID,
133                 CMP_CONNECTION_FACTORY,
134                 Common.TYPE_0_1 | Common.TYPE_STRING | Common.TYPE_KEY,
135                 java.lang.String JavaDoc.class);
136         this.createAttribute(CMP_CONNECTION_FACTORY,XMI_ID_ID,CMP_CONNECTION_FACTORY_XMI_ID,AttrProp.CDATA | AttrProp.IMPLIED,null, null);
137         this.createAttribute(CMP_CONNECTION_FACTORY,JNDI_NAME_ID,CMP_CONNECTION_FACTORY_JNDI_NAME,AttrProp.CDATA | AttrProp.IMPLIED,null, null);
138         this.createAttribute(CMP_CONNECTION_FACTORY,RES_AUTH_ID,CMP_CONNECTION_FACTORY_RES_AUTH,AttrProp.CDATA | AttrProp.IMPLIED,null, null);
139         
140         
141         this.initialize(options);
142     }
143     
144     public void setEjbBindings(int index,EjbBindingsType value) {
145         this.setValue(EJB_BINDINGS, index,value);
146     }
147     
148     public void setEjbBindings(EjbBindingsType[]value) {
149         this.setValue(EJB_BINDINGS, value);
150     }
151     //
152
public EjbBindingsType[] getEjbBindings() {
153         return (EjbBindingsType[])this.getValues(EJB_BINDINGS);
154     }
155     public EjbBindingsType getEjbBindings(int index) {
156         return (EjbBindingsType)this.getValue(EJB_BINDINGS,index);
157     }
158     public int sizeEjbBindings() {
159         return this.size(EJB_BINDINGS);
160     }
161     public int addEjbBindings(EjbBindingsType value) {
162         int positionOfNewItem = this.addValue(EJB_BINDINGS, value);
163         return positionOfNewItem;
164     }
165     
166     //
167
// Remove an element using its reference
168
// Returns the index the element had in the list
169
//
170
public int removeEjbBindings(EjbBindingsType value) {
171         return this.removeValue(EJB_BINDINGS, value);
172     }
173     
174     
175     public void setEjbBindingsId(String JavaDoc value,int index) {
176         setAttributeValue(EJB_BINDINGS,index,XMI_ID,value);
177     }
178     
179     public String JavaDoc getEjbBindingsId(int index){
180         return (String JavaDoc)getAttributeValue(EJB_BINDINGS,index,EJB_BINDINGS_XMI_ID);
181     }
182     
183     
184     
185     public void setEjbBindingsJndiName(String JavaDoc value,int index) {
186         setAttributeValue(EJB_BINDINGS,index,EJB_BINDINGS_JNDI_NAME,value);
187     }
188     
189     public String JavaDoc getEjbBindingsJndiName(int index){
190         return (String JavaDoc)getAttributeValue(EJB_BINDINGS,index,EJB_BINDINGS_JNDI_NAME);
191     }
192     public void setCurrentBackendId(String JavaDoc value) {
193         setAttributeValue(CURRENT_BACKEND_ID,value);
194     }
195     public String JavaDoc getCurrentBackendId() {
196         return (String JavaDoc)this.getAttributeValue(CURRENT_BACKEND_ID);
197     }
198     
199     
200     public void setCmpConnectionFactory(String JavaDoc value) {
201         this.setValue(CMP_CONNECTION_FACTORY,value);
202     }
203     public String JavaDoc getCmpConnectionFactory() {
204         return (String JavaDoc)this.getValue(CMP_CONNECTION_FACTORY);
205     }
206     public void setCmpConnectionFactoryXmiId(String JavaDoc value) {
207         if(size(CMP_CONNECTION_FACTORY)==0) {
208             setCmpConnectionFactory("");
209         }
210         this.setAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_XMI_ID,value);
211     }
212     public String JavaDoc getCmpConnectionFactoryXmiId() {
213         if(size(CMP_CONNECTION_FACTORY)==0) {
214             return null;
215         }
216         return (String JavaDoc) this.getAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_XMI_ID);
217     }
218     public void setCmpConnectionFactoryJndiName(String JavaDoc value) {
219         if(size(CMP_CONNECTION_FACTORY)==0) {
220             setCmpConnectionFactory("");
221         }
222         this.setAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_JNDI_NAME,value);
223     }
224     public String JavaDoc getCmpConnectionFactoryJndiName() {
225         if(size(CMP_CONNECTION_FACTORY)==0) {
226             return null;
227         }
228         return (String JavaDoc) this.getAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_JNDI_NAME);
229     }
230     public void setCmpConnectionFactoryResAuth(String JavaDoc value) {
231         if(size(CMP_CONNECTION_FACTORY)==0) {
232             setCmpConnectionFactory("");
233         }
234         this.setAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_RES_AUTH,value);
235     }
236     public String JavaDoc getCmpConnectionFactoryResAuth() {
237         if(size(CMP_CONNECTION_FACTORY)==0) {
238             return null;
239         }
240         return (String JavaDoc) this.getAttributeValue(CMP_CONNECTION_FACTORY,CMP_CONNECTION_FACTORY_RES_AUTH);
241     }
242     
243     
244     public void validate() throws org.netbeans.modules.schema2beans.ValidateException {
245         
246         if (getEjbBindings()!= null) {
247             // Validating property jdbcConnectionPool
248
for (int _index = 0; _index < sizeEjbBindings(); ++_index) {
249                 EjbBindingsType element = getEjbBindings(_index);
250                 if (element != null) {
251                     element.validate();
252                 }
253                 if(getEjbBindingsId(_index)==null) {
254                     throw new org.netbeans.modules.schema2beans.ValidateException("getEjbBindingsId["+_index+"] == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, EJB_BINDINGS, this); // NOI18N
255
}
256                 if(getEjbBindingsJndiName(_index)==null) {
257                     throw new org.netbeans.modules.schema2beans.ValidateException("getEjbBindingsName["+_index+"] == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, EJB_BINDINGS, this); // NOI18N
258
}
259             }
260         }
261         if (getEjbJar()== null) {
262             throw new org.netbeans.modules.schema2beans.ValidateException("getEjbJar() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, EJB_JAR, this); // NOI18N
263
}
264         if (getEjbJarHref()==null) {
265             throw new org.netbeans.modules.schema2beans.ValidateException("getEjbJarHref() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, EJB_JAR, this); // NOI18N
266
}
267         if (getNsEjb()==null) {
268             throw new org.netbeans.modules.schema2beans.ValidateException("getNsEjb() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, ROOT, this); // NOI18N
269
}
270         if (getNsEjbBnd()==null) {
271             throw new org.netbeans.modules.schema2beans.ValidateException("getNsEjbBnd() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, ROOT, this); // NOI18N
272
}
273         if (getNsXmi()==null) {
274             throw new org.netbeans.modules.schema2beans.ValidateException("getNsXmi() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, ROOT, this); // NOI18N
275
}
276         if(getXmiId()==null) {
277             throw new org.netbeans.modules.schema2beans.ValidateException("getXmiId() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, ROOT, this); // NOI18N
278
}
279         if(getXmiVersion()==null) {
280             throw new org.netbeans.modules.schema2beans.ValidateException("getXmiVersion() == null", org.netbeans.modules.schema2beans.ValidateException.FailureType.NULL_VALUE, ROOT, this); // NOI18N
281
}
282         
283     }
284     
285     public void dump(StringBuffer JavaDoc str, String JavaDoc indent){
286         String JavaDoc s;
287         Object JavaDoc o;
288         BaseBean n;
289         
290         str.append(indent);
291         str.append(EJB_JAR); // NOI18N
292
str.append(indent+"\t"); // NOI18N
293
str.append("<"); // NOI18N
294
o = this.getApplication();
295         str.append((o==null?"null":o.toString().trim())); // NOI18N
296
str.append(">\n"); // NOI18N
297
this.dumpAttributes(EJB_JAR, 0, str, indent);
298         
299         str.append(indent);
300         str.append(EJB_BINDINGS+"["+this.sizeEjbBindings()+"]"); // NOI18N
301
for(int i=0; i<this.sizeEjbBindings(); i++) {
302             str.append(indent+"\t");
303             str.append("#"+i+":");
304             n = (BaseBean) this.getEjbBindings(i);
305             if (n != null)
306                 n.dump(str, indent + "\t"); // NOI18N
307
else
308                 str.append(indent+"\tnull"); // NOI18N
309
this.dumpAttributes(EJB_BINDINGS, i, str, indent);
310         }
311         
312     }
313     public String JavaDoc dumpBeanNode(){
314         StringBuffer JavaDoc str = new StringBuffer JavaDoc();
315         str.append(getClass().getName()); // NOI18N
316
this.dump(str, "\n "); // NOI18N
317
return str.toString();
318     }
319 }
320
Popular Tags