KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > wsdl > config > ConfigurationProxy


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 package org.netbeans.modules.websvc.wsdl.config;
21
22 import org.netbeans.modules.websvc.wsdl.config.api.Configuration;
23
24 /**
25  *
26  * @author Peter Williams
27  */

28 public class ConfigurationProxy implements Configuration {
29     private Configuration configuration;
30     private String JavaDoc version;
31     private java.util.List JavaDoc listeners;
32     public boolean writing=false;
33     private OutputProvider outputProvider;
34     private org.xml.sax.SAXParseException JavaDoc error;
35     private int ddStatus;
36
37     public ConfigurationProxy(Configuration configuration) {
38         init(configuration, "1.1");
39     }
40
41     private void init(Configuration configuration, String JavaDoc version) {
42         this.configuration=configuration;
43         this.version = version;
44         listeners = new java.util.ArrayList JavaDoc();
45     }
46
47     public void setOriginal(Configuration configuration) {
48         if (this.configuration!=configuration) {
49             for (int i=0;i<listeners.size();i++) {
50                 java.beans.PropertyChangeListener JavaDoc pcl =
51                     (java.beans.PropertyChangeListener JavaDoc)listeners.get(i);
52                 if (this.configuration!=null) {
53                     this.configuration.removePropertyChangeListener(pcl);
54                 }
55                 if (configuration!=null) {
56                     configuration.addPropertyChangeListener(pcl);
57                 }
58
59             }
60             this.configuration=configuration;
61             // !PW Configuration does not store version in JAX-RPC 1.1
62
// if (configuration!=null) {
63
// setProxyVersion(configuration.getVersion());
64
// }
65
}
66     }
67
68     public Configuration getOriginal() {
69         return configuration;
70     }
71
72     public void setProxyVersion(java.lang.String JavaDoc value) {
73         if ((version==null && value!=null) || !version.equals(value)) {
74             java.beans.PropertyChangeEvent JavaDoc evt =
75                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_VERSION, version, value);
76             version=value;
77             for (int i=0;i<listeners.size();i++) {
78                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
79             }
80         }
81     }
82     /*
83     public void setVersion(java.lang.String value) {
84     }
85     */

86     public java.lang.String JavaDoc getVersion() {
87         return version;
88     }
89     public org.xml.sax.SAXParseException JavaDoc getError() {
90         return error;
91     }
92     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
93         this.error=error;
94     }
95     public int getStatus() {
96         return ddStatus;
97     }
98     public void setStatus(int value) {
99         if (ddStatus!=value) {
100             java.beans.PropertyChangeEvent JavaDoc evt =
101                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_STATUS, new Integer JavaDoc(ddStatus), new Integer JavaDoc(value));
102             ddStatus=value;
103             for (int i=0;i<listeners.size();i++) {
104                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
105             }
106         }
107     }
108
109     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
110         if (configuration!=null) configuration.addPropertyChangeListener(pcl);
111         listeners.add(pcl);
112     }
113
114     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
115         if (configuration!=null) configuration.removePropertyChangeListener(pcl);
116         listeners.remove(pcl);
117     }
118
119 // public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean createBean(String beanName) throws ClassNotFoundException {
120
// return configuration==null?null:configuration.createBean(beanName);
121
// }
122
//
123
// public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String beanName, String[] propertyNames, Object[] propertyValues, String keyProperty) throws ClassNotFoundException, org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException {
124
// return configuration==null?null:configuration.addBean(beanName, propertyNames, propertyValues, keyProperty);
125
// }
126
//
127
// public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String beanName) throws ClassNotFoundException {
128
// return configuration==null?null:configuration.addBean(beanName);
129
// }
130
//
131
// public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean findBeanByName(String beanName, String propertyName, String value) {
132
// return configuration==null?null:configuration.findBeanByName(beanName, propertyName, value);
133
// }
134

135     public org.netbeans.modules.websvc.wsdl.config.api.J2eeMappingFile getJ2eeMappingFile() {
136         return configuration == null ? null : configuration.getJ2eeMappingFile();
137     }
138
139     public org.netbeans.modules.websvc.wsdl.config.api.Modelfile getModelfile() {
140         return configuration == null ? null : configuration.getModelfile();
141     }
142
143     public org.netbeans.modules.websvc.wsdl.config.api.Service getService() {
144         return configuration == null ? null : configuration.getService();
145     }
146
147     public org.netbeans.modules.websvc.wsdl.config.api.Wsdl getWsdl() {
148         return configuration == null ? null : configuration.getWsdl();
149     }
150
151     public org.netbeans.modules.websvc.wsdl.config.api.J2eeMappingFile newJ2eeMappingFile() {
152         return configuration == null ? null : configuration.newJ2eeMappingFile();
153     }
154
155     public org.netbeans.modules.websvc.wsdl.config.api.Modelfile newModelfile() {
156         return configuration == null ? null : configuration.newModelfile();
157     }
158
159     public org.netbeans.modules.websvc.wsdl.config.api.Service newService() {
160         return configuration == null ? null : configuration.newService();
161     }
162
163     public org.netbeans.modules.websvc.wsdl.config.api.Wsdl newWsdl() {
164         return configuration == null ? null : configuration.newWsdl();
165     }
166
167     public void setJ2eeMappingFile(org.netbeans.modules.websvc.wsdl.config.api.J2eeMappingFile value) {
168         if(configuration != null) {
169             configuration.setJ2eeMappingFile(value);
170         }
171     }
172
173     public void setModelfile(org.netbeans.modules.websvc.wsdl.config.api.Modelfile value) {
174         if(configuration != null) {
175             configuration.setModelfile(value);
176         }
177     }
178
179     public void setService(org.netbeans.modules.websvc.wsdl.config.api.Service value) {
180         if(configuration != null) {
181             configuration.setService(value);
182         }
183     }
184
185     public void setWsdl(org.netbeans.modules.websvc.wsdl.config.api.Wsdl value) {
186         if(configuration != null) {
187             configuration.setWsdl(value);
188         }
189     }
190
191     public Object JavaDoc getValue(String JavaDoc name) {
192         return configuration==null?null:configuration.getValue(name);
193     }
194
195     public void merge(org.netbeans.modules.websvc.wsdl.config.api.RootInterface bean, int mode) {
196         if (configuration!=null) {
197             if (bean instanceof ConfigurationProxy) {
198                 configuration.merge(((ConfigurationProxy)bean).getOriginal(), mode);
199             } else {
200                 configuration.merge(bean, mode);
201             }
202         }
203     }
204
205     public void write(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
206         if (configuration!=null) {
207             writing=true;
208             configuration.write(os);
209         }
210     }
211
212     public void write(org.openide.filesystems.FileObject fo) throws java.io.IOException JavaDoc {
213         if (configuration!=null) {
214             try {
215                 org.openide.filesystems.FileLock lock = fo.lock();
216                 try {
217                     java.io.OutputStream JavaDoc os = fo.getOutputStream(lock);
218                     try {
219                         writing=true;
220                         write(os);
221                     } finally {
222                         os.close();
223                     }
224                 }
225                 finally {
226                     lock.releaseLock();
227                 }
228             } catch (org.openide.filesystems.FileAlreadyLockedException ex) {
229                 // trying to use OutputProvider for writing changes
230
org.openide.loaders.DataObject dobj = org.openide.loaders.DataObject.find(fo);
231                 if (dobj!=null && dobj instanceof ConfigurationProxy.OutputProvider)
232                     ((ConfigurationProxy.OutputProvider)dobj).write(this);
233                 else throw ex;
234             }
235         }
236     }
237
238     public Object JavaDoc clone() {
239         ConfigurationProxy proxy = null;
240         if (configuration==null) {
241             proxy = new ConfigurationProxy(null);
242         } else {
243             Configuration clonedConfiguration=(Configuration)configuration.clone();
244             proxy = new ConfigurationProxy(clonedConfiguration);
245             ((org.netbeans.modules.websvc.wsdl.config.impl.Configuration)clonedConfiguration)._setSchemaLocation
246                 ("http://java.sun.com/xml/ns/jax-rpc/ri/config");
247         }
248         proxy.setError(error);
249         proxy.setStatus(ddStatus);
250         return proxy;
251     }
252
253     public boolean isWriting() {
254         return writing;
255     }
256
257     public void setWriting(boolean writing) {
258         this.writing=writing;
259     }
260
261     public void setOutputProvider(OutputProvider iop) {
262         this.outputProvider=iop;
263     }
264
265     /** Contract between friend modules that enables
266     * a specific handling of write(FileObject) method for targeted FileObject
267     */

268     public static interface OutputProvider {
269         public void write(Configuration configuration) throws java.io.IOException JavaDoc;
270         public org.openide.filesystems.FileObject getTarget();
271     }
272 }
273
Popular Tags