KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > dd > impl > webservices > WebServicesProxy


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  * WebservicesProxy.java
21  *
22  * Created on August 27, 2004, 2:47 PM
23  */

24
25 package org.netbeans.modules.j2ee.dd.impl.webservices;
26
27 /**
28  *
29  * @author Nitya Doraisamy
30  */

31 import org.netbeans.modules.j2ee.dd.api.webservices.Webservices;
32
33 public class WebServicesProxy implements Webservices {
34     private Webservices webSvc;
35     private String JavaDoc version;
36     private java.util.List JavaDoc listeners;
37     public boolean writing = false;
38     private org.xml.sax.SAXParseException JavaDoc error;
39     private int ddStatus;
40
41     /** Creates a new instance of WebservicesProxy */
42     public WebServicesProxy(Webservices webService, String JavaDoc version) {
43         this.webSvc = webService;
44         this.version = version;
45         listeners = new java.util.ArrayList JavaDoc();
46     }
47
48     public void setOriginal(Webservices webSvc) {
49         if (this.webSvc != webSvc) {
50             for (int i=0;i<listeners.size();i++) {
51                 java.beans.PropertyChangeListener JavaDoc pcl =
52                     (java.beans.PropertyChangeListener JavaDoc)listeners.get(i);
53                 if (this.webSvc != null) this.webSvc.removePropertyChangeListener(pcl);
54                 if (webSvc != null) webSvc.addPropertyChangeListener(pcl);
55                 
56             }
57             this.webSvc = webSvc;
58             if (webSvc != null) setProxyVersion(webSvc.getVersion().toString());
59         }
60     }
61     
62     public Webservices getOriginal() {
63         return webSvc;
64     }
65     
66     public void setProxyVersion(java.lang.String JavaDoc value) {
67         if ((version == null && value != null) || !version.equals(value)) {
68             java.beans.PropertyChangeEvent JavaDoc evt =
69                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_VERSION, version, value);
70             version = value;
71             for (int i=0;i<listeners.size();i++) {
72                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
73             }
74         }
75     }
76     
77     public org.xml.sax.SAXParseException JavaDoc getError() {
78         return error;
79     }
80
81     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
82         this.error = error;
83     }
84      
85     public int getStatus() {
86         return ddStatus;
87     }
88
89     public void setStatus(int value) {
90         if (ddStatus != value) {
91             java.beans.PropertyChangeEvent JavaDoc evt =
92                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_STATUS, new Integer JavaDoc(ddStatus), new Integer JavaDoc(value));
93             ddStatus = value;
94             for (int i=0;i<listeners.size();i++) {
95                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
96             }
97         }
98     }
99     
100     public java.math.BigDecimal JavaDoc getVersion() {
101         return new java.math.BigDecimal JavaDoc(version);
102     }
103
104     public int addWebserviceDescription(org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription value) {
105         if(webSvc == null)
106             return -1;
107         else
108             return webSvc.addWebserviceDescription(value);
109     }
110
111      
112     public org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription[] getWebserviceDescription() {
113         if(webSvc == null)
114             return new org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription[0];
115         else
116             return webSvc.getWebserviceDescription();
117     }
118
119     public org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription getWebserviceDescription(int index) {
120         if(webSvc == null)
121             return null;
122         else
123             return webSvc.getWebserviceDescription(index);
124     }
125
126     public org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription newWebserviceDescription() {
127         if(webSvc == null)
128             return null;
129         else
130             return webSvc.newWebserviceDescription();
131     }
132
133     public int removeWebserviceDescription(org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription value) {
134         if(webSvc == null)
135             return -1;
136         else
137             return webSvc.removeWebserviceDescription(value);
138     }
139
140     public void setWebserviceDescription(org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription[] value) {
141         if(webSvc != null){
142             webSvc.setWebserviceDescription(value);
143         }
144     }
145
146     public void setWebserviceDescription(int index, org.netbeans.modules.j2ee.dd.api.webservices.WebserviceDescription value) {
147         if(webSvc != null){
148             webSvc.setWebserviceDescription(index, value);
149         }
150     }
151
152     public int sizeWebserviceDescription() {
153         if(webSvc == null)
154             return 0;
155         else
156             return webSvc.sizeWebserviceDescription();
157     }
158     
159     
160     public Object JavaDoc getValue(String JavaDoc name) {
161         if(webSvc == null)
162             return null;
163         else
164             return webSvc.getValue(name);
165     }
166     
167     public java.lang.String JavaDoc getId() {
168         if(webSvc == null)
169             return null;
170         else
171             return webSvc.getId();
172     }
173     
174     public void setId(java.lang.String JavaDoc value) {
175         if(webSvc != null) {
176             webSvc.setId(value);
177         }
178     }
179    
180     public java.util.Map JavaDoc getAllDescriptions() {
181         return webSvc==null?new java.util.HashMap JavaDoc():webSvc.getAllDescriptions();
182     }
183     
184     public String JavaDoc getDescription(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
185         return webSvc==null?null:webSvc.getDescription(locale);
186     }
187      
188     public String JavaDoc getDefaultDescription() {
189         return webSvc==null?null:webSvc.getDefaultDescription();
190     }
191     
192     public java.util.Map JavaDoc getAllDisplayNames() {
193         return webSvc==null?new java.util.HashMap JavaDoc():webSvc.getAllDisplayNames();
194     }
195     
196     public String JavaDoc getDefaultDisplayName() {
197         return webSvc==null?null:webSvc.getDefaultDisplayName();
198     }
199     
200     public String JavaDoc getDisplayName(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
201         return webSvc==null?null:webSvc.getDisplayName(locale);
202     }
203     
204     public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() {
205         return webSvc==null?null:webSvc.getDefaultIcon();
206     }
207     
208     public java.util.Map JavaDoc getAllIcons() {
209         return webSvc==null?new java.util.HashMap JavaDoc():webSvc.getAllIcons();
210     }
211     
212     public String JavaDoc getLargeIcon() {
213         return webSvc==null?null:webSvc.getLargeIcon();
214     }
215     
216     public String JavaDoc getLargeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
217         return webSvc==null?null:webSvc.getLargeIcon(locale);
218     }
219     
220     public String JavaDoc getSmallIcon() {
221         return webSvc==null?null:webSvc.getSmallIcon();
222     }
223     
224     public String JavaDoc getSmallIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
225         return webSvc==null?null:webSvc.getSmallIcon(locale);
226     }
227     
228     public void removeAllDescriptions() {
229         if (webSvc!=null) webSvc.removeAllDescriptions();
230     }
231     
232     public void removeDescription() {
233         if (webSvc!=null) webSvc.removeDescription();
234     }
235     
236     public void removeDescriptionForLocale(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
237         if (webSvc!=null) webSvc.removeDescriptionForLocale(locale);
238     }
239     
240     public void removeAllDisplayNames() {
241         if (webSvc!=null) webSvc.removeAllDisplayNames();
242     }
243     
244     public void removeDisplayName() {
245         if (webSvc!=null) webSvc.removeDisplayName();
246     }
247     
248     public void removeDisplayNameForLocale(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
249         if (webSvc!=null) webSvc.removeDisplayNameForLocale(locale);
250     }
251     
252     public void removeAllIcons() {
253         if (webSvc!=null) webSvc.removeAllIcons();
254     }
255     
256     public void removeIcon() {
257         if (webSvc!=null) webSvc.removeIcon();
258     }
259     
260     public void removeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
261         if (webSvc!=null) webSvc.removeIcon(locale);
262     }
263     
264     public void removeLargeIcon() {
265         if (webSvc!=null) webSvc.removeLargeIcon();
266     }
267     
268     public void removeLargeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
269         if (webSvc!=null) webSvc.removeLargeIcon(locale);
270     }
271     
272     public void removeSmallIcon() {
273         if (webSvc!=null) webSvc.removeSmallIcon();
274     }
275     
276     public void removeSmallIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
277         if (webSvc!=null) webSvc.removeSmallIcon(locale);
278     }
279     
280     public void setAllDescriptions(java.util.Map JavaDoc descriptions) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
281         if (webSvc!=null) webSvc.setAllDescriptions(descriptions);
282     }
283     
284     public void setDescription(String JavaDoc description) {
285         if (webSvc!=null) webSvc.setDescription(description);
286     }
287     
288     public void setDescription(String JavaDoc locale, String JavaDoc description) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
289         if (webSvc!=null) webSvc.setDescription(locale, description);
290     }
291     
292     public void setAllDisplayNames(java.util.Map JavaDoc displayNames) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
293         if (webSvc!=null) webSvc.setAllDisplayNames(displayNames);
294     }
295     
296     public void setDisplayName(String JavaDoc displayName) {
297         if (webSvc!=null) webSvc.setDisplayName(displayName);
298     }
299     
300     public void setDisplayName(String JavaDoc locale, String JavaDoc displayName) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
301         if (webSvc!=null) webSvc.setDisplayName(locale, displayName);
302     }
303     
304     public void setAllIcons(String JavaDoc[] locales, String JavaDoc[] smallIcons, String JavaDoc[] largeIcons) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
305         if (webSvc!=null) webSvc.setAllIcons(locales, smallIcons, largeIcons);
306     }
307     
308     public void setLargeIcon(String JavaDoc icon) {
309         if (webSvc!=null) webSvc.setLargeIcon(icon);
310     }
311     
312     public void setLargeIcon(String JavaDoc locale, String JavaDoc icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
313         if (webSvc!=null) webSvc.setLargeIcon(locale, icon);
314     }
315     
316     public void setSmallIcon(String JavaDoc icon) {
317         if (webSvc!=null) webSvc.setSmallIcon(icon);
318     }
319     
320     public void setSmallIcon(String JavaDoc locale, String JavaDoc icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
321         if (webSvc!=null) webSvc.setSmallIcon(locale, icon);
322     }
323     
324     public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) {
325         if (webSvc!=null) webSvc.setIcon(icon);
326     }
327     
328     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String JavaDoc beanName, String JavaDoc[] propertyNames, Object JavaDoc[] propertyValues, String JavaDoc keyProperty) throws ClassNotFoundException JavaDoc, org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException {
329         return webSvc==null?null:webSvc.addBean(beanName, propertyNames, propertyValues, keyProperty);
330     }
331     
332     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
333         return webSvc==null?null:webSvc.addBean(beanName);
334     }
335     
336     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean createBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
337         return webSvc==null?null:webSvc.createBean(beanName);
338     }
339     
340     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean findBeanByName(String JavaDoc beanName, String JavaDoc propertyName, String JavaDoc value) {
341         return webSvc==null?null:webSvc.findBeanByName(beanName, propertyName, value);
342     }
343         
344     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
345         if (webSvc != null) {
346             webSvc.addPropertyChangeListener(pcl);
347         }
348         listeners.add(pcl);
349     }
350     
351     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
352         if (webSvc != null) {
353             webSvc.removePropertyChangeListener(pcl);
354         }
355         listeners.remove(pcl);
356     }
357     
358     public void merge(org.netbeans.modules.j2ee.dd.api.common.RootInterface bean, int mode) {
359         if (webSvc != null) {
360             if (bean instanceof WebServicesProxy)
361                 webSvc.merge(((WebServicesProxy)bean).getOriginal(), mode);
362             else webSvc.merge(bean, mode);
363         }
364     }
365     
366     public void write(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
367         if (webSvc != null) {
368             writing = true;
369             if (webSvc instanceof org.netbeans.modules.j2ee.dd.impl.webservices.model_1_1.Webservices) {
370                 org.netbeans.modules.j2ee.dd.impl.webservices.model_1_1.Webservices webSvcImpl =
371                     (org.netbeans.modules.j2ee.dd.impl.webservices.model_1_1.Webservices)webSvc;
372                 if (webSvcImpl._getSchemaLocation()==null) {
373                     webSvcImpl._setSchemaLocation("http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"); //NOI18N
374
}
375             } else if (webSvc instanceof org.netbeans.modules.j2ee.dd.impl.webservices.model_1_2.Webservices) {
376                 org.netbeans.modules.j2ee.dd.impl.webservices.model_1_2.Webservices webSvcImpl =
377                     (org.netbeans.modules.j2ee.dd.impl.webservices.model_1_2.Webservices)webSvc;
378                 if (webSvcImpl._getSchemaLocation()==null) {
379                     webSvcImpl._setSchemaLocation("http://java.sun.com/xml/ns/javaee http://www.ibm.com/webservices/xsd/javaee_web_services_1_2.xsd"); //NOI18N
380
}
381             }
382             webSvc.write(os);
383         }
384     }
385     
386     public void write(org.openide.filesystems.FileObject fo) throws java.io.IOException JavaDoc {
387         if (webSvc != null) {
388             try {
389                 org.openide.filesystems.FileLock lock = fo.lock();
390                 try {
391                     java.io.OutputStream JavaDoc os = fo.getOutputStream(lock);
392                     try {
393                         writing = true;
394                         write(os);
395                     } finally {
396                         os.close();
397                     }
398                 }
399                 finally {
400                     lock.releaseLock();
401                 }
402             } catch (org.openide.filesystems.FileAlreadyLockedException ex) {
403                 // trying to use OutputProvider for writing changes
404
org.openide.loaders.DataObject dobj = org.openide.loaders.DataObject.find(fo);
405                 if (dobj != null && dobj instanceof WebServicesProxy.OutputProvider)
406                     ((WebServicesProxy.OutputProvider)dobj).write(this);
407                 else
408                     throw ex;
409             }
410         }
411     }
412     
413     public Object JavaDoc clone() {
414         WebServicesProxy proxy = null;
415         if (webSvc == null)
416             proxy = new WebServicesProxy(null, version);
417         else {
418             Webservices clonedWebSvc = (Webservices)webSvc.clone();
419             proxy = new WebServicesProxy(clonedWebSvc, version);
420             if (Webservices.VERSION_1_1.equals(version)) {
421                 ((org.netbeans.modules.j2ee.dd.impl.webservices.model_1_1.Webservices)clonedWebSvc)._setSchemaLocation
422                     ("http://java.sun.com/xml/ns/j2ee http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd"); //NOI18N
423
} else if (Webservices.VERSION_1_2.equals(version)) {
424                 ((org.netbeans.modules.j2ee.dd.impl.webservices.model_1_2.Webservices)clonedWebSvc)._setSchemaLocation
425                     ("http://java.sun.com/xml/ns/javaee http://www.ibm.com/webservices/xsd/javaee_web_services_1_2.xsd"); //NOI18N
426
}
427         }
428         proxy.setError(error);
429         proxy.setStatus(ddStatus);
430         return proxy;
431     }
432     
433     /** Contract between friend modules that enables
434     * a specific handling of write(FileObject) method for targeted FileObject
435     */

436     public static interface OutputProvider {
437         public void write(Webservices webSvc) throws java.io.IOException JavaDoc;
438         public org.openide.filesystems.FileObject getTarget();
439     }
440 }
441
Popular Tags