KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > dd > api > DDProvider


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.sun.dd.api;
21 import java.io.IOException JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.lang.reflect.Constructor JavaDoc;
24 import java.lang.reflect.InvocationTargetException JavaDoc;
25 import java.lang.reflect.Method JavaDoc;
26 import java.text.MessageFormat JavaDoc;
27 import java.util.HashMap JavaDoc;
28 import javax.xml.parsers.DocumentBuilder JavaDoc;
29 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
30 import javax.xml.parsers.ParserConfigurationException JavaDoc;
31 import org.netbeans.modules.j2ee.sun.dd.impl.common.SunBaseBean;
32 import org.netbeans.modules.schema2beans.Common;
33 import org.xml.sax.*;
34 import java.util.Map JavaDoc;
35 import org.w3c.dom.Document JavaDoc;
36 import org.w3c.dom.DocumentType JavaDoc;
37 import java.util.ResourceBundle JavaDoc;
38
39 import org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar;
40 import org.netbeans.modules.j2ee.sun.dd.impl.ejb.SunEjbJarProxy;
41
42 import org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp;
43 import org.netbeans.modules.j2ee.sun.dd.impl.web.SunWebAppProxy;
44
45 import org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication;
46 import org.netbeans.modules.j2ee.sun.dd.impl.app.SunApplicationProxy;
47
48 import org.netbeans.modules.j2ee.sun.dd.api.serverresources.Resources;
49 import org.netbeans.modules.j2ee.sun.dd.impl.serverresources.ResourcesProxy;
50         
51 import org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient;
52 import org.netbeans.modules.j2ee.sun.dd.impl.client.SunApplicationClientProxy;
53
54 import org.netbeans.modules.j2ee.sun.dd.impl.DTDRegistry;
55
56 /**
57  * Provides access to Deployment Descriptor root objects.
58  *
59  * @author Milan Kuchtiak
60  */

