KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > dd > impl > client > SunApplicationClientProxy


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  * SunApplicationClientProxy.java
21  *
22  * Created on February 10, 2006, 11:49 AM
23  *
24  */

25
26 package org.netbeans.modules.j2ee.sun.dd.impl.client;
27
28 import java.beans.PropertyChangeListener JavaDoc;
29 import java.io.IOException JavaDoc;
30 import java.io.OutputStream JavaDoc;
31 import java.io.Writer JavaDoc;
32 import java.math.BigDecimal JavaDoc;
33 import org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean;
34 import org.netbeans.modules.j2ee.sun.dd.api.DDException;
35 import org.netbeans.modules.j2ee.sun.dd.api.client.JavaWebStartAccess;
36 import org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient;
37 import org.netbeans.modules.j2ee.sun.dd.api.common.EjbRef;
38 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestination;
39 import org.netbeans.modules.j2ee.sun.dd.api.common.MessageDestinationRef;
40 import org.netbeans.modules.j2ee.sun.dd.api.common.ResourceEnvRef;
41 import org.netbeans.modules.j2ee.sun.dd.api.common.ResourceRef;
42 import org.netbeans.modules.j2ee.sun.dd.api.common.ServiceRef;
43 import org.netbeans.modules.j2ee.sun.dd.api.VersionNotSupportedException;
44
45 import org.w3c.dom.Document JavaDoc;
46 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry;
47 import org.netbeans.modules.j2ee.sun.dd.impl.DDTreeWalker;
48
49 /**
50  *
51  * @author Nitya Doraisamy
52  */

53 public class SunApplicationClientProxy implements SunApplicationClient {
54     
55     private SunApplicationClient appClientRoot;
56     private String JavaDoc version;
57     private OutputProvider outputProvider;
58     private int ddStatus;
59     private org.xml.sax.SAXParseException JavaDoc error;
60     private java.util.List JavaDoc listeners;
61     
62     /** Creates a new instance of SunApplicationProxy */
63     public SunApplicationClientProxy(SunApplicationClient appClientRoot, String JavaDoc version) {
64         this.appClientRoot = appClientRoot;
65         this.version = version;
66     }
67
68     public void setEjbRef(int index, EjbRef value) {
69         if (appClientRoot != null) appClientRoot.setEjbRef(index, value);
70     }
71
72     public EjbRef getEjbRef(int index) {
73         return appClientRoot == null?null:appClientRoot.getEjbRef(index);
74     }
75
76     public int sizeEjbRef() {
77         return appClientRoot == null?-1:appClientRoot.sizeEjbRef();
78     }
79
80     public void setEjbRef(EjbRef[] value) {
81         if (appClientRoot != null) appClientRoot.setEjbRef(value);
82     }
83
84     public EjbRef[] getEjbRef() {
85         return appClientRoot == null?null:appClientRoot.getEjbRef();
86     }
87
88     public int addEjbRef(EjbRef value) {
89         return appClientRoot == null?-1:appClientRoot.addEjbRef(value);
90     }
91
92     public int removeEjbRef(EjbRef value) {
93         return appClientRoot == null?-1:appClientRoot.removeEjbRef(value);
94     }
95
96     public EjbRef newEjbRef() {
97         return appClientRoot == null?null:appClientRoot.newEjbRef();
98     }
99
100     public void setResourceRef(int index, ResourceRef value) {
101         if (appClientRoot != null) appClientRoot.setResourceRef(index, value);
102     }
103
104     public ResourceRef getResourceRef(int index) {
105         return appClientRoot == null?null:appClientRoot.getResourceRef(index);
106     }
107
108     public int sizeResourceRef() {
109         return appClientRoot == null?-1:appClientRoot.sizeResourceRef();
110     }
111
112     public void setResourceRef(ResourceRef[] value) {
113         if (appClientRoot != null) appClientRoot.setResourceRef(value);
114     }
115
116     public ResourceRef[] getResourceRef() {
117         return appClientRoot == null?null:appClientRoot.getResourceRef();
118     }
119
120     public int addResourceRef(ResourceRef value) {
121         return appClientRoot == null?-1:appClientRoot.addResourceRef(value);
122     }
123
124     public int removeResourceRef(ResourceRef value) {
125         return appClientRoot == null?-1:appClientRoot.removeResourceRef(value);
126     }
127
128     public ResourceRef newResourceRef() {
129         return appClientRoot == null?null:appClientRoot.newResourceRef();
130     }
131
132     public void setResourceEnvRef(int index, ResourceEnvRef value) {
133         if (appClientRoot != null) appClientRoot.setResourceEnvRef(index, value);
134     }
135
136     public ResourceEnvRef getResourceEnvRef(int index) {
137         return appClientRoot == null?null:appClientRoot.getResourceEnvRef(index);
138     }
139
140     public int sizeResourceEnvRef() {
141         return appClientRoot == null?-1:appClientRoot.sizeResourceEnvRef();
142     }
143
144     public void setResourceEnvRef(ResourceEnvRef[] value) {
145         if (appClientRoot != null) appClientRoot.setResourceEnvRef(value);
146     }
147
148     public ResourceEnvRef[] getResourceEnvRef() {
149         return appClientRoot == null?null:appClientRoot.getResourceEnvRef();
150     }
151
152     public int addResourceEnvRef(ResourceEnvRef value) {
153         return appClientRoot == null?-1:appClientRoot.addResourceEnvRef(value);
154     }
155
156     public int removeResourceEnvRef(ResourceEnvRef value) {
157         return appClientRoot == null?-1:appClientRoot.removeResourceEnvRef(value);
158     }
159
160     public ResourceEnvRef newResourceEnvRef() {
161         return appClientRoot == null?null:appClientRoot.newResourceEnvRef();
162     }
163
164     public void setServiceRef(int index, ServiceRef value) {
165         if (appClientRoot != null) appClientRoot.setServiceRef(index, value);
166     }
167
168     public ServiceRef getServiceRef(int index) {
169         return appClientRoot == null?null:appClientRoot.getServiceRef(index);
170     }
171
172     public int sizeServiceRef() {
173         return appClientRoot == null?-1:appClientRoot.sizeServiceRef();
174     }
175
176     public void setServiceRef(ServiceRef[] value) {
177         if (appClientRoot != null) appClientRoot.setServiceRef(value);
178     }
179
180     public ServiceRef[] getServiceRef() {
181         return appClientRoot == null?null:appClientRoot.getServiceRef();
182     }
183
184     public int addServiceRef(ServiceRef value) {
185         return appClientRoot == null?-1:appClientRoot.addServiceRef(value);
186     }
187
188     public int removeServiceRef(ServiceRef value) {
189         return appClientRoot == null?-1:appClientRoot.removeServiceRef(value);
190     }
191
192     public ServiceRef newServiceRef() {
193         return appClientRoot == null?null:appClientRoot.newServiceRef();
194     }
195
196     public void setMessageDestinationRef(int index, MessageDestinationRef value) throws VersionNotSupportedException {
197         if (appClientRoot != null) appClientRoot.setMessageDestinationRef(index, value);
198     }
199
200     public MessageDestinationRef getMessageDestinationRef(int index) throws VersionNotSupportedException {
201         return appClientRoot == null?null:appClientRoot.getMessageDestinationRef(index);
202     }
203
204     public int sizeMessageDestinationRef() throws VersionNotSupportedException {
205         return appClientRoot == null?-1:appClientRoot.sizeMessageDestinationRef();
206     }
207
208     public void setMessageDestinationRef(MessageDestinationRef[] value) throws VersionNotSupportedException {
209         if (appClientRoot != null) appClientRoot.setMessageDestinationRef(value);
210     }
211
212     public MessageDestinationRef[] getMessageDestinationRef() throws VersionNotSupportedException {
213         return appClientRoot == null?null:appClientRoot.getMessageDestinationRef();
214     }
215
216     public int addMessageDestinationRef(MessageDestinationRef value) throws VersionNotSupportedException {
217         return appClientRoot == null?-1:appClientRoot.addMessageDestinationRef(value);
218     }
219
220     public int removeMessageDestinationRef(MessageDestinationRef value) throws VersionNotSupportedException {
221         return appClientRoot == null?-1:appClientRoot.removeMessageDestinationRef(value);
222     }
223
224     public MessageDestinationRef newMessageDestinationRef() throws VersionNotSupportedException {
225         return appClientRoot == null?null:appClientRoot.newMessageDestinationRef();
226     }
227
228     public void setMessageDestination(int index, MessageDestination value) {
229         if (appClientRoot != null) appClientRoot.setMessageDestination(index, value);
230     }
231
232     public MessageDestination getMessageDestination(int index) {
233         return appClientRoot == null?null:appClientRoot.getMessageDestination(index);
234     }
235
236     public int sizeMessageDestination() {
237         return appClientRoot == null?-1:appClientRoot.sizeMessageDestination();
238     }
239
240     public void setMessageDestination(MessageDestination[] value) {
241         if (appClientRoot != null) appClientRoot.setMessageDestination(value);
242     }
243
244     public MessageDestination[] getMessageDestination() {
245         return appClientRoot == null?null:appClientRoot.getMessageDestination();
246     }
247
248     public int addMessageDestination(MessageDestination value) {
249         return appClientRoot == null?-1:appClientRoot.addMessageDestination(value);
250     }
251
252     public int removeMessageDestination(MessageDestination value) {
253         return appClientRoot == null?-1:appClientRoot.removeMessageDestination(value);
254     }
255
256     public MessageDestination newMessageDestination() {
257         return appClientRoot == null?null:appClientRoot.newMessageDestination();
258     }
259
260     public void setJavaWebStartAccess(JavaWebStartAccess value) throws VersionNotSupportedException {
261         if (appClientRoot != null) appClientRoot.setJavaWebStartAccess(value);
262     }
263
264     public JavaWebStartAccess getJavaWebStartAccess() throws VersionNotSupportedException {
265         return appClientRoot == null?null:appClientRoot.getJavaWebStartAccess();
266     }
267
268     public JavaWebStartAccess newJavaWebStartAccess() throws VersionNotSupportedException {
269         return appClientRoot == null?null:appClientRoot.newJavaWebStartAccess();
270     }
271
272     public void setVersion(BigDecimal JavaDoc version) {
273         String JavaDoc newVersion = version.toString();
274         String JavaDoc currentVersion = null;
275         if (this.version.equals(newVersion))
276             return;
277         if (appClientRoot != null) {
278             Document JavaDoc document = null;
279             if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient) {
280                 document =
281                         ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
282                 currentVersion = SunApplicationClient.VERSION_1_3_0;
283             }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient) {
284                 document =
285                         ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
286                 currentVersion = SunApplicationClient.VERSION_1_4_0;
287             }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient) {
288                 document =
289                         ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
290                 currentVersion = SunApplicationClient.VERSION_1_4_1;
291             }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient) {
292                 document =
293                         ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
294                 currentVersion = SunApplicationClient.VERSION_5_0_0;
295             }
296             
297             //remove the doctype
298
document = removeDocType(document);
299             
300             if(newVersion.equals(SunApplicationClient.VERSION_5_0_0)){
301                 //This will always be an upgrade
302
generate5_00Graph(document);
303             }
304             if(newVersion.equals(SunApplicationClient.VERSION_1_4_1)){
305                 if(currentVersion.equals(SunApplicationClient.VERSION_1_4_0) || currentVersion.equals(SunApplicationClient.VERSION_1_3_0))
306                     generate1_41Graph(document);
307                 else
308                     downgradeClientJarGraph(document, newVersion, currentVersion);
309             }
310             if(newVersion.equals(SunApplicationClient.VERSION_1_4_0)){
311                 if(currentVersion.equals(SunApplicationClient.VERSION_1_3_0))
312                     generate1_40Graph(document);
313                 else
314                     downgradeClientJarGraph(document, newVersion, currentVersion);
315             }
316             if(newVersion.equals(SunApplicationClient.VERSION_1_3_0)){
317                 //This will always be a downgrade
318
downgradeClientJarGraph(document, newVersion, currentVersion);
319             }
320         }
321     }
322
323     private void downgradeClientJarGraph(Document JavaDoc document, String JavaDoc downgradeVersion, String JavaDoc currentVersion){
324             DDTreeWalker downgradeScanner = new DDTreeWalker(document, downgradeVersion, currentVersion);
325             downgradeScanner.downgradeSunClientDocument();
326             if(downgradeVersion.equals(SunApplicationClient.VERSION_1_4_1)){
327                 generate1_41Graph(document);
328             }else if(downgradeVersion.equals(SunApplicationClient.VERSION_1_4_0)){
329                 generate1_40Graph(document);
330             }else if(downgradeVersion.equals(SunApplicationClient.VERSION_1_3_0)){
331                 generate1_30Graph(document);
332             }
333     }
334     
335     private void generate5_00Graph(Document JavaDoc document){
336         org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient appClientGraph =
337                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient.createGraph(document);
338         appClientGraph.changeDocType(DTDRegistry.SUN_APPCLIENT_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_50_DTD_SYSTEM_ID);
339         this.appClientRoot = appClientGraph;
340     }
341     
342     private void generate1_41Graph(Document JavaDoc document){
343         org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient appClientGraph =
344                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient.createGraph(document);
345         appClientGraph.changeDocType(DTDRegistry.SUN_APPCLIENT_141_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_141_DTD_SYSTEM_ID);
346         this.appClientRoot = appClientGraph;
347     }
348     
349     private void generate1_40Graph(Document JavaDoc document){
350         org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient appClientGraph =
351                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient.createGraph(document);
352         appClientGraph.changeDocType(DTDRegistry.SUN_APPCLIENT_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_140_DTD_SYSTEM_ID);
353         this.appClientRoot = appClientGraph;
354     }
355     
356     private void generate1_30Graph(Document JavaDoc document){
357         org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient appClientGraph =
358                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient.createGraph(document);
359         appClientGraph.changeDocType(DTDRegistry.SUN_APPCLIENT_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_130_DTD_SYSTEM_ID);
360         this.appClientRoot = appClientGraph;
361     }
362     
363     public BigDecimal JavaDoc getVersion() {
364         return new java.math.BigDecimal JavaDoc(version);
365     }
366
367     private Document JavaDoc getDocument(){
368         Document JavaDoc document = null;
369         if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient) {
370             document =
371                     ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
372         }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient) {
373             document =
374                     ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
375         }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient) {
376             document =
377                     ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
378         }else if (appClientRoot instanceof org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient) {
379             document =
380                     ((org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient)appClientRoot).graphManager().getXmlDocument();
381         }
382         return document;
383     }
384     
385     private Document JavaDoc removeDocType(Document JavaDoc document){
386         if (document != null) {
387             org.w3c.dom.Element JavaDoc docElement = document.getDocumentElement();
388             if (docElement != null) {
389                 org.w3c.dom.DocumentType JavaDoc docType = document.getDoctype();
390                 if (docType != null) {
391                     document.removeChild(docType); //NOI18N
392
}
393             }
394         }
395         return document;
396     }
397     public void merge(CommonDDBean root, int mode) {
398         if (appClientRoot != null) {
399             if (root instanceof SunApplicationClientProxy)
400                 appClientRoot.merge(((SunApplicationClientProxy)root).getOriginal(), mode);
401             else appClientRoot.merge(root, mode);
402         }
403     }
404
405     public CommonDDBean cloneVersion(String JavaDoc version) {
406         return appClientRoot == null ? null : appClientRoot.cloneVersion(version);
407     }
408    
409     public SunApplicationClient getOriginal() {
410         return appClientRoot;
411     }
412     
413     public void addPropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
414         if (appClientRoot != null)
415             appClientRoot.addPropertyChangeListener(pcl);
416         listeners.add(pcl);
417     }
418
419     public void removePropertyChangeListener(PropertyChangeListener JavaDoc pcl) {
420         if (appClientRoot != null)
421             appClientRoot.removePropertyChangeListener(pcl);
422         listeners.remove(pcl);
423     }
424
425     public Object JavaDoc getValue(String JavaDoc propertyName) {
426         return appClientRoot == null?null:appClientRoot.getValue(propertyName);
427     }
428
429     public Object JavaDoc[] getValues(String JavaDoc name) {
430         return appClientRoot == null?null:appClientRoot.getValues(name);
431     }
432
433     public Object JavaDoc getValue(String JavaDoc name, int index) {
434         return appClientRoot == null?null:appClientRoot.getValue(name, index);
435     }
436
437     public void setValue(String JavaDoc name, Object JavaDoc value) {
438         if (appClientRoot != null) appClientRoot.setValue(name, value);
439     }
440
441     public void setValue(String JavaDoc name, Object JavaDoc[] value) {
442         if (appClientRoot != null) appClientRoot.setValue(name, value);
443     }
444
445     public void setValue(String JavaDoc name, int index, Object JavaDoc value) {
446         if (appClientRoot != null) appClientRoot.setValue(name, index, value);
447     }
448
449     public String JavaDoc getAttributeValue(String JavaDoc name) {
450         return appClientRoot == null?null:appClientRoot.getAttributeValue(name);
451     }
452
453     public String JavaDoc getAttributeValue(String JavaDoc propName, String JavaDoc name) {
454         return appClientRoot == null?null:appClientRoot.getAttributeValue(propName, name);
455     }
456
457     public String JavaDoc getAttributeValue(String JavaDoc propName, int index, String JavaDoc name) {
458         return appClientRoot == null?null:appClientRoot.getAttributeValue(propName, index, name);
459     }
460
461     public void setAttributeValue(String JavaDoc name, String JavaDoc value) {
462         if (appClientRoot != null) appClientRoot.setAttributeValue(name, value);
463     }
464
465     public void setAttributeValue(String JavaDoc propName, int index, String JavaDoc name, String JavaDoc value) {
466         if (appClientRoot != null) appClientRoot.setAttributeValue(propName, index, name, value);
467     }
468
469     public void setAttributeValue(String JavaDoc propName, String JavaDoc name, String JavaDoc value) {
470         if (appClientRoot != null) appClientRoot.setAttributeValue(propName, name, value);
471     }
472
473     public String JavaDoc[] findPropertyValue(String JavaDoc propName, Object JavaDoc value) {
474         return appClientRoot == null?null:appClientRoot.findPropertyValue(propName, value);
475     }
476
477     public int addValue(String JavaDoc name, Object JavaDoc value) {
478         return appClientRoot == null?-1:appClientRoot.addValue(name, value);
479     }
480
481     public int removeValue(String JavaDoc name, Object JavaDoc value) {
482         return appClientRoot == null?-1:appClientRoot.removeValue(name, value);
483     }
484
485     public void removeValue(String JavaDoc name, int index) {
486         if (appClientRoot != null) appClientRoot.removeValue(name, index);
487     }
488
489     public void write(OutputStream JavaDoc os) throws IOException JavaDoc {
490         if (appClientRoot != null) {
491             appClientRoot.write(os);
492         }
493     }
494
495     public void write(Writer JavaDoc w) throws IOException JavaDoc, DDException {
496         if (appClientRoot != null) appClientRoot.write(w);
497     }
498
499     public String JavaDoc dumpBeanNode() {
500         if (appClientRoot != null)
501             return appClientRoot.dumpBeanNode();
502         else
503             return null;
504     }
505
506     public CommonDDBean getPropertyParent(String JavaDoc name) {
507         return appClientRoot.getPropertyParent(name);
508     }
509     
510     public Object JavaDoc clone() {
511         SunApplicationClientProxy proxy = null;
512         if (appClientRoot == null)
513             proxy = new SunApplicationClientProxy(null, version);
514         else {
515             SunApplicationClient clonedSunAppClient=(SunApplicationClient)appClientRoot.clone();
516             proxy = new SunApplicationClientProxy(clonedSunAppClient, version);
517         }
518         proxy.setError(error);
519         return proxy;
520     }
521     
522     public org.xml.sax.SAXParseException JavaDoc getError() {
523         return error;
524     }
525     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
526         this.error=error;
527     }
528
529     public int size(String JavaDoc name) {
530         return appClientRoot == null?-1:appClientRoot.size(name);
531     }
532     /** Contract between friend modules that enables
533     * a specific handling of write(FileObject) method for targeted FileObject
534     */

535     public static interface OutputProvider {
536         public void write(SunApplicationClient appClientRoot) throws java.io.IOException JavaDoc;
537     }
538     
539 }
540
Popular Tags