KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > dd > impl > ejb > SunEjbJarProxy


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 /*
20  * SunEjbJarProxy.java
21  *
22  * Created on February 7, 2005, 12:13 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.dd.impl.ejb;
26
27 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
28 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
29 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar;
30 import org.netbeans.modules.j2ee.sun.dd.impl.DDTreeWalker;
31 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry;
32
33 import org.w3c.dom.Document JavaDoc;
34
35
36 /**
37  *
38  * @author Nitya Doraisamy
39  */

40 public class SunEjbJarProxy implements SunEjbJar {
41
42     private SunEjbJar ejbJarRoot;
43     private String JavaDoc version;
44     private OutputProvider outputProvider;
45     private int ddStatus;
46     private org.xml.sax.SAXParseException JavaDoc error;
47     private java.util.List JavaDoc listeners;
48         
49     /** Creates a new instance of SunEjbJarProxy */
50     public SunEjbJarProxy(SunEjbJar ejbJarRoot, String JavaDoc version) {
51         this.ejbJarRoot = ejbJarRoot;
52         this.version = version;
53     }
54
55     public int addSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) {
56         return ejbJarRoot==null?-1:ejbJarRoot.addSecurityRoleMapping(securityRoleMapping);
57     }
58
59     public org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans getEnterpriseBeans() {
60         return ejbJarRoot==null?null:ejbJarRoot.getEnterpriseBeans();
61     }
62
63     public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] getSecurityRoleMapping() {
64         return ejbJarRoot==null?null:ejbJarRoot.getSecurityRoleMapping();
65     }
66
67     public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping getSecurityRoleMapping(int param) {
68         return ejbJarRoot==null?null:ejbJarRoot.getSecurityRoleMapping(param);
69     }
70
71     public org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans newEnterpriseBeans() {
72         if(ejbJarRoot == null)
73             return null;
74         else
75             return ejbJarRoot.newEnterpriseBeans();
76     }
77
78     public int removeSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) {
79         return ejbJarRoot==null?-1:ejbJarRoot.removeSecurityRoleMapping(securityRoleMapping);
80     }
81
82     public void setEnterpriseBeans(org.netbeans.modules.j2ee.sun.dd.api.ejb.EnterpriseBeans enterpriseBeans) {
83         if (ejbJarRoot!=null) ejbJarRoot.setEnterpriseBeans(enterpriseBeans);
84     }
85
86     public void setSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] securityRoleMapping) {
87         if (ejbJarRoot!=null) ejbJarRoot.setSecurityRoleMapping(securityRoleMapping);
88     }
89
90     public void setSecurityRoleMapping(int param, org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping securityRoleMapping) {
91         if (ejbJarRoot!=null) ejbJarRoot.setSecurityRoleMapping(param, securityRoleMapping);
92     }
93
94     public int sizeSecurityRoleMapping() {
95          return ejbJarRoot==null?-1:ejbJarRoot.sizeSecurityRoleMapping();
96     }
97
98     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
99         if (ejbJarRoot != null)
100             ejbJarRoot.removePropertyChangeListener(pcl);
101         listeners.remove(pcl);
102     }
103
104     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
105          if (ejbJarRoot != null)
106             ejbJarRoot.addPropertyChangeListener(pcl);
107         listeners.add(pcl);
108     }
109
110     public void setVersion(java.math.BigDecimal JavaDoc version) {
111         String JavaDoc newVersion = version.toString();
112         String JavaDoc currentVersion = null;
113         if (this.version.equals(newVersion))
114             return;
115         if (ejbJarRoot != null) {
116             Document JavaDoc document = null;
117             if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar) {
118                 document =
119                         ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument();
120                 currentVersion = SunEjbJar.VERSION_2_0_0;
121             }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar) {
122                 document =
123                         ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument();
124                 currentVersion = SunEjbJar.VERSION_2_1_0;
125             }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar) {
126                 document =
127                         ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument();
128                 currentVersion = SunEjbJar.VERSION_2_1_1;
129             }else if (ejbJarRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar) {
130                 document =
131                         ((org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar)ejbJarRoot).graphManager().getXmlDocument();
132                 currentVersion = SunEjbJar.VERSION_3_0_0;
133             }
134             
135             //remove the doctype
136
document = removeDocType(document);
137             
138             if(newVersion.equals(SunEjbJar.VERSION_3_0_0)){
139                 //This will always be an upgrade
140
generate3_00Graph(document);
141             }
142             if(newVersion.equals(SunEjbJar.VERSION_2_1_1)){
143                 if(currentVersion.equals(SunEjbJar.VERSION_2_1_0) || currentVersion.equals(SunEjbJar.VERSION_2_0_0))
144                     generate2_11Graph(document);
145                 else
146                     downgradeEjbJarGraph(document, newVersion, currentVersion);
147             }
148             if(newVersion.equals(SunEjbJar.VERSION_2_1_0)){
149                 if(currentVersion.equals(SunEjbJar.VERSION_2_0_0))
150                     generate2_10Graph(document);
151                 else
152                     downgradeEjbJarGraph(document, newVersion, currentVersion);
153             }
154             if(newVersion.equals(SunEjbJar.VERSION_2_0_0)){
155                 //This will always be a downgrade
156
downgradeEjbJarGraph(document, newVersion, currentVersion);
157             }
158         }
159     }
160
161     private Document JavaDoc removeDocType(Document JavaDoc document){
162         if (document != null) {
163             org.w3c.dom.Element JavaDoc docElement = document.getDocumentElement();
164             if (docElement != null) {
165                 org.w3c.dom.DocumentType JavaDoc docType = document.getDoctype();
166                 if (docType != null) {
167                     document.removeChild(docType); //NOI18N
168
}
169             }
170         }
171         return document;
172     }
173     
174     private void downgradeEjbJarGraph(Document JavaDoc document, String JavaDoc downgradeVersion, String JavaDoc currentVersion){
175             DDTreeWalker downgradeScanner = new DDTreeWalker(document, downgradeVersion, currentVersion);
176             downgradeScanner.downgradeSunEjbJarDocument();
177             if(downgradeVersion.equals(SunEjbJar.VERSION_2_1_1)){
178                 generate2_11Graph(document);
179             }else if(downgradeVersion.equals(SunEjbJar.VERSION_2_1_0)){
180                 generate2_10Graph(document);
181             }else if(downgradeVersion.equals(SunEjbJar.VERSION_2_0_0)){
182                 generate2_00Graph(document);
183             }
184     }
185     
186     private void generate3_00Graph(Document JavaDoc document){
187         org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar ejbGraph =
188                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar.createGraph(document);
189         ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID);
190         this.ejbJarRoot = ejbGraph;
191     }
192     
193     private void generate2_11Graph(Document JavaDoc document){
194         org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar ejbGraph =
195                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar.createGraph(document);
196         ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID);
197         this.ejbJarRoot = ejbGraph;
198     }
199     
200     private void generate2_10Graph(Document JavaDoc document){
201         org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar ejbGraph =
202                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar.createGraph(document);
203         ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID);
204         this.ejbJarRoot = ejbGraph;
205     }
206     
207     private void generate2_00Graph(Document JavaDoc document){
208         org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar ejbGraph =
209                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar.createGraph(document);
210         ejbGraph.changeDocType(DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID);
211         this.ejbJarRoot = ejbGraph;
212     }
213     
214     public java.math.BigDecimal JavaDoc getVersion() {
215         return new java.math.BigDecimal JavaDoc(version);
216     }
217     
218      public void setOriginal(SunEjbJar ejbJarRoot) {
219         if (this.ejbJarRoot != ejbJarRoot) {
220             for (int i=0;i<listeners.size();i++) {
221                 java.beans.PropertyChangeListener JavaDoc pcl =
222                     (java.beans.PropertyChangeListener JavaDoc)listeners.get(i);
223                 if (this.ejbJarRoot != null)
224                     this.ejbJarRoot.removePropertyChangeListener(pcl);
225                 if (ejbJarRoot != null)
226                     ejbJarRoot.addPropertyChangeListener(pcl);
227                 
228             }
229             this.ejbJarRoot = ejbJarRoot;
230             if (ejbJarRoot != null)
231                 setProxyVersion(ejbJarRoot.getVersion().toString());
232         }
233     }
234     
235     public SunEjbJar getOriginal() {
236         return ejbJarRoot;
237     }
238     
239     public org.xml.sax.SAXParseException JavaDoc getError() {
240         return error;
241     }
242     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
243         this.error=error;
244     }
245     
246     public void setProxyVersion(java.lang.String JavaDoc value) {
247         if ((version==null && value!=null) || !version.equals(value)) {
248             java.beans.PropertyChangeEvent JavaDoc evt =
249                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_VERSION, version, value);
250             version=value;
251             for (int i=0;i<listeners.size();i++) {
252                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
253             }
254         }
255     }
256     
257     public Object JavaDoc getValue(String JavaDoc name) {
258         return ejbJarRoot==null?null:ejbJarRoot.getValue(name);
259     }
260     
261     public void write(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
262         if (ejbJarRoot!=null) {
263             ejbJarRoot.write(os);
264         }
265     }
266
267     public String JavaDoc dumpBeanNode() {
268         if (ejbJarRoot!=null)
269             return ejbJarRoot.dumpBeanNode();
270         else
271             return null;
272     }
273
274     public void setValue(String JavaDoc name, Object JavaDoc[] value) {
275         if (ejbJarRoot!=null) ejbJarRoot.setValue(name, value);
276     }
277
278     public Object JavaDoc[] getValues(String JavaDoc name) {
279         return ejbJarRoot==null?null:ejbJarRoot.getValues(name);
280     }
281
282     public void setValue(String JavaDoc name, int index, Object JavaDoc value) {
283         if (ejbJarRoot!=null) ejbJarRoot.setValue(name, index, value);
284     }
285
286     public void setValue(String JavaDoc name, Object JavaDoc value) {
287         if (ejbJarRoot!=null) ejbJarRoot.setValue(name, value);
288     }
289
290     public Object JavaDoc getValue(String JavaDoc name, int index) {
291         return ejbJarRoot==null?null:ejbJarRoot.getValue(name, index);
292     }
293
294     public String JavaDoc getAttributeValue(String JavaDoc name) {
295         return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(name);
296     }
297
298     public int size(String JavaDoc name) {
299         return ejbJarRoot==null?-1:ejbJarRoot.size(name);
300     }
301
302     public int addValue(String JavaDoc name, Object JavaDoc value) {
303         return ejbJarRoot==null?-1:ejbJarRoot.addValue(name, value);
304     }
305
306     public String JavaDoc[] findPropertyValue(String JavaDoc propName, Object JavaDoc value) {
307         return ejbJarRoot==null?null:ejbJarRoot.findPropertyValue(propName, value);
308     }
309
310     public int removeValue(String JavaDoc name, Object JavaDoc value) {
311         return ejbJarRoot==null?-1:ejbJarRoot.removeValue(name, value);
312     }
313
314     public void write(java.io.Writer JavaDoc w) throws java.io.IOException JavaDoc, DDException {
315         if (ejbJarRoot!=null) ejbJarRoot.write(w);
316     }
317
318     public void removeValue(String JavaDoc name, int index) {
319         if (ejbJarRoot!=null) ejbJarRoot.removeValue(name, index);
320     }
321
322    public Object JavaDoc clone() {
323         SunEjbJarProxy proxy = null;
324         if (ejbJarRoot==null)
325             proxy = new SunEjbJarProxy(null, version);
326         else {
327             SunEjbJar clonedSunEjb=(SunEjbJar)ejbJarRoot.clone();
328             proxy = new SunEjbJarProxy(clonedSunEjb, version);
329         }
330         proxy.setError(error);
331         return proxy;
332     }
333
334     public String JavaDoc getAttributeValue(String JavaDoc propName, String JavaDoc name) {
335         return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(propName, name);
336     }
337
338     public String JavaDoc getAttributeValue(String JavaDoc propName, int index, String JavaDoc name) {
339         return ejbJarRoot==null?null:ejbJarRoot.getAttributeValue(propName, index, name);
340     }
341
342     public void setAttributeValue(String JavaDoc name, String JavaDoc value) {
343          if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(name, value);
344     }
345
346     public void setAttributeValue(String JavaDoc propName, String JavaDoc name, String JavaDoc value) {
347         if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(propName, name, value);
348     }
349
350     public void setAttributeValue(String JavaDoc propName, int index, String JavaDoc name, String JavaDoc value) {
351         if (ejbJarRoot!=null) ejbJarRoot.setAttributeValue(propName, index, name, value);
352     }
353
354     public CommonDDBean getPropertyParent(String JavaDoc name) {
355         return ejbJarRoot.getPropertyParent(name);
356     }
357
358     public void merge(CommonDDBean root, int mode) {
359         if (root != null) {
360             if (root instanceof SunEjbJarProxy)
361                 ejbJarRoot.merge(((SunEjbJarProxy)root).getOriginal(), mode);
362             else ejbJarRoot.merge(root, mode);
363         }
364     }
365         
366     public CommonDDBean cloneVersion(String JavaDoc version) {
367         return ejbJarRoot == null ? null : ejbJarRoot.cloneVersion(version);
368     }
369    
370     /** Contract between friend modules that enables
371     * a specific handling of write(FileObject) method for targeted FileObject
372     */

373     public static interface OutputProvider {
374         public void write(SunEjbJar ejbJarRoot) throws java.io.IOException JavaDoc;
375     }
376 }
377
Popular Tags