61
62 public final class DDProvider {
63     // !PW FIXME refer to DTDRegistry file directly, or at least map to it, rather than redeclaring.
64
private static final String JavaDoc EJB_30_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN"; //NOI18N "sun-ejb-jar_3_0-0.dtd"
65
private static final String JavaDoc EJB_21_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN"; //NOI18N
66
private static final String JavaDoc EJB_21_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 EJB 2.1//EN"; //NOI18N
67
private static final String JavaDoc EJB_20_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN"; //NOI18N "sun-ejb-jar_2_0-0.dtd" ,
68
private static final String JavaDoc EJB_21_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN"; //NOI18N "sun-ejb-jar_2_1-0.dtd" , ///[THIS IS DEPRECATED]
69

70     private static final String JavaDoc WEB_25_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN"; //NOI18N "sun-web-app_2_5-0"
71
private static final String JavaDoc WEB_21_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN"; //NOI18N
72
private static final String JavaDoc WEB_21_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Servlet 2.4//EN"; //NOI18N
73
private static final String JavaDoc WEB_20_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN" ; //NOI18N "sun-web-app_2_3-0.dtd" ,
74
private static final String JavaDoc WEB_21_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Servlet 2.4//EN"; //NOI18N "sun-web-app_2_4-0.dtd" , ///[THIS IS DEPRECATED]
75

76     private static final String JavaDoc APP_50_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Java EE Application 5.0//EN"; //NOI18N "sun-application_5_0-0.dtd"
77
private static final String JavaDoc APP_14_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 J2EE Application 1.4//EN"; //NOI18N "sun-application_1_4-0.dtd"
78
private static final String JavaDoc APP_14_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 J2EE Application 1.4//EN"; //NOI18N "sun-application_1_4-0.dtd"
79
private static final String JavaDoc APP_13_70_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 J2EE Application 1.3//EN"; //NOI18N "sun-application_1_3-0.dtd"
80
private static final String JavaDoc APP_14_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 J2EE Application 1.4//EN"; //NOI18N "sun-application_1_4-0.dtd" ///[THIS IS DEPRECATED]
81

82     private static final String JavaDoc APPCLIENT_50_90_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN"; //NOI18N "sun-application-client_5_0-0.dtd"
83
private static final String JavaDoc APPCLIENT_14_81_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Application Client 1.4//EN"; //NOI18N "sun-application-client_1_4-1.dtd"
84
private static final String JavaDoc APPCLIENT_14_80_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Application Client 1.4//EN"; //NOI18N "sun-application-client_1_4-0.dtd"
85
private static final String JavaDoc APPCLIENT_14_80_DOCTYPE_SUNONE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Application Client 1.4//EN"; //NOI18N "sun-application-client_1_4-0.dtd" [THIS IS DEPRECATED]
86
private static final String JavaDoc APPCLIENT_13_70_DOCTYPE = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN"; //NOI18N "sun-application-client_1_3-0.dtd"
87

88 // private static final String = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Connector 1.0//EN" , "sun-connector_1_0-0.dtd" ,
89
// private static final String = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client Container 1.0//EN" , "sun-application-client-container_1_0.dtd" ,
90
// private static final String = "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 OR Mapping //EN" , "sun-cmp-mapping_1_0.dtd" ,
91
// private static final String = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 OR Mapping//EN" , "sun-cmp-mapping_1_1.dtd" ,
92
// private static final String = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 OR Mapping//EN" , "sun-cmp-mapping_1_2.dtd" ,
93
// private static final String = "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Application Client Container //EN" , "sun-application-client-container_1_0.dtd" ,
94
// private static final String = "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Application Client Container //EN" , "sun-application-client-container_1_1.dtd" ,
95

96     
97     
98     
99     
100     
101     
102     private static final DDProvider ddProvider = new DDProvider();
103     private Map JavaDoc ddMap;
104     
105     /** Creates a new instance of DDProvider */
106     private DDProvider() {
107         //ddMap=new java.util.WeakHashMap(5);
108
ddMap = new java.util.HashMap JavaDoc(5);
109     }
110     
111     /**
112     * Accessor method for DDProvider singleton
113     * @return DDProvider object
114     */

115     public static DDProvider getDefault() {
116         return ddProvider;
117     }
118     
119      /**
120      * Returns the root of deployment descriptor bean graph for java.io.File object.
121      *
122      * @param is source representing the sun-ejb-jar.xml file
123      * @return Ejb object - root of the deployment descriptor bean graph
124      */

125     public SunEjbJar getEjbDDRoot(InputSource is) throws IOException JavaDoc, SAXException {
126         DDParse parse = parseDD(is);
127         SunEjbJar ejbRoot = createEjbJar(parse);
128         SunEjbJarProxy proxy = new SunEjbJarProxy(ejbRoot, ejbRoot.getVersion().toString());
129         setEjbProxyErrorStatus(proxy, parse);
130         return proxy;
131     }
132     
133     /**
134      * Returns the root of deployment descriptor bean graph for java.io.File object.
135      *
136      * @param is source representing the sun-web.xml file
137      * @return Web object - root of the deployment descriptor bean graph
138      */

139     public SunWebApp getWebDDRoot(InputSource is) throws IOException JavaDoc, SAXException, DDException {
140         DDParse parse = parseDD(is);
141         return processWebAppParseTree(parse);
142     }
143
144     /**
145      * Returns the root of deployment descriptor bean graph for java.io.File object.
146      *
147      * @param is stream representing the sun-web.xml file
148      * @return Web object - root of the deployment descriptor bean graph
149      */

150     public SunWebApp getWebDDRoot(InputStream JavaDoc is) throws IOException JavaDoc, SAXException, DDException {
151         DDParse parse = parseDD(is);
152         return processWebAppParseTree(parse);
153     }
154     
155     /**
156      * Returns the root of deployment descriptor bean graph for java.io.File object.
157      *
158      * @param doc XML document representing the sun-web.xml file
159      * @return Web object - root of the deployment descriptor bean graph
160      */

161     public SunWebApp getWebDDRoot(org.w3c.dom.Document JavaDoc doc) throws DDException {
162         DDParse parse = new DDParse(doc, null);
163         return processWebAppParseTree(parse);
164     }
165     
166     private SunWebApp processWebAppParseTree(DDParse parse) throws DDException {
167         SunWebApp webRoot = createWebApp(parse);
168         SunWebAppProxy proxy = new SunWebAppProxy(webRoot, webRoot.getVersion().toString());
169         setWebProxyErrorStatus(proxy, parse);
170         return proxy;
171     }
172     
173     /**
174      * Returns the root of deployment descriptor bean graph for java.io.File object.
175      *
176      * @param is source representing the sun-application.xml file
177      * @return Application object - root of the deployment descriptor bean graph
178      */

179     public SunApplication getAppDDRoot(InputSource is) throws IOException JavaDoc, SAXException {
180         DDParse parse = parseDD(is);
181         SunApplication appRoot = createApplication(parse);
182         SunApplicationProxy proxy = new SunApplicationProxy(appRoot, appRoot.getVersion().toString());
183         setAppProxyErrorStatus(proxy, parse);
184         return proxy;
185     }
186     
187     /**
188      * Returns the root of deployment descriptor bean graph for java.io.File object.
189      *
190      * @param is source representing the sun-application-client.xml file
191      * @return Application object - root of the deployment descriptor bean graph
192      */

193     public SunApplicationClient getAppClientDDRoot(InputSource is) throws IOException JavaDoc, SAXException {
194         DDParse parse = parseDD(is);
195         SunApplicationClient appClientRoot = createApplicationClient(parse);
196         SunApplicationClientProxy proxy = new SunApplicationClientProxy(appClientRoot, appClientRoot.getVersion().toString());
197         setAppClientProxyErrorStatus(proxy, parse);
198         return proxy;
199     }
200         
201     // PENDING j2eeserver needs BaseBean - this is a temporary workaround to avoid dependency of web project on DD impl
202
/** Convenient method for getting the BaseBean object from CommonDDBean object
203      *
204      */

205     public org.netbeans.modules.schema2beans.BaseBean getBaseBean(org.netbeans.modules.j2ee.sun.dd.api.CommonDDBean bean) {
206         if (bean instanceof org.netbeans.modules.schema2beans.BaseBean)
207             return (org.netbeans.modules.schema2beans.BaseBean)bean;
208         else if (bean instanceof SunEjbJarProxy)
209             return (org.netbeans.modules.schema2beans.BaseBean) ((SunEjbJarProxy)bean).getOriginal();
210         else if (bean instanceof SunWebAppProxy)
211             return (org.netbeans.modules.schema2beans.BaseBean) ((SunWebAppProxy)bean).getOriginal();
212         else if (bean instanceof SunApplicationProxy)
213             return (org.netbeans.modules.schema2beans.BaseBean) ((SunApplicationProxy)bean).getOriginal();
214         else if (bean instanceof SunApplicationClientProxy)
215             return (org.netbeans.modules.schema2beans.BaseBean) ((SunApplicationClientProxy)bean).getOriginal();
216         return null;
217     }
218
219     private static void setEjbProxyErrorStatus(SunEjbJarProxy ejbJarProxy, DDParse parse) {
220         SAXParseException error = parse.getWarning();
221         ejbJarProxy.setError(error);
222         /*if (error!=null) {
223             ejbJarProxy.setStatus(SunEjbJar.STATE_INVALID_PARSABLE);
224         } else {
225             ejbJarProxy.setStatus(SunEjbJar.STATE_VALID);
226         }*/

227     }
228     
229     private static void setAppProxyErrorStatus(SunApplicationProxy appProxy, DDParse parse) {
230         SAXParseException error = parse.getWarning();
231         appProxy.setError(error);
232         /*if (error!=null) {
233             appProxy.setStatus(SunApplication.STATE_INVALID_PARSABLE);
234         } else {
235             appProxy.setStatus(SunApplication.STATE_VALID);
236         }*/

237     }
238     
239     private static void setWebProxyErrorStatus(SunWebAppProxy webProxy, DDParse parse) {
240         SAXParseException error = parse.getWarning();
241         webProxy.setError(error);
242         /*if (error!=null) {
243             appProxy.setStatus(SunApplication.STATE_INVALID_PARSABLE);
244         } else {
245             appProxy.setStatus(SunApplication.STATE_VALID);
246         }*/

247     }
248
249     private static class VersionInfo {
250         private Class JavaDoc implClass;
251         private Class JavaDoc proxyClass;
252         private String JavaDoc publicId;
253         private String JavaDoc systemId;
254         
255         public VersionInfo(Class JavaDoc implClass, Class JavaDoc proxyClass, String JavaDoc publicId, String JavaDoc systemId) {
256             this.implClass = implClass;
257             this.proxyClass = proxyClass;
258             this.publicId = publicId;
259             this.systemId = systemId;
260         }
261
262         public Class JavaDoc getImplClass() {
263             return implClass;
264         }
265
266         public Class JavaDoc getProxyClass() {
267             return proxyClass;
268         }
269
270         public String JavaDoc getPublicId() {
271             return publicId;
272         }
273
274         public String JavaDoc getSystemId() {
275             return systemId;
276         }
277     }
278     
279     private static HashMap JavaDoc apiToVersionMap = new HashMap JavaDoc(11);
280     private static HashMap JavaDoc sunWebAppVersionMap = new HashMap JavaDoc(11);
281     private static HashMap JavaDoc sunEjbJarVersionMap = new HashMap JavaDoc(11);
282     private static HashMap JavaDoc sunApplicationVersionMap = new HashMap JavaDoc(11);
283     private static HashMap JavaDoc sunAppClientVersionMap = new HashMap JavaDoc(11);
284     
285     static {
286         sunWebAppVersionMap.put(SunWebApp.VERSION_2_3_0, new VersionInfo(
287                 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_3_0.SunWebApp.class, SunWebAppProxy.class,
288                 DTDRegistry.SUN_WEBAPP_230_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_230_DTD_SYSTEM_ID
289             ));
290         sunWebAppVersionMap.put(SunWebApp.VERSION_2_4_0, new VersionInfo(
291                 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_0.SunWebApp.class, SunWebAppProxy.class,
292                 DTDRegistry.SUN_WEBAPP_240_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_240_DTD_SYSTEM_ID
293             ));
294         sunWebAppVersionMap.put(SunWebApp.VERSION_2_4_1, new VersionInfo(
295                 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_1.SunWebApp.class, SunWebAppProxy.class,
296                 DTDRegistry.SUN_WEBAPP_241_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_241_DTD_SYSTEM_ID
297             ));
298         sunWebAppVersionMap.put(SunWebApp.VERSION_2_5_0, new VersionInfo(
299                 org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_5_0.SunWebApp.class, SunWebAppProxy.class,
300                 DTDRegistry.SUN_WEBAPP_250_DTD_PUBLIC_ID, DTDRegistry.SUN_WEBAPP_250_DTD_SYSTEM_ID
301             ));
302
303         sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_0_0, new VersionInfo(
304                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar.class, SunEjbJarProxy.class,
305                 DTDRegistry.SUN_EJBJAR_200_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_200_DTD_SYSTEM_ID
306             ));
307         sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_1_0, new VersionInfo(
308                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar.class, SunEjbJarProxy.class,
309                 DTDRegistry.SUN_EJBJAR_210_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_210_DTD_SYSTEM_ID
310             ));
311         sunEjbJarVersionMap.put(SunEjbJar.VERSION_2_1_1, new VersionInfo(
312                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar.class, SunEjbJarProxy.class,
313                 DTDRegistry.SUN_EJBJAR_211_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_211_DTD_SYSTEM_ID
314             ));
315         sunEjbJarVersionMap.put(SunEjbJar.VERSION_3_0_0, new VersionInfo(
316                 org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar.class, SunEjbJarProxy.class,
317                 DTDRegistry.SUN_EJBJAR_300_DTD_PUBLIC_ID, DTDRegistry.SUN_EJBJAR_300_DTD_SYSTEM_ID
318             ));
319
320         sunApplicationVersionMap.put(SunApplication.VERSION_1_3_0, new VersionInfo(
321                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication.class, SunApplicationProxy.class,
322                 DTDRegistry.SUN_APPLICATION_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_130_DTD_SYSTEM_ID
323             ));
324         sunApplicationVersionMap.put(SunApplication.VERSION_1_4_0, new VersionInfo(
325                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication.class, SunApplicationProxy.class,
326                 DTDRegistry.SUN_APPLICATION_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_140_DTD_SYSTEM_ID
327             ));
328         sunApplicationVersionMap.put(SunApplication.VERSION_5_0_0, new VersionInfo(
329                 org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication.class, SunApplicationProxy.class,
330                 DTDRegistry.SUN_APPLICATION_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPLICATION_50_DTD_SYSTEM_ID
331             ));
332
333         sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_3_0, new VersionInfo(
334                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient.class, SunApplicationClientProxy.class,
335                 DTDRegistry.SUN_APPCLIENT_130_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_130_DTD_SYSTEM_ID
336             ));
337         sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_4_0, new VersionInfo(
338                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient.class, SunApplicationClientProxy.class,
339                 DTDRegistry.SUN_APPCLIENT_140_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_140_DTD_SYSTEM_ID
340             ));
341         sunAppClientVersionMap.put(SunApplicationClient.VERSION_1_4_1, new VersionInfo(
342                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient.class, SunApplicationClientProxy.class,
343                 DTDRegistry.SUN_APPCLIENT_141_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_141_DTD_SYSTEM_ID
344             ));
345         sunAppClientVersionMap.put(SunApplicationClient.VERSION_5_0_0, new VersionInfo(
346                 org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient.class, SunApplicationClientProxy.class,
347                 DTDRegistry.SUN_APPCLIENT_50_DTD_PUBLIC_ID, DTDRegistry.SUN_APPCLIENT_50_DTD_SYSTEM_ID
348             ));
349         
350         apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp.class, sunWebAppVersionMap);
351         apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar.class, sunEjbJarVersionMap);
352         apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication.class, sunApplicationVersionMap);
353         apiToVersionMap.put(org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient.class, sunAppClientVersionMap);
354     }
355     
356     public RootInterface newGraph(Class JavaDoc rootType, String JavaDoc version) {
357         RootInterface result = null;
358         SunBaseBean graphRoot = null;
359         Class JavaDoc graphRootClass = null;
360         
361         Map JavaDoc versionMap = (Map JavaDoc) apiToVersionMap.get(rootType);
362         if(versionMap != null) {
363             VersionInfo vInfo = (VersionInfo) versionMap.get(version);
364             if(vInfo != null) {
365                 try {
366                     // Formerly invoked static 'createGraph()' method, but that is merely a wrapper
367
// for the default constructor so we'll call it directly.
368
graphRoot = (SunBaseBean) vInfo.getImplClass().newInstance();
369                     graphRoot.graphManager().setDoctype(vInfo.getPublicId(), vInfo.getSystemId());
370                     
371                     Class JavaDoc proxyClass = vInfo.getProxyClass();
372                     Constructor JavaDoc proxyConstructor = proxyClass.getConstructor(new Class JavaDoc [] { rootType, String JavaDoc.class });
373                     result = (RootInterface) proxyConstructor.newInstance(new Object JavaDoc [] { graphRoot, version });
374                 } catch(IllegalArgumentException JavaDoc ex) {
375                     // These five exceptions will be caught and logged either in StorageBeanFactory static
376
// initializer or in Base.addToGraphs(). They all represent some type of coding error
377
// on our part and should not occur under normal conditions (unless there is a bug).
378
throw new RuntimeException JavaDoc(ex.getMessage(), ex); // Programmer error
379
} catch(InvocationTargetException JavaDoc ex) {
380                     throw new RuntimeException JavaDoc(ex.getMessage(), ex); // Programmer error
381
} catch(InstantiationException JavaDoc ex) {
382                     throw new RuntimeException JavaDoc(ex.getMessage(), ex); // Programmer error
383
} catch(IllegalAccessException JavaDoc ex) {
384                     throw new RuntimeException JavaDoc(ex.getMessage(), ex); // Programmer error
385
} catch(NoSuchMethodException JavaDoc ex) {
386                     throw new RuntimeException JavaDoc(ex.getMessage(), ex); // Programmer error
387
}
388             } else {
389                 throw new IllegalStateException JavaDoc("No version information for " + version + " of type " + rootType.getName());
390             }
391         } else {
392             throw new IllegalStateException JavaDoc("No version map for " + rootType.getName());
393         }
394         
395         return result;
396     }
397     
398     private static void setAppClientProxyErrorStatus(SunApplicationClientProxy appClientProxy, DDParse parse) {
399         SAXParseException error = parse.getWarning();
400         appClientProxy.setError(error);
401         /*if (error!=null) {
402             appProxy.setStatus(SunApplication.STATE_INVALID_PARSABLE);
403         } else {
404             appProxy.setStatus(SunApplication.STATE_VALID);
405         }*/

406     }
407     
408     /** @deprecated use the version that specifies the graph version you want.
409      */

410     public RootInterface newGraph(Class JavaDoc rootType) {
411         if(org.netbeans.modules.j2ee.sun.dd.api.web.SunWebApp.class.equals(rootType)) {
412             return newGraph(rootType, SunWebApp.VERSION_2_4_1);
413         } else if(org.netbeans.modules.j2ee.sun.dd.api.ejb.SunEjbJar.class.equals(rootType)) {
414             return newGraph(rootType, SunEjbJar.VERSION_2_1_1);
415         } else if(org.netbeans.modules.j2ee.sun.dd.api.app.SunApplication.class.equals(rootType)) {
416             return newGraph(rootType, SunApplication.VERSION_1_4_0);
417         } else if(org.netbeans.modules.j2ee.sun.dd.api.client.SunApplicationClient.class.equals(rootType)) {
418             return newGraph(rootType, SunApplicationClient.VERSION_1_4_1);
419         }
420         
421         return null;
422     }
423     
424     private static SunEjbJar createEjbJar(DDParse parse) {
425           SunEjbJar jar = null;
426           String JavaDoc version = parse.getVersion();
427           if (SunEjbJar.VERSION_3_0_0.equals(version)) {
428               return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES);
429           } else if (SunEjbJar.VERSION_2_1_1.equals(version)) {
430               return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_1.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES);
431           } else if (SunEjbJar.VERSION_2_1_0.equals(version)) {//ludo fix that!!!2.1.0 below
432
return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_1_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES);
433           } else if (SunEjbJar.VERSION_2_0_0.equals(version)) {//ludo fix that!!!2.1.0 below
434
return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_2_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES);
435           } //LUDO CHANGE LATER!!!
436
else{
437               //What should we do there? ludo throws somethig or try with 3.0.0? FIXTIT
438
return new org.netbeans.modules.j2ee.sun.dd.impl.ejb.model_3_0_0.SunEjbJar(parse.getDocument(), Common.NO_DEFAULT_VALUES);
439           }
440           
441         // return jar;
442
}
443     
444     private static SunWebApp createWebApp(DDParse parse) throws DDException {
445         SunWebApp webRoot = null;
446         String JavaDoc version = parse.getVersion();
447         if (SunWebApp.VERSION_2_5_0.equals(version)) {
448             return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_5_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES);
449         } else if (SunWebApp.VERSION_2_4_1.equals(version)) {
450             return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_1.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES);
451         } else if (SunWebApp.VERSION_2_4_0.equals(version)){ //ludo fix that!!!2_4_0 below
452
return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_4_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES);
453         } else if (SunWebApp.VERSION_2_3_0.equals(version)){
454             return new org.netbeans.modules.j2ee.sun.dd.impl.web.model_2_3_0.SunWebApp(parse.getDocument(), Common.NO_DEFAULT_VALUES);
455         }else
456             throw new DDException(
457                     MessageFormat.format(ResourceBundle.getBundle("org/netbeans/modules/j2ee/sun/dd/api/Bundle").getString("MSG_UnknownWebXml"),new Object JavaDoc[] {version} ));
458         
459     }
460   
461     private static SunApplication createApplication(DDParse parse) {
462           SunApplication jar = null;
463           String JavaDoc version = parse.getVersion();
464           if (SunApplication.VERSION_5_0_0.equals(version)) {
465               return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_5_0_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES);
466           } else if (SunApplication.VERSION_1_4_0.equals(version)) {
467               return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_4_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES);
468           } else if(SunApplication.VERSION_1_3_0.equals(version)){
469               return new org.netbeans.modules.j2ee.sun.dd.impl.app.model_1_3_0.SunApplication(parse.getDocument(), Common.NO_DEFAULT_VALUES);
470           }
471           
472           return jar;
473     }
474     
475     private static SunApplicationClient createApplicationClient(DDParse parse) {
476           SunApplicationClient jar = null;
477           String JavaDoc version = parse.getVersion();
478           if (SunApplicationClient.VERSION_5_0_0.equals(version)) {
479               return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_5_0_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES);
480           } else if (SunApplicationClient.VERSION_1_4_1.equals(version)) {
481               return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_1.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES);
482           } else if (SunApplicationClient.VERSION_1_4_0.equals(version)) {
483               return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_4_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES);
484           } else if (SunApplicationClient.VERSION_1_3_0.equals(version)) {
485               return new org.netbeans.modules.j2ee.sun.dd.impl.client.model_1_3_0.SunApplicationClient(parse.getDocument(), Common.NO_DEFAULT_VALUES);
486           }
487           
488           return jar;
489     }
490     
491     /**
492      * Returns the root of Resources bean graph for java.io.File object.
493      *
494      * @param doc XML document representing the .sun-resource file
495      */

496     public Resources getResourcesGraph() {
497         Resources resourcesRoot = org.netbeans.modules.j2ee.sun.dd.impl.serverresources.model.Resources.createGraph();
498         ResourcesProxy proxy = new ResourcesProxy(resourcesRoot);
499         return proxy;
500     }
501     
502     /**
503      * Returns the root of Resources bean graph for java.io.File object.
504      *
505      * @param doc XML document representing the .sun-resource file
506      */

507     public Resources getResourcesGraph(InputStream JavaDoc in) {
508         Resources resourcesRoot = org.netbeans.modules.j2ee.sun.dd.impl.serverresources.model.Resources.createGraph(in);
509         ResourcesProxy proxy = new ResourcesProxy(resourcesRoot);
510         return proxy;
511     }
512     
513     
514     private static class DDResolver implements EntityResolver {
515         static DDResolver resolver;
516         static synchronized DDResolver getInstance() {
517             if (resolver==null) {
518                 resolver=new DDResolver();
519             }
520             return resolver;
521         }
522         public InputSource resolveEntity(String JavaDoc publicId, String JavaDoc systemId) {
523             String JavaDoc resource = null;
524             if (EJB_30_90_DOCTYPE.equals(publicId)) {
525                 //return ejb30
526
resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_3_0-0.dtd"); //NOI18N
527
}else if (EJB_21_81_DOCTYPE.equals(publicId)) {
528                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-1.dtd"); //NOI18N
529
} else if (EJB_21_80_DOCTYPE.equals(publicId)) {
530                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-0.dtd"); //NOI18N
531
} else if (EJB_21_80_DOCTYPE_SUNONE.equals(publicId)) {
532                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_1-0.dtd"); //NOI18N
533
} else if (EJB_20_70_DOCTYPE_SUNONE.equals(publicId)) {////LUDO this 2.0.0 is missing FIXIT
534
resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-ejb-jar_2_0-0.dtd"); //NOI18N
535
} else if (WEB_25_90_DOCTYPE.equals(publicId)) {
536                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_5-0.dtd"); //NOI18N
537
}else if (WEB_21_81_DOCTYPE.equals(publicId)) {
538                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-1.dtd"); //NOI18N
539
} else if (WEB_21_80_DOCTYPE.equals(publicId)) {
540                 resource ="/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-0.dtd"; //NOI18N
541
} else if (WEB_21_80_DOCTYPE_SUNONE.equals(publicId)) {
542                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_4-0.dtd"); //NOI18N
543
} else if (WEB_20_70_DOCTYPE_SUNONE.equals(publicId)) {//LUDO this 2.3.0 is missing FIXIT
544
resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-web-app_2_3-0.dtd"); //NOI18N
545
} else if (APP_50_90_DOCTYPE.equals(publicId)) {
546                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_5_0-0.dtd"); //NOI18N
547
}else if (APP_14_80_DOCTYPE.equals(publicId) || APP_14_81_DOCTYPE.equals(publicId) || APP_14_80_DOCTYPE_SUNONE.equals(publicId) ) {
548                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_1_4-0.dtd"); //NOI18N
549
} else if(APP_13_70_DOCTYPE_SUNONE.equals(publicId)){
550                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application_1_3-0.dtd"); //NOI18N
551
} else if(APPCLIENT_50_90_DOCTYPE.equals(publicId)) {
552                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_5_0-0.dtd"); //NOI18N
553
} else if (APPCLIENT_14_81_DOCTYPE.equals(publicId)) {
554                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-1.dtd"); //NOI18N
555
} else if (APPCLIENT_14_80_DOCTYPE.equals(publicId)) {
556                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-0.dtd"); //NOI18N
557
} else if (APPCLIENT_14_80_DOCTYPE_SUNONE.equals(publicId)) {
558                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_4-0.dtd"); //NOI18N
559
} else if (APPCLIENT_13_70_DOCTYPE.equals(publicId)) {
560                 resource = ("/org/netbeans/modules/j2ee/sun/dd/impl/resources/sun-application-client_1_3-0.dtd"); //NOI18N
561
}
562             java.net.URL JavaDoc url = this.getClass().getResource(resource);
563             return new InputSource(url.toString());
564         }
565     }
566     
567     private static class ErrorHandler implements org.xml.sax.ErrorHandler JavaDoc {
568         private int errorType=-1;
569         SAXParseException error;
570
571         public void warning(org.xml.sax.SAXParseException JavaDoc sAXParseException) throws org.xml.sax.SAXException JavaDoc {
572             if (errorType<0) {
573                 errorType=0;
574                 error=sAXParseException;
575             }
576             //throw sAXParseException;
577
}
578         public void error(org.xml.sax.SAXParseException JavaDoc sAXParseException) throws org.xml.sax.SAXException JavaDoc {
579             if (errorType<1) {
580                 errorType=1;
581                 error=sAXParseException;
582             }
583             //throw sAXParseException;
584
}
585         public void fatalError(org.xml.sax.SAXParseException JavaDoc sAXParseException) throws org.xml.sax.SAXException JavaDoc {
586             errorType=2;
587             throw sAXParseException;
588         }
589         
590         public int getErrorType() {
591             return errorType;
592         }
593         public SAXParseException getError() {
594             return error;
595         }
596     }
597    
598     private DDParse parseDD (InputStream JavaDoc is)
599     throws SAXException, java.io.IOException JavaDoc {
600         return parseDD(new InputSource(is));
601     }
602     
603     private DDParse parseDD(InputSource is) throws SAXException, java.io.IOException JavaDoc {
604         
605         DDProvider.ErrorHandler errorHandler = new DDProvider.ErrorHandler();
606         DocumentBuilder JavaDoc parser = createParser(errorHandler);
607         parser.setEntityResolver(DDResolver.getInstance());
608         Document JavaDoc document = parser.parse(is);
609         SAXParseException error = errorHandler.getError();
610         return new DDParse(document, error);
611     }
612
613     private static DocumentBuilder JavaDoc createParser(ErrorHandler errorHandler) throws SAXException {
614         DocumentBuilder JavaDoc parser=null;
615         try {
616             DocumentBuilderFactory JavaDoc fact = DocumentBuilderFactory.newInstance();
617             parser = fact.newDocumentBuilder();
618         } catch (ParserConfigurationException JavaDoc ex) {
619             throw new SAXException(ex.getMessage());
620         }
621         parser.setErrorHandler(errorHandler);
622         return parser;
623     }
624
625   
626     /**
627      * This class represents one parse of the deployment descriptor
628      */

629     private static class DDParse {
630         private Document JavaDoc document;
631         private SAXParseException saxException;
632         private String JavaDoc version;
633         public DDParse(Document JavaDoc d, SAXParseException saxEx) {
634             document = d;
635             saxException = saxEx;
636             extractVersion();
637         }
638         
639         /**
640          * @return document from last parse
641          */

642         public Document JavaDoc getDocument() {
643             return document;
644         }
645         
646         /**
647          * @return version of deployment descriptor.
648          */

649         private void extractVersion () {
650             // first check the doc type to see if there is one
651
DocumentType JavaDoc dt = document.getDoctype();
652             // This is the default version
653
version = SunEjbJar.VERSION_3_0_0;
654             if (dt != null) {
655                 if (EJB_21_81_DOCTYPE.equals(dt.getPublicId())) {
656                     version = SunEjbJar.VERSION_2_1_1;
657                 }else if (EJB_21_80_DOCTYPE.equals(dt.getPublicId())) {
658                     version = SunEjbJar.VERSION_2_1_0;
659                 }else if (EJB_30_90_DOCTYPE.equals(dt.getPublicId())) {
660                     version = SunEjbJar.VERSION_3_0_0;
661                 }else if(EJB_21_80_DOCTYPE_SUNONE.equals(dt.getPublicId())) {
662                     version = SunEjbJar.VERSION_2_1_0;
663                 }else if(EJB_20_70_DOCTYPE_SUNONE.equals(dt.getPublicId())) {
664                     version = SunEjbJar.VERSION_2_0_0;
665                 }else if(WEB_25_90_DOCTYPE.equals(dt.getPublicId())){
666                     version = SunWebApp.VERSION_2_5_0;
667                 }else if(WEB_21_81_DOCTYPE.equals(dt.getPublicId())){
668                     version = SunWebApp.VERSION_2_4_1;
669                 }else if(WEB_21_80_DOCTYPE.equals(dt.getPublicId())){
670                     version = SunWebApp.VERSION_2_4_0;
671                 }else if(WEB_21_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){
672                     version = SunWebApp.VERSION_2_4_0;
673                 }else if(WEB_20_70_DOCTYPE_SUNONE.equals(dt.getPublicId())){
674                     version = SunWebApp.VERSION_2_3_0;
675                 }else if(APP_50_90_DOCTYPE.equals(dt.getPublicId())){
676                     version = SunApplication.VERSION_5_0_0;
677                 }else if(APP_14_80_DOCTYPE.equals(dt.getPublicId()) || APP_14_81_DOCTYPE.equals(dt.getPublicId()) || APP_14_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){
678                     version = SunApplication.VERSION_1_4_0;
679                 }else if(APP_13_70_DOCTYPE_SUNONE.equals(dt.getPublicId())) {
680                     version = SunApplication.VERSION_1_3_0;
681                 }else if (APPCLIENT_50_90_DOCTYPE.equals(dt.getPublicId())){
682                     version = SunApplicationClient.VERSION_5_0_0;
683                 }else if (APPCLIENT_14_81_DOCTYPE.equals(dt.getPublicId())){
684                     version = SunApplicationClient.VERSION_1_4_1;
685                 }else if(APPCLIENT_14_80_DOCTYPE.equals(dt.getPublicId()) || APPCLIENT_14_80_DOCTYPE_SUNONE.equals(dt.getPublicId())){
686                     version = SunApplicationClient.VERSION_1_4_0;
687                 }else if(APPCLIENT_13_70_DOCTYPE.equals(dt.getPublicId())){
688                     version = SunApplicationClient.VERSION_1_3_0;
689                 }
690             }
691         }
692         
693         public String JavaDoc getVersion() {
694             return version;
695         }
696         
697         /**
698          * @return validation error encountered during the parse
699          */

700         public SAXParseException getWarning() {
701             return saxException;
702         }
703     }
704     
705 }
706
Popular Tags