KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > dd > impl > app > SunApplicationProxy


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  * SunApplicationProxy.java
21  *
22  * Created on February 7, 2005, 9:14 PM
23  */

24
25 package org.netbeans.modules.j2ee.sun.dd.impl.app;
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.app.SunApplication;
30 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry;
31
32 import org.w3c.dom.Document JavaDoc;
33 /**
34  *
35  * @author Nitya Doraisamy
36  */

37 public class SunApplicationProxy implements SunApplication {
38
39     private SunApplication appRoot;
40     private String JavaDoc version;
41     private OutputProvider outputProvider;
42     private int ddStatus;
43     private org.xml.sax.SAXParseException JavaDoc error;
44     private java.util.List JavaDoc listeners;
45     
46     /** Creates a new instance of SunApplicationProxy */
47     public SunApplicationProxy(SunApplication appRoot, String JavaDoc version) {
48         this.appRoot = appRoot;
49         this.version = version;
50     }
51
52     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
53         if (appRoot != null)
54             appRoot.addPropertyChangeListener(pcl);
55         listeners.add(pcl);
56     }
57
58     public int addSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping value) {
59         return appRoot==null?-1:appRoot.addSecurityRoleMapping(value);
60     }
61
62     public int addWeb(org.netbeans.modules.j2ee.sun.dd.api.app.Web value) {
63         return appRoot==null?-1:appRoot.addWeb(value);
64     }
65
66     public String JavaDoc dumpBeanNode() {
67         return appRoot==null?null:appRoot.dumpBeanNode();
68     }
69
70     public String JavaDoc getPassByReference() {
71         return appRoot==null?null:appRoot.getPassByReference();
72     }
73
74     public String JavaDoc getRealm() {
75         return appRoot==null?null:appRoot.getRealm();
76     }
77
78     public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] getSecurityRoleMapping() {
79         return appRoot==null?null:appRoot.getSecurityRoleMapping();
80     }
81
82     public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping getSecurityRoleMapping(int index) {
83         return appRoot==null?null:appRoot.getSecurityRoleMapping(index);
84     }
85
86     public String JavaDoc getUniqueId() {
87         return appRoot==null?null:appRoot.getUniqueId();
88     }
89
90     public Object JavaDoc getValue(String JavaDoc propertyName) {
91         return appRoot==null?null:appRoot.getValue(propertyName);
92     }
93
94     public java.math.BigDecimal JavaDoc getVersion() {
95         return new java.math.BigDecimal JavaDoc(version);
96     }
97
98     public org.netbeans.modules.j2ee.sun.dd.api.app.Web[] getWeb() {
99         return appRoot==null?null:appRoot.getWeb();
100     }
101
102     public org.netbeans.modules.j2ee.sun.dd.api.app.Web getWeb(int index) {
103         return appRoot==null?null:appRoot.getWeb(index);
104     }
105
106     public org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping newSecurityRoleMapping() {
107         return appRoot==null?null:appRoot.newSecurityRoleMapping();
108     }
109
110     public org.netbeans.modules.j2ee.sun.dd.api.app.Web newWeb() {
111         return appRoot==null?null:appRoot.newWeb();
112     }
113
114     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
115         if (appRoot != null)
116             appRoot.removePropertyChangeListener(pcl);
117         listeners.remove(pcl);
118     }
119
120     public int removeSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping value) {
121         return appRoot==null?-1:appRoot.removeSecurityRoleMapping(value);
122     }
123
124     public int removeWeb(org.netbeans.modules.j2ee.sun.dd.api.app.Web value) {
125         return appRoot==null?-1:appRoot.removeWeb(value);
126     }
127
128     public void setPassByReference(String JavaDoc value) {
129         if (appRoot!=null) appRoot.setPassByReference(value);
130     }
131
132     public void setRealm(String JavaDoc value) {
133         if (appRoot!=null) appRoot.setRealm(value);
134     }
135
136     public void setSecurityRoleMapping(org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping[] value) {
137         if (appRoot!=null) appRoot.setSecurityRoleMapping(value);
138     }
139
140     public void setSecurityRoleMapping(int index, org.netbeans.modules.j2ee.sun.dd.api.common.SecurityRoleMapping value) {
141         if (appRoot!=null) appRoot.setSecurityRoleMapping(index, value);
142     }
143
144     public void setUniqueId(String JavaDoc value) {
145         if (appRoot!=null) appRoot.setUniqueId(value);
146     }
147
148     public void setVersion(java.math.BigDecimal JavaDoc version) {
149         String JavaDoc newVersion = version.toString();
150         
151         if (this.version.equals(newVersion))
152             return;
153         if (appRoot != null) {
154             Document JavaDoc document = null;
155             if(newVersion.equals(SunApplication.VERSION_5_0_0)){
156                 //This will always be an upgrade
157
document = getDocument();
158                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication appGraph =
159                         org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication.createGraph(document);
160                 appGraph.changeDocType(DTDRegistry.SUN_APPLICATION_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_50_DTD_SYSTEM_ID);
161                 this.appRoot = appGraph;
162             }
163             if(newVersion.equals(SunApplication.VERSION_1_4_0)){
164                 document = getDocument();
165                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication appGraph =
166                         org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication.createGraph(document);
167                 appGraph.changeDocType(DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140_DTD_SYSTEM_ID);
168                 this.appRoot = appGraph;
169             }
170             if(newVersion.equals(SunApplication.VERSION_1_3_0)){
171                 appRoot.setRealm(null);
172                 document = getDocument();
173                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication appGraph =
174                         org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication.createGraph(document);
175                 appGraph.changeDocType(DTDRegistry.SUN_APPCLIENT_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_130_DTD_SYSTEM_ID);
176                 this.appRoot = appGraph;
177             }
178         }
179     }
180
181     private Document JavaDoc getDocument(){
182         Document JavaDoc document = null;
183         if (appRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication) {
184             document =
185                     ((org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication)appRoot).graphManager().getXmlDocument();
186         }else if (appRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication) {
187             document =
188                     ((org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication)appRoot).graphManager().getXmlDocument();
189         }else if (appRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication) {
190             document =
191                     ((org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication)appRoot).graphManager().getXmlDocument();
192         }
193         return document;
194     }
195     
196     public void setWeb(org.netbeans.modules.j2ee.sun.dd.api.app.Web[] value) {
197         if (appRoot!=null) appRoot.setWeb(value);
198     }
199
200     public void setWeb(int index, org.netbeans.modules.j2ee.sun.dd.api.app.Web value) {
201         if (appRoot!=null) appRoot.setWeb(index, value);
202     }
203
204     public int sizeSecurityRoleMapping() {
205         return appRoot==null?-1:appRoot.sizeSecurityRoleMapping();
206     }
207
208     public int sizeWeb() {
209         return appRoot==null?-1:appRoot.sizeWeb();
210     }
211
212     public void write(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
213         if (appRoot!=null) {
214             appRoot.write(os);
215         }
216     }
217  
218     public SunApplication getOriginal() {
219         return appRoot;
220     }
221     
222     public org.xml.sax.SAXParseException JavaDoc getError() {
223         return error;
224     }
225     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
226         this.error = error;
227     }
228
229     public void setValue(String JavaDoc name, Object JavaDoc[] value) {
230         if (appRoot!=null) appRoot.setValue(name, value);
231     }
232
233     public Object JavaDoc[] getValues(String JavaDoc name) {
234         return appRoot==null?null:appRoot.getValues(name);
235     }
236
237     public void setValue(String JavaDoc name, int index, Object JavaDoc value) {
238         if (appRoot!=null) appRoot.setValue(name, index, value);
239     }
240
241     public void setValue(String JavaDoc name, Object JavaDoc value) {
242         if (appRoot!=null) appRoot.setValue(name, value);
243     }
244
245     public Object JavaDoc getValue(String JavaDoc name, int index) {
246         return appRoot==null?null:appRoot.getValue(name, index);
247     }
248
249     public String JavaDoc getAttributeValue(String JavaDoc name) {
250         return appRoot==null?null:appRoot.getAttributeValue(name);
251     }
252
253     public int size(String JavaDoc name) {
254         return appRoot==null?-1:appRoot.size(name);
255     }
256
257     public int addValue(String JavaDoc name, Object JavaDoc value) {
258         return appRoot==null?-1:appRoot.addValue(name, value);
259     }
260
261     public String JavaDoc[] findPropertyValue(String JavaDoc propName, Object JavaDoc value) {
262         return appRoot==null?null:appRoot.findPropertyValue(propName, value);
263     }
264
265     public int removeValue(String JavaDoc name, Object JavaDoc value) {
266         return appRoot==null?-1:appRoot.removeValue(name, value);
267     }
268
269     public void write(java.io.Writer JavaDoc w) throws java.io.IOException JavaDoc, org.netbeans.modules.j2ee.sun.dd.api.DDException {
270         if (appRoot!=null) appRoot.write(w);
271     }
272     
273     public void removeValue(String JavaDoc name, int index) {
274         if (appRoot!=null) appRoot.removeValue(name, index);
275     }
276
277     public Object JavaDoc clone() {
278         SunApplicationProxy proxy = null;
279         if (appRoot==null)
280             proxy = new SunApplicationProxy(null, version);
281         else {
282             SunApplication clonedSunApp=(SunApplication)appRoot.clone();
283             proxy = new SunApplicationProxy(clonedSunApp, version);
284         }
285         proxy.setError(error);
286         return proxy;
287     }
288
289     public String JavaDoc getAttributeValue(String JavaDoc propName, String JavaDoc name) {
290         return appRoot==null?null:appRoot.getAttributeValue(propName, name);
291     }
292
293     public String JavaDoc getAttributeValue(String JavaDoc propName, int index, String JavaDoc name) {
294         return appRoot==null?null:appRoot.getAttributeValue(propName, index, name);
295     }
296
297     public void setAttributeValue(String JavaDoc name, String JavaDoc value) {
298         if (appRoot!=null) appRoot.setAttributeValue(name, value);
299     }
300
301     public void setAttributeValue(String JavaDoc propName, String JavaDoc name, String JavaDoc value) {
302         if (appRoot!=null) appRoot.setAttributeValue(propName, name, value);
303     }
304
305     public void setAttributeValue(String JavaDoc propName, int index, String JavaDoc name, String JavaDoc value) {
306         if (appRoot!=null) appRoot.setAttributeValue(propName, index, name, value);
307     }
308
309     public CommonDDBean getPropertyParent(String JavaDoc name) {
310         return appRoot.getPropertyParent(name);
311     }
312     
313     public void merge(CommonDDBean root, int mode) {
314         if (root != null) {
315             if (root instanceof SunApplicationProxy)
316                 appRoot.merge(((SunApplicationProxy)root).getOriginal(), mode);
317             else appRoot.merge(root, mode);
318         }
319     }
320     
321     public CommonDDBean cloneVersion(String JavaDoc version) {
322         return appRoot == null ? null : appRoot.cloneVersion(version);
323     }
324    
325     public static interface OutputProvider {
326         public void write(SunApplication appRoot) throws java.io.IOException JavaDoc;
327     }
328 }
329
Popular Tags