KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > dd > impl > ejb > EjbJarProxy


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.ejb;
21
22 import org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException;
23 import org.netbeans.modules.j2ee.dd.api.ejb.EjbJar;
24 import org.netbeans.modules.j2ee.dd.api.ejb.Interceptors;
25 import org.netbeans.modules.j2ee.dd.impl.common.DDProviderDataObject;
26 import org.netbeans.modules.schema2beans.Schema2BeansUtil;
27 import org.netbeans.modules.schema2beans.BaseBean;
28 import org.openide.loaders.DataObject;
29 import org.openide.filesystems.FileObject;
30 import org.openide.filesystems.FileLock;
31
32 import java.math.BigDecimal JavaDoc;
33 import java.io.OutputStream JavaDoc;
34
35 /**
36  *
37  * @author mk115033
38  */

39 public class EjbJarProxy implements EjbJar {
40     private EjbJar ejbJar;
41     private String JavaDoc version;
42     private java.util.List JavaDoc listeners;
43     public boolean writing=false;
44     private org.xml.sax.SAXParseException JavaDoc error;
45     private int ddStatus;
46     private Schema2BeansUtil.ReindentationListener reindentationListener = new Schema2BeansUtil.ReindentationListener();
47
48     /** Creates a new instance of EjbJarProxy */
49     public EjbJarProxy(EjbJar ejbJar, String JavaDoc version) {
50         this.ejbJar=ejbJar;
51         this.version = version;
52         listeners = new java.util.ArrayList JavaDoc();
53         addPropertyChangeListener(reindentationListener);
54     }
55
56     public void setOriginal(EjbJar ejbJar) {
57         if (this.ejbJar!=ejbJar) {
58             for (int i=0;i<listeners.size();i++) {
59                 java.beans.PropertyChangeListener JavaDoc pcl =
60                     (java.beans.PropertyChangeListener JavaDoc)listeners.get(i);
61                 if (this.ejbJar!=null) this.ejbJar.removePropertyChangeListener(pcl);
62                 if (ejbJar!=null) ejbJar.addPropertyChangeListener(pcl);
63
64             }
65             this.ejbJar=ejbJar;
66             if (ejbJar!=null) setProxyVersion(ejbJar.getVersion().toString());
67         }
68     }
69
70     public EjbJar getOriginal() {
71         return ejbJar;
72     }
73
74     public void setProxyVersion(java.lang.String JavaDoc value) {
75         if ((version == null && value != null) || (version != null && !version.equals(value))) {
76             java.beans.PropertyChangeEvent JavaDoc evt =
77                     new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_VERSION, version, value);
78             version = value;
79             for (int i = 0; i < listeners.size(); i++) {
80                 ((java.beans.PropertyChangeListener JavaDoc) listeners.get(i)).propertyChange(evt);
81             }
82         }
83     }
84
85     /** Setter for version property.
86      * Warning : Only the upgrade from lower to higher version is supported.
87      * @param version ejb-jar version value
88      */

89     public void setVersion(java.math.BigDecimal JavaDoc version) {
90         String JavaDoc newVersion = version.toString();
91         if (this.version.equals(newVersion)) return;
92         if (!EjbJar.VERSION_2_1.equals(newVersion))
93             throw new RuntimeException JavaDoc("Only the upgrade from lower to upper version is supported"); //NOI18N
94
if (ejbJar!=null) {
95             org.w3c.dom.Document JavaDoc document = null;
96             if (ejbJar instanceof org.netbeans.modules.j2ee.dd.impl.ejb.model_2_0.EjbJar) {
97                 document =
98                     ((org.netbeans.modules.j2ee.dd.impl.ejb.model_2_0.EjbJar)ejbJar).graphManager().getXmlDocument();
99             }
100             if (document!=null) {
101                 org.w3c.dom.Element JavaDoc docElement = document.getDocumentElement();
102                 if (docElement!=null) {
103                     org.w3c.dom.DocumentType JavaDoc docType = document.getDoctype();
104                     if (docType!=null) {
105                         document.removeChild(docType); //NOI18N
106
}
107                     docElement.setAttribute("version","2.1"); //NOI18N
108
docElement.setAttribute("xmlns","http://java.sun.com/xml/ns/j2ee"); //NOI18N
109
docElement.setAttribute("xmlns:xsi","http://www.w3.org/2001/XMLSchema-instance"); //NOI18N
110
docElement.setAttribute("xsi:schemaLocation", //NOI18N
111
"http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd"); //NOI18N
112
}
113             }
114         }
115     }
116
117     public java.math.BigDecimal JavaDoc getVersion() {
118         return version == null ? BigDecimal.valueOf(0) : new BigDecimal JavaDoc(version);
119     }
120     public org.xml.sax.SAXParseException JavaDoc getError() {
121         return error;
122     }
123     public void setError(org.xml.sax.SAXParseException JavaDoc error) {
124         this.error=error;
125     }
126     public int getStatus() {
127         return ddStatus;
128     }
129     public void setStatus(int value) {
130         if (ddStatus!=value) {
131             java.beans.PropertyChangeEvent JavaDoc evt =
132                 new java.beans.PropertyChangeEvent JavaDoc(this, PROPERTY_STATUS, new Integer JavaDoc(ddStatus), new Integer JavaDoc(value));
133             ddStatus=value;
134             for (int i=0;i<listeners.size();i++) {
135                 ((java.beans.PropertyChangeListener JavaDoc)listeners.get(i)).propertyChange(evt);
136             }
137         }
138     }
139
140     public void addPropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
141         if (ejbJar!=null) ejbJar.addPropertyChangeListener(pcl);
142         listeners.add(pcl);
143     }
144
145     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc pcl) {
146         if (ejbJar!=null) ejbJar.removePropertyChangeListener(pcl);
147         listeners.remove(pcl);
148     }
149
150     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean createBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
151         return ejbJar==null?null:ejbJar.createBean(beanName);
152     }
153
154     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 {
155         return ejbJar==null?null:ejbJar.addBean(beanName, propertyNames, propertyValues, keyProperty);
156     }
157
158     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean addBean(String JavaDoc beanName) throws ClassNotFoundException JavaDoc {
159         return ejbJar==null?null:ejbJar.addBean(beanName);
160     }
161
162     public org.netbeans.modules.j2ee.dd.api.common.CommonDDBean findBeanByName(String JavaDoc beanName, String JavaDoc propertyName, String JavaDoc value) {
163         return ejbJar==null?null:ejbJar.findBeanByName(beanName, propertyName, value);
164     }
165
166     public java.util.Map JavaDoc getAllDescriptions() {
167         return ejbJar==null?new java.util.HashMap JavaDoc():ejbJar.getAllDescriptions();
168     }
169
170     public java.util.Map JavaDoc getAllDisplayNames() {
171         return ejbJar==null?new java.util.HashMap JavaDoc():ejbJar.getAllDisplayNames();
172     }
173
174     public java.util.Map JavaDoc getAllIcons() {
175         return ejbJar==null?new java.util.HashMap JavaDoc():ejbJar.getAllIcons();
176     }
177
178     public String JavaDoc getDefaultDescription() {
179         return ejbJar==null?null:ejbJar.getDefaultDescription();
180     }
181
182     public String JavaDoc getDefaultDisplayName() {
183         return ejbJar==null?null:ejbJar.getDefaultDisplayName();
184     }
185
186     public org.netbeans.modules.j2ee.dd.api.common.Icon getDefaultIcon() {
187         return ejbJar==null?null:ejbJar.getDefaultIcon();
188     }
189
190     public String JavaDoc getDescription(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
191         return ejbJar==null?null:ejbJar.getDescription(locale);
192     }
193
194     public String JavaDoc getDisplayName(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
195         return ejbJar==null?null:ejbJar.getDisplayName(locale);
196     }
197
198     public java.lang.String JavaDoc getId() {
199         return ejbJar==null?null:ejbJar.getId();
200     }
201
202     public String JavaDoc getLargeIcon() {
203         return ejbJar==null?null:ejbJar.getLargeIcon();
204     }
205
206     public String JavaDoc getLargeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
207         return ejbJar==null?null:ejbJar.getLargeIcon(locale);
208     }
209
210     public String JavaDoc getSmallIcon() {
211         return ejbJar==null?null:ejbJar.getSmallIcon();
212     }
213
214     public String JavaDoc getSmallIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
215         return ejbJar==null?null:ejbJar.getSmallIcon(locale);
216     }
217
218     public Object JavaDoc getValue(String JavaDoc name) {
219         return ejbJar==null?null:ejbJar.getValue(name);
220     }
221
222     public void merge(org.netbeans.modules.j2ee.dd.api.common.RootInterface bean, int mode) {
223         if (bean instanceof EjbJarProxy) {
224             bean = ((EjbJarProxy) bean).getOriginal();
225         }
226         if (ejbJar != bean && bean instanceof EjbJar) {
227             EjbJar newEjbJar = (EjbJar) bean;
228             if (ejbJar != null && ejbJar.getVersion().equals(newEjbJar.getVersion())) {
229                 removePropertyChangeListener(reindentationListener);
230                 ejbJar.merge(newEjbJar, mode);
231                 addPropertyChangeListener(reindentationListener);
232             } else {
233                 setOriginal((EjbJar) newEjbJar.clone());
234             }
235         }
236     }
237
238     public void removeAllDescriptions() {
239
240         if (ejbJar!=null) ejbJar.removeAllDescriptions();
241     }
242
243     public void removeAllDisplayNames() {
244         if (ejbJar!=null) ejbJar.removeAllDisplayNames();
245     }
246
247     public void removeAllIcons() {
248         if (ejbJar!=null) ejbJar.removeAllIcons();
249     }
250
251     public void removeDescription() {
252         if (ejbJar!=null) ejbJar.removeDescription();
253     }
254
255     public void removeDescriptionForLocale(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
256         if (ejbJar!=null) ejbJar.removeDescriptionForLocale(locale);
257     }
258
259     public void removeDisplayName() {
260         if (ejbJar!=null) ejbJar.removeDisplayName();
261     }
262
263     public void removeDisplayNameForLocale(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
264         if (ejbJar!=null) ejbJar.removeDisplayNameForLocale(locale);
265     }
266
267     public void removeIcon() {
268         if (ejbJar!=null) ejbJar.removeIcon();
269     }
270
271     public void removeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
272         if (ejbJar!=null) ejbJar.removeIcon(locale);
273     }
274
275     public void removeLargeIcon() {
276         if (ejbJar!=null) ejbJar.removeLargeIcon();
277     }
278
279     public void removeLargeIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
280         if (ejbJar!=null) ejbJar.removeLargeIcon(locale);
281     }
282
283     public void removeSmallIcon() {
284         if (ejbJar!=null) ejbJar.removeSmallIcon();
285     }
286
287     public void removeSmallIcon(String JavaDoc locale) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
288         if (ejbJar!=null) ejbJar.removeSmallIcon(locale);
289     }
290
291     public void setAllDescriptions(java.util.Map JavaDoc descriptions) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
292         if (ejbJar!=null) ejbJar.setAllDescriptions(descriptions);
293     }
294
295     public void setAllDisplayNames(java.util.Map JavaDoc displayNames) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
296         if (ejbJar!=null) ejbJar.setAllDisplayNames(displayNames);
297     }
298
299     public void setAllIcons(String JavaDoc[] locales, String JavaDoc[] smallIcons, String JavaDoc[] largeIcons) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
300         if (ejbJar!=null) ejbJar.setAllIcons(locales, smallIcons, largeIcons);
301     }
302
303     public void setDescription(String JavaDoc description) {
304         if (ejbJar!=null) ejbJar.setDescription(description);
305     }
306
307     public void setDescription(String JavaDoc locale, String JavaDoc description) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
308         if (ejbJar!=null) ejbJar.setDescription(locale, description);
309     }
310
311     public void setDisplayName(String JavaDoc displayName) {
312         if (ejbJar!=null) ejbJar.setDisplayName(displayName);
313     }
314
315     public void setDisplayName(String JavaDoc locale, String JavaDoc displayName) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
316         if (ejbJar!=null) ejbJar.setDisplayName(locale, displayName);
317     }
318
319     public void setIcon(org.netbeans.modules.j2ee.dd.api.common.Icon icon) {
320         if (ejbJar!=null) ejbJar.setIcon(icon);
321     }
322
323     public void setId(java.lang.String JavaDoc value) {
324         if (ejbJar!=null) ejbJar.setId(value);
325     }
326
327     public void setLargeIcon(String JavaDoc icon) {
328         if (ejbJar!=null) ejbJar.setLargeIcon(icon);
329     }
330
331     public void setLargeIcon(String JavaDoc locale, String JavaDoc icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
332         if (ejbJar!=null) ejbJar.setLargeIcon(locale, icon);
333     }
334
335     public void setSmallIcon(String JavaDoc icon) {
336         if (ejbJar!=null) ejbJar.setSmallIcon(icon);
337     }
338
339     public void setSmallIcon(String JavaDoc locale, String JavaDoc icon) throws org.netbeans.modules.j2ee.dd.api.common.VersionNotSupportedException {
340         if (ejbJar!=null) ejbJar.setSmallIcon(locale, icon);
341     }
342
343     public void write(java.io.OutputStream JavaDoc os) throws java.io.IOException JavaDoc {
344         if (ejbJar!=null) {
345             writing=true;
346             Schema2BeansUtil.write((BaseBean) ejbJar, os);
347         }
348     }
349
350     public void write(FileObject fo) throws java.io.IOException JavaDoc {
351         if (ejbJar != null) {
352             DataObject dataObject = DataObject.find(fo);
353             if (dataObject instanceof DDProviderDataObject) {
354                 ((DDProviderDataObject) dataObject).writeModel(ejbJar);
355             } else {
356                 FileLock lock = fo.lock();
357                 try {
358                     OutputStream JavaDoc os = fo.getOutputStream(lock);
359                     try {
360                         writing = true;
361                         write(os);
362                     } finally {
363                         os.close();
364                     }
365                 } finally {
366                     lock.releaseLock();
367                 }
368             }
369         }
370     }
371
372     public Object JavaDoc clone() {
373         EjbJarProxy proxy;
374         if (ejbJar==null)
375             proxy = new EjbJarProxy(null,version);
376         else {
377             EjbJar clonedEjbJar=(EjbJar)ejbJar.clone();
378             proxy = new EjbJarProxy(clonedEjbJar,version);
379             if (EjbJar.VERSION_1_1.equals(version)) {
380                 ((org.netbeans.modules.schema2beans.BaseBean)clonedEjbJar).changeDocType
381                     ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.0//EN","http://java.sun.com/dtd/ejb-jar_1.1.dtd");
382             } else if (EjbJar.VERSION_2_0.equals(version)) {
383                 ((org.netbeans.modules.schema2beans.BaseBean)clonedEjbJar).changeDocType
384                     ("-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN","http://java.sun.com/dtd/ejb-jar_2_0.dtd");
385             } else {
386                 ((org.netbeans.modules.j2ee.dd.impl.ejb.model_2_1.EjbJar)clonedEjbJar)._setSchemaLocation
387                     ("http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd");
388                 clonedEjbJar.setVersion(new java.math.BigDecimal JavaDoc(EjbJar.VERSION_2_1));
389             }
390         }
391         proxy.setError(error);
392         proxy.setStatus(ddStatus);
393         return proxy;
394     }
395
396     public boolean isWriting() {
397         return writing;
398     }
399
400     public void setWriting(boolean writing) {
401         this.writing=writing;
402     }
403
404     public org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans getEnterpriseBeans() {
405         return ejbJar==null?null:ejbJar.getEnterpriseBeans();
406     }
407
408     public org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor getSingleAssemblyDescriptor() {
409         return ejbJar==null?null:ejbJar.getSingleAssemblyDescriptor();
410     }
411
412     public String JavaDoc getSingleEjbClientJar() {
413         return ejbJar==null?null:ejbJar.getSingleEjbClientJar();
414     }
415
416     public org.netbeans.modules.j2ee.dd.api.ejb.Relationships getSingleRelationships() {
417         return ejbJar==null?null:ejbJar.getSingleRelationships();
418     }
419
420     public void setAssemblyDescriptor(org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor value) {
421         if (ejbJar!=null) ejbJar.setAssemblyDescriptor(value);
422     }
423
424     public void setEjbClientJar(String JavaDoc value) {
425         if (ejbJar!=null) ejbJar.setEjbClientJar(value);
426     }
427
428     public void setEnterpriseBeans(org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans value) {
429         if (ejbJar!=null) ejbJar.setEnterpriseBeans(value);
430     }
431
432     public void setRelationships(org.netbeans.modules.j2ee.dd.api.ejb.Relationships value) {
433         if (ejbJar!=null) ejbJar.setRelationships(value);
434     }
435
436     public org.netbeans.modules.j2ee.dd.api.ejb.AssemblyDescriptor newAssemblyDescriptor() {
437         if(ejbJar == null)
438             return null;
439         else
440             return ejbJar.newAssemblyDescriptor();
441     }
442
443     public org.netbeans.modules.j2ee.dd.api.ejb.EnterpriseBeans newEnterpriseBeans() {
444         if(ejbJar == null)
445             return null;
446         else
447             return ejbJar.newEnterpriseBeans();
448     }
449
450     public org.netbeans.modules.j2ee.dd.api.ejb.Relationships newRelationships() {
451         if(ejbJar == null)
452             return null;
453         else
454             return ejbJar.newRelationships();
455     }
456
457     public void setInterceptors(Interceptors valueInterface) throws VersionNotSupportedException {
458         if (ejbJar!=null) ejbJar.setInterceptors(valueInterface);
459     }
460
461     public Interceptors newInterceptors() throws VersionNotSupportedException {
462         if(ejbJar == null)
463             return null;
464         else
465             return ejbJar.newInterceptors();
466     }
467
468     public Interceptors getInterceptors() throws VersionNotSupportedException {
469         if(ejbJar == null)
470             return null;
471         else
472             return ejbJar.getInterceptors();
473     }
474 }
475
Popular Tags