KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > dd > impl > application > ApplicationProxy


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.j2ee.dd.impl.application;
21
22 import java.math.BigDecimal JavaDoc;
23 import org.netbeans.modules.j2ee.dd.api.application.Application;
24
25 /**
26  * @author Nitya Doraisamy
27  */

28 public class ApplicationProxy implements Application {
29     private Application app;
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 // private static CommonDDAccess cDDA = new
38

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

450     public static interface OutputProvider {
451         public void write(Application app) throws java.io.IOException JavaDoc;
452         public org.openide.filesystems.FileObject getTarget();
453     }
454 }
455
Popular Tags