KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > sun > ide > j2ee > RunTimeDDCatalog


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.ide.j2ee;
21
22 import java.beans.FeatureDescriptor JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.io.File JavaDoc;
25 import java.io.IOException JavaDoc;
26 import java.util.ArrayList JavaDoc;
27 import java.util.Enumeration JavaDoc;
28 import java.util.List JavaDoc;
29 import org.netbeans.modules.j2ee.deployment.plugins.api.InstanceProperties;
30 import org.netbeans.modules.j2ee.sun.api.ServerLocationManager;
31 import org.netbeans.modules.xml.api.model.GrammarEnvironment;
32 import org.netbeans.modules.xml.api.model.GrammarQuery;
33 import org.openide.util.NbBundle;
34 import org.openide.util.Utilities;
35 import org.w3c.dom.Element JavaDoc;
36 import org.w3c.dom.Node JavaDoc;
37 import org.netbeans.modules.xml.api.model.DTDUtil;
38 import org.netbeans.api.xml.services.UserCatalog;
39 import org.netbeans.modules.xml.api.model.GrammarQueryManager;
40 import org.netbeans.modules.xml.catalog.spi.CatalogDescriptor;
41 import org.netbeans.modules.xml.catalog.spi.CatalogListener;
42 import org.netbeans.modules.xml.catalog.spi.CatalogReader;
43 import org.xml.sax.EntityResolver JavaDoc;
44 import org.xml.sax.InputSource JavaDoc;
45 import org.xml.sax.SAXException JavaDoc;
46
47
48 /** Catalog for App Server 8PE DTDs that enables completion support in editor.
49  *
50  * @author Ludo
51  */

52
53 public class RunTimeDDCatalog extends GrammarQueryManager implements CatalogReader, CatalogDescriptor,org.xml.sax.EntityResolver JavaDoc {
54     
55     private static final String JavaDoc XML_XSD="http://www.w3.org/2001/xml.xsd"; // NOI18N
56
private static final String JavaDoc XML_XSD_DEF="<?xml version='1.0'?><xs:schema targetNamespace=\"http://www.w3.org/XML/1998/namespace\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xml:lang=\"en\"><xs:attribute name=\"lang\" type=\"xs:language\"><xs:annotation><xs:documentation>In due course, we should install the relevant ISO 2- and 3-letter codes as the enumerated possible values . . .</xs:documentation></xs:annotation></xs:attribute></xs:schema>"; // NOI18N
57
private static final String JavaDoc TypeToURLMap[] = {
58         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 J2EE Application 1.3//EN" , "sun-application_1_3-0.dtd" ,
59         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 J2EE Application 1.4//EN" , "sun-application_1_4-0.dtd" , ///[THIS IS DEPRECATED]
60
"-//Sun Microsystems, Inc.//DTD Application Server 8.0 J2EE Application 1.4//EN" , "sun-application_1_4-0.dtd" ,
61         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 J2EE Application 1.4//EN" , "sun-application_1_4-0.dtd" ,
62         "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Java EE Application 5.0//EN" , "sun-application_5_0-0.dtd",
63         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 EJB 2.0//EN" , "sun-ejb-jar_2_0-0.dtd" ,
64         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 EJB 2.1//EN" , "sun-ejb-jar_2_1-0.dtd" , ///[THIS IS DEPRECATED]
65
"-//Sun Microsystems, Inc.//DTD Application Server 8.0 EJB 2.1//EN" , "sun-ejb-jar_2_1-0.dtd" ,
66         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 EJB 2.1//EN" , "sun-ejb-jar_2_1-1.dtd" ,
67         "-//Sun Microsystems, Inc.//DTD Application Server 9.0 EJB 3.0//EN" , "sun-ejb-jar_3_0-0.dtd",
68         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client 1.3//EN" , "sun-application-client_1_3-0.dtd" ,
69         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Application Client 1.4//EN" , "sun-application-client_1_4-0.dtd" , ///[THIS IS DEPRECATED]
70
"-//Sun Microsystems, Inc.//DTD Application Server 8.0 Application Client 1.4//EN" , "sun-application-client_1_4-0.dtd" ,
71         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Application Client 1.4//EN" , "sun-application-client_1_4-1.dtd" ,
72         "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Application Client 5.0//EN" , "sun-application-client_5_0-0.dtd" ,
73         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Connector 1.0//EN" , "sun-connector_1_0-0.dtd" ,
74         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Servlet 2.3//EN" , "sun-web-app_2_3-0.dtd" ,
75         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 8.0 Servlet 2.4//EN" , "sun-web-app_2_4-0.dtd" , ///[THIS IS DEPRECATED]
76
"-//Sun Microsystems, Inc.//DTD Application Server 8.0 Servlet 2.4//EN" , "sun-web-app_2_4-0.dtd" ,
77         "-//Sun Microsystems, Inc.//DTD Sun ONE Web Server 6.1 Servlet 2.3//EN" , "sun-web-app_2_3-1.dtd" ,
78         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Servlet 2.4//EN" , "sun-web-app_2_4-1.dtd" ,
79         "-//Sun Microsystems, Inc.//DTD Application Server 9.0 Servlet 2.5//EN" , "sun-web-app_2_5-0.dtd" ,
80         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 Application Client Container 1.0//EN" , "sun-application-client-container_1_0.dtd" ,
81         "-//Sun Microsystems, Inc.//DTD Sun ONE Application Server 7.0 OR Mapping //EN" , "sun-cmp-mapping_1_0.dtd" ,
82         "-//Sun Microsystems, Inc.//DTD Application Server 8.0 OR Mapping//EN" , "sun-cmp-mapping_1_1.dtd" ,
83         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 OR Mapping//EN" , "sun-cmp-mapping_1_2.dtd" ,
84         "-//Sun Microsystems, Inc.//DTD Application Server 8.0 Domain//EN" , "sun-domain_1_0.dtd" ,
85         "-//Sun Microsystems Inc.//DTD Application Server 8.0 Application Client Container//EN" , "sun-application-client-container_1_2.dtd" ,
86         "-//Sun Microsystems, Inc.//DTD Application Server 8.1 Application Client Container //EN" , "sun-application-client-container_1_1.dtd" ,
87         "-//Sun Microsystems Inc.//DTD Application Server 8.0 Domain//EN" ,"sun-domain_1_1.dtd",
88         "-//Sun Microsystems Inc.//DTD Application Server 8.1 Domain//EN" ,"sun-domain_1_1.dtd",
89         
90         "-//Sun Microsystems, Inc.//DTD J2EE Application 1.3//EN" , "application_1_3.dtd",
91         "-//Sun Microsystems, Inc.//DTD J2EE Application 1.2//EN" , "application_1_2.dtd",
92         "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" , "ejb-jar_2_0.dtd",
93         "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 1.1//EN" , "ejb-jar_1_1.dtd",
94         "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.3//EN" , "application-client_1_3.dtd",
95         "-//Sun Microsystems, Inc.//DTD J2EE Application Client 1.2//EN" , "application-client_1_2.dtd",
96         "-//Sun Microsystems, Inc.//DTD Connector 1.0//EN" , "connector_1_0.dtd",
97         "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" , "web-app_2_3.dtd",
98         "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN" , "web-app_2_2.dtd",
99         "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.2//EN" , "web-jsptaglibrary_1_2.dtd",
100         "-//Sun Microsystems, Inc.//DTD JSP Tag Library 1.1//EN" , "web-jsptaglibrary_1_1.dtd",
101     };
102     
103     /*******NetBeans 3.6 is NOT ready yet to support schemas for code completion... What a pity!: */
104     private static final String JavaDoc SchemaToURLMap[] = {
105         
106         "SCHEMA:http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd" , "ejb-jar_2_1",
107         
108         "SCHEMA:http://java.sun.com/xml/ns/j2ee/application-client_1_4.xsd" , "application-client_1_4",
109         "SCHEMA:http://java.sun.com/xml/ns/j2ee/application_1_4.xsd" , "application_1_4",
110         "SCHEMA:http://java.sun.com/xml/ns/j2ee/jax-rpc-ri-config.xsd" , "jax-rpc-ri-config",
111         "SCHEMA:http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd" , "connector_1_5",
112         ///"SCHEMA:http://java.sun.com/xml/ns/j2ee/jsp_2_0.xsd" , "jsp_2_0.xsd",
113
///"SCHEMA:http://java.sun.com/xml/ns/j2ee/datatypes.dtd" , "datatypes",
114
///"SCHEMA:http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" , "web-app_2_4",
115
///"SCHEMA:http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd" , "web-jsptaglibrary_2_0",
116
///"SCHEMA:http://java.sun.com/xml/ns/j2ee/j2ee_1_4.xsd" , "j2ee_1_4",
117
"SCHEMA:http://java.sun.com/xml/ns/j2ee/j2ee_jaxrpc_mapping_1_1.xsd" , "j2ee_jaxrpc_mapping_1_1",
118         "SCHEMA:http://www.ibm.com/webservices/xsd/j2ee_web_services_1_1.xsd" ,"j2ee_web_services_1_1",
119        // "SCHEMA:http://www.ibm.com/webservices/xsd/j2ee_web_services_client_1_1.xsd" ,"j2ee_web_services_client_1_1",
120
"SCHEMA:http://java.sun.com/xml/ns/javaee/ejb-jar_3_0.xsd" , "ejb-jar_3_0",
121         "SCHEMA:http://java.sun.com/xml/ns/javaee/application-client_5.xsd" , "application-client_5",
122         "SCHEMA:http://java.sun.com/xml/ns/javaee/application_5.xsd" , "application_5",
123         "SCHEMA:http://java.sun.com/xml/ns/persistence/orm_1_0.xsd" , "orm_1_0",
124         "SCHEMA:http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" , "persistence_1_0",
125
126     };
127     
128     File JavaDoc platformRootDir=null;
129     
130     /** Creates a new instance of RunTimeDDCatalog */
131     public RunTimeDDCatalog() {
132         // lazy call to possible registration. This is called only when needed (i.e runtime tab DTD exploration
133
InstanceProperties.getInstanceList();
134         PluginProperties.configureDefaultServerInstance();
135         platformRootDir = ServerLocationManager.getLatestPlatformLocation();
136     }
137     private static RunTimeDDCatalog ddCatalog;
138     
139     /** Factory method providing catalog for XML completion of DD */
140     public static synchronized RunTimeDDCatalog getRunTimeDDCatalog(){
141         if (ddCatalog==null) {
142             ddCatalog = new RunTimeDDCatalog();
143         }
144         return ddCatalog;
145     }
146     /**
147      * Get String iterator representing all public IDs registered in catalog.
148      * @return null if cannot proceed, try later.
149      */

150     public java.util.Iterator JavaDoc getPublicIDs() {
151         if (platformRootDir == null) {
152             return null;
153         }
154         if (!platformRootDir.exists()) {
155             return null;
156         }
157         
158         String JavaDoc installRoot = platformRootDir.getAbsolutePath();
159         if (installRoot == null) {
160             return null;
161         }
162         
163         java.util.List JavaDoc list = new java.util.ArrayList JavaDoc();
164         for (int i=0;i<TypeToURLMap.length;i = i+2){
165             list.add(TypeToURLMap[i]);
166         }
167         for (int i=0;i<SchemaToURLMap.length;i = i+2){
168             list.add(SchemaToURLMap[i]);
169         }
170         
171         return list.listIterator();
172     }
173
174     /**
175      * Get registered systemid for given public Id or null if not registered.
176      * @return null if not registered
177      */

178     public String JavaDoc getSystemID(String JavaDoc publicId) {
179         if (platformRootDir == null) {
180             return null;
181         }
182         if (!platformRootDir.exists()) {
183             return null;
184         }
185         
186         String JavaDoc installRoot = platformRootDir.getAbsolutePath(); //System.getProperty("com.sun.aas.installRoot");
187
if (installRoot == null) {
188             return null;
189         }
190         String JavaDoc loc="dtds";
191         for (int i=0;i<TypeToURLMap.length;i = i+2){
192             if (TypeToURLMap[i].equals(publicId)){
193                 File JavaDoc file = new File JavaDoc(installRoot+"/lib/"+loc+"/"+TypeToURLMap[i+1]);
194                 try{
195                     return file.toURI().toURL().toExternalForm();
196                 }catch(Exception JavaDoc e){
197                     return "";
198                 }
199             }
200         }
201         loc="schemas";
202         for (int i=0;i<SchemaToURLMap.length;i = i+2){
203             if (SchemaToURLMap[i].equals(publicId)){
204                 return "nbres:/org/netbeans/modules/j2ee/sun/ide/resources/"+SchemaToURLMap[i+1]+".dtd";
205                 
206                 
207             }
208         }
209         return null;
210     }
211     
212     /**
213      * Refresh content according to content of mounted catalog.
214      */

215     public void refresh() {
216         File JavaDoc newLoc = ServerLocationManager.getLatestPlatformLocation();
217         if (platformRootDir!=newLoc){
218             platformRootDir = newLoc;
219             getRunTimeDDCatalog().fireCatalogListeners();
220         }
221     
222     }
223     
224     private List JavaDoc catalogListeners = new ArrayList JavaDoc(1);
225     
226     /**
227      * Optional operation allowing to listen at catalog for changes.
228      * @throws UnsupportedOpertaionException if not supported by the implementation.
229      */

230     public void addCatalogListener(CatalogListener l) {
231         if (null == l)
232             return;
233         if (catalogListeners.contains(l))
234             return;
235         catalogListeners.add(l);
236     }
237     
238     /**
239      * Optional operation couled with addCatalogListener.
240      * @throws UnsupportedOpertaionException if not supported by the implementation.
241      */

242     public void removeCatalogListener(CatalogListener l) {
243         if (null == l)
244             return;
245         if (catalogListeners.contains(l))
246             catalogListeners.remove(l);
247     }
248     
249     public void fireCatalogListeners() {
250         platformRootDir = ServerLocationManager.getLatestPlatformLocation();
251         java.util.Iterator JavaDoc iter = catalogListeners.iterator();
252         while (iter.hasNext()) {
253             CatalogListener l = (CatalogListener) iter.next();
254             l.notifyInvalidate();
255         }
256     }
257     
258     /** Registers new listener. */
259     public void addPropertyChangeListener(PropertyChangeListener JavaDoc l) {
260     }
261     
262     /**
263      * @return I18N display name
264      */

265     public String JavaDoc getDisplayName() {
266         return NbBundle.getMessage(RunTimeDDCatalog.class, "LBL_RunTimeDDCatalog");
267     }
268     
269     /**
270      * Return visuaized state of given catalog.
271      * @param type of icon defined by JavaBeans specs
272      * @return icon representing current state or null
273      */

274     public java.awt.Image JavaDoc getIcon(int type) {
275         return Utilities.loadImage("org/netbeans/modules/j2ee/sun/ide/resources/ServerInstanceIcon.png"); // NOI18N
276
}
277     
278     /**
279      * @return I18N short description
280      */

281     public String JavaDoc getShortDescription() {
282         return NbBundle.getMessage(RunTimeDDCatalog.class, "DESC_RunTimeDDCatalog");
283     }
284     
285     /** Unregister the listener. */
286     public void removePropertyChangeListener(java.beans.PropertyChangeListener JavaDoc l) {
287     }
288     
289     public static final String JavaDoc J2EE_NS = "http://java.sun.com/xml/ns/j2ee"; // NOI18N
290
public static final String JavaDoc JAVAEE_NS = "http://java.sun.com/xml/ns/javaee"; // NOI18N
291
public static final String JavaDoc RI_CONFIG_NS = "http://java.sun.com/xml/ns/jax-rpc/ri/config"; // NOI18N
292

293     public static final String JavaDoc IBM_J2EE_NS = "http://www.ibm.com/webservices/xsd"; // NOI18N
294
private static final String JavaDoc XMLNS_ATTR="xmlns"; //NOI18N
295
// public org.xml.sax.InputSource resolveEntity(String publicId, String systemId) throws org.xml.sax.SAXException, java.io.IOException {
296
// return null;
297
// }
298
private static final String JavaDoc EJB_JAR_TAG="ejb-jar"; //NOI18N
299
private static final String JavaDoc EJBJAR_2_1_XSD="ejb-jar_2_1.xsd"; // NOI18N
300
private static final String JavaDoc EJBJAR_2_1 = J2EE_NS+"/"+EJBJAR_2_1_XSD; // NOI18N
301
public static final String JavaDoc EJBJAR_2_1_ID = "SCHEMA:"+EJBJAR_2_1; // NOI18N
302

303     private static final String JavaDoc EJBJAR_3_0_XSD="ejb-jar_3_0.xsd"; // NOI18N
304
private static final String JavaDoc EJBJAR_3_0 = JAVAEE_NS+"/"+EJBJAR_3_0_XSD; // NOI18N
305
public static final String JavaDoc EJBJAR_3_0_ID = "SCHEMA:"+EJBJAR_3_0; // NOI18N
306

307     private static final String JavaDoc APP_TAG="application"; //NOI18N
308
private static final String JavaDoc APP_1_4_XSD="application_1_4.xsd"; // NOI18N
309
private static final String JavaDoc APP_1_4= J2EE_NS+"/"+APP_1_4_XSD; // NOI18N
310
public static final String JavaDoc APP_1_4_ID = "SCHEMA:"+APP_1_4; // NOI18N
311

312     private static final String JavaDoc APP_5_XSD="application_5.xsd"; // NOI18N
313
private static final String JavaDoc APP_5= JAVAEE_NS+"/"+APP_5_XSD; // NOI18N
314
public static final String JavaDoc APP_5_ID = "SCHEMA:"+APP_5; // NOI18N
315

316     
317     private static final String JavaDoc APPCLIENT_TAG="application-client"; //NOI18N
318
private static final String JavaDoc APPCLIENT_1_4_XSD="application-client_1_4.xsd"; // NOI18N
319
private static final String JavaDoc APPCLIENT_1_4= J2EE_NS+"/"+APPCLIENT_1_4_XSD; // NOI18N
320
public static final String JavaDoc APPCLIENT_1_4_ID = "SCHEMA:"+APPCLIENT_1_4; // NOI18N
321

322     private static final String JavaDoc APPCLIENT_5_XSD="application-client_5.xsd"; // NOI18N
323
private static final String JavaDoc APPCLIENT_5= JAVAEE_NS+"/"+APPCLIENT_5_XSD; // NOI18N
324
public static final String JavaDoc APPCLIENT_5_ID = "SCHEMA:"+APPCLIENT_5; // NOI18N
325

326     
327     private static final String JavaDoc WEBSERVICES_TAG="webservices"; //NOI18N
328
private static final String JavaDoc WEBSERVICES_1_1_XSD="j2ee_web_services_1_1.xsd"; // NOI18N
329
private static final String JavaDoc WEBSERVICES_1_1= IBM_J2EE_NS+"/"+WEBSERVICES_1_1_XSD; // NOI18N
330
public static final String JavaDoc WEBSERVICES_1_1_ID = "SCHEMA:"+WEBSERVICES_1_1; // NOI18N
331

332     private static final String JavaDoc WEBSERVICES_1_2_XSD="javaee_web_services_1_2.xsd"; // NOI18N
333
private static final String JavaDoc WEBSERVICES_1_2= JAVAEE_NS+"/"+WEBSERVICES_1_2_XSD; // NOI18N
334
public static final String JavaDoc WEBSERVICES_1_2_ID = "SCHEMA:"+WEBSERVICES_1_2; // NOI18N
335

336     private static final String JavaDoc WEBAPP_TAG="web-app"; //NOI18N
337
private static final String JavaDoc WEBAPP_2_5_XSD="web-app_2_5.xsd"; // NOI18N
338
private static final String JavaDoc WEBAPP_2_5 = JAVAEE_NS+"/"+WEBAPP_2_5_XSD; // NOI18N
339
public static final String JavaDoc WEBAPP_2_5_ID = "SCHEMA:"+WEBAPP_2_5; // NOI18N
340

341     public static final String JavaDoc PERSISTENCE_NS = "http://java.sun.com/xml/ns/persistence"; // NOI18N
342
private static final String JavaDoc PERSISTENCE_TAG="persistence"; //NOI18N
343
private static final String JavaDoc PERSISTENCE_XSD="persistence_1_0.xsd"; // NOI18N
344
private static final String JavaDoc PERSISTENCE = PERSISTENCE_NS+"/"+PERSISTENCE_XSD; // NOI18N
345
public static final String JavaDoc PERSISTENCE_ID = "SCHEMA:"+PERSISTENCE; // NOI18N
346

347     public static final String JavaDoc PERSISTENCEORM_NS = "http://java.sun.com/xml/ns/persistence/orm"; // NOI18N
348
private static final String JavaDoc PERSISTENCEORM_TAG="entity-mappings"; //NOI18N
349
private static final String JavaDoc PERSISTENCEORM_XSD="orm_1_0.xsd"; // NOI18N
350
private static final String JavaDoc PERSISTENCEORM = PERSISTENCE_NS+"/"+PERSISTENCEORM_XSD; // NOI18N yes not ORM NS!!!
351
public static final String JavaDoc PERSISTENCEORM_ID = "SCHEMA:"+PERSISTENCEORM; // NOI18N
352

353
354     
355     
356     public String JavaDoc getFullURLFromSystemId(String JavaDoc systemId){
357         return null;
358         
359     }
360     
361     private static String JavaDoc SCHEMASLOCATION=null;
362     /**
363      * Resolves schema definition file for deployment descriptor (spec.2_4)
364      * @param publicId publicId for resolved entity (null in our case)
365      * @param systemId systemId for resolved entity
366      * @return InputSource for
367      */

368     public InputSource JavaDoc resolveEntity(String JavaDoc publicId, String JavaDoc systemId) throws SAXException JavaDoc, IOException JavaDoc {
369         
370         if (SCHEMASLOCATION == null) {
371             if (platformRootDir == null) {
372                 return null;
373             }
374             if (!platformRootDir.exists()) {
375                 return null;
376             }
377         
378             String JavaDoc installRoot = platformRootDir.getAbsolutePath(); //System.getProperty("com.sun.aas.installRoot");
379
if (installRoot==null)
380                 return null;
381             File JavaDoc f = new File JavaDoc(installRoot);
382             if (f.exists()==false)
383                 return null;
384             File JavaDoc file = new File JavaDoc(installRoot+"/lib/schemas/");
385             SCHEMASLOCATION = "";
386             try{
387                 SCHEMASLOCATION= file.toURI().toURL().toExternalForm();
388             }catch(Exception JavaDoc e){
389                 
390             }
391
392             
393         }
394         if (systemId!=null && systemId.endsWith(EJBJAR_2_1_XSD)) {
395             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+EJBJAR_2_1_XSD);
396         }
397         else if (systemId!=null && systemId.endsWith(EJBJAR_3_0_XSD)) {
398             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+EJBJAR_3_0_XSD);
399         }
400         else if (systemId!=null && systemId.endsWith(APP_1_4_XSD)) {
401             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+APP_1_4_XSD);
402         }
403         else if (systemId!=null && systemId.endsWith(WEBAPP_2_5_XSD)) {
404             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+WEBAPP_2_5_XSD);
405         }
406         else if (systemId!=null && systemId.endsWith(APP_5_XSD)) {
407             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+APP_5_XSD);
408         }
409         else if (systemId!=null && systemId.endsWith(PERSISTENCEORM_XSD)) {
410             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+PERSISTENCEORM_XSD);
411         }
412         else if (systemId!=null && systemId.endsWith(PERSISTENCE_XSD)) {
413             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+PERSISTENCE_XSD);
414         }
415         else if (systemId!=null && systemId.endsWith(WEBSERVICES_1_1_XSD)) {
416             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+WEBSERVICES_1_1_XSD);
417         }
418         else if (systemId!=null && systemId.endsWith(WEBSERVICES_1_2_XSD)) {
419             return new org.xml.sax.InputSource JavaDoc(SCHEMASLOCATION+WEBSERVICES_1_2_XSD);
420         } else if (XML_XSD.equals(systemId)) {
421             return new org.xml.sax.InputSource JavaDoc(new java.io.StringReader JavaDoc(XML_XSD_DEF));
422         }
423         else {
424             return null;
425         }
426     }
427     
428     
429     
430     public Enumeration JavaDoc enabled(GrammarEnvironment ctx) {
431         if (ctx.getFileObject() == null) return null;
432         InputSource JavaDoc is= ctx.getInputSource();
433         java.util.Enumeration JavaDoc en = ctx.getDocumentChildren();
434         while (en.hasMoreElements()) {
435             Node JavaDoc next = (Node JavaDoc) en.nextElement();
436             if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) {
437                 return null; // null for web.xml specified by DTD
438
} else if (next.getNodeType() == next.ELEMENT_NODE) {
439                 Element JavaDoc element = (Element JavaDoc) next;
440                 String JavaDoc tag = element.getTagName();
441                 if (EJB_JAR_TAG.equals(tag)) { // NOI18N
442
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
443                     if (xmlns!=null && J2EE_NS.equals(xmlns)) {
444                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
445                         v.add(next);
446                         return v.elements();
447                         // return org.openide.util.Enumerations.singleton(next);
448
}
449                     else if (xmlns!=null && JAVAEE_NS.equals(xmlns)) {
450                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
451                         v.add(next);
452                         return v.elements();
453                         // return org.openide.util.Enumerations.singleton(next);
454
}
455                 }
456                 
457                 if (APP_TAG.equals(tag)) { // NOI18N
458
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
459                     if (xmlns!=null && J2EE_NS.equals(xmlns)) {
460                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
461                         v.add(next);
462                         return v.elements();
463                         // return org.openide.util.Enumerations.singleton(next);
464
}
465                     else if (xmlns!=null && JAVAEE_NS.equals(xmlns)) {
466                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
467                         v.add(next);
468                         return v.elements();
469                         // return org.openide.util.Enumerations.singleton(next);
470
}
471                 }
472                 if (WEBAPP_TAG.equals(tag)) { // NOI18N
473
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
474                     if (xmlns!=null && JAVAEE_NS.equals(xmlns)) {
475                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
476                         v.add(next);
477                         return v.elements();
478                         // return org.openide.util.Enumerations.singleton(next);
479
}
480
481                 }
482                 if (APPCLIENT_TAG.equals(tag)) { // NOI18N
483
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
484                     if (xmlns!=null && J2EE_NS.equals(xmlns)) {
485                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
486                         v.add(next);
487                         return v.elements();
488                         // return org.openide.util.Enumerations.singleton(next);
489
}
490                     else if (xmlns!=null && JAVAEE_NS.equals(xmlns)) {
491                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
492                         v.add(next);
493                         return v.elements();
494                         // return org.openide.util.Enumerations.singleton(next);
495
}
496                 }
497                 if (PERSISTENCEORM_TAG.equals(tag)) { // NOI18N
498
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
499                     if (xmlns!=null && PERSISTENCEORM_NS.equals(xmlns)) {
500                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
501                         v.add(next);
502                         return v.elements();
503                         // return org.openide.util.Enumerations.singleton(next);
504
}
505
506                 }
507                 
508                 if (PERSISTENCE_TAG.equals(tag)) { // NOI18N
509
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
510                     if (xmlns!=null && PERSISTENCE_NS.equals(xmlns)) {
511                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
512                         v.add(next);
513                         return v.elements();
514                         // return org.openide.util.Enumerations.singleton(next);
515
}
516
517                 }
518                 
519                 if (WEBSERVICES_TAG.equals(tag)) { // NOI18N
520
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
521                     if (xmlns!=null && J2EE_NS.equals(xmlns)) {
522                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
523                         v.add(next);
524                         return v.elements();
525                         // return org.openide.util.Enumerations.singleton(next);
526
} else if (xmlns!=null && JAVAEE_NS.equals(xmlns)) {
527                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
528                         v.add(next);
529                         return v.elements();
530                         // return org.openide.util.Enumerations.singleton(next);
531
}
532                     else if (xmlns!=null && IBM_J2EE_NS.equals(xmlns)) {
533                         java.util.Vector JavaDoc v = new java.util.Vector JavaDoc();
534                         v.add(next);
535                         return v.elements();
536                         // return org.openide.util.Enumerations.singleton(next);
537
}
538                 }
539             }
540         }
541         
542         return null;
543     }
544     
545     public FeatureDescriptor JavaDoc getDescriptor() {
546         return new FeatureDescriptor JavaDoc();
547     }
548     
549     /** Returns pseudo DTD for code completion
550      */

551     public GrammarQuery getGrammar(GrammarEnvironment ctx) {
552         UserCatalog catalog = UserCatalog.getDefault();
553         ///System.out.println("bbb");
554
InputSource JavaDoc is= ctx.getInputSource();
555         //System.out.println(is.getPublicId());
556
//System.out.println(is.getSystemId());
557
//System.out.println(is);
558
if (catalog != null) {
559             
560             EntityResolver JavaDoc resolver = catalog.getEntityResolver();
561             if (resolver != null) {
562                 try {
563                     
564                     
565                     if (ctx.getFileObject() == null) {
566                         return null;
567                     }
568                     InputSource JavaDoc inputSource = null;
569                     
570                     String JavaDoc mimeType = ctx.getFileObject().getMIMEType();
571                     if (mimeType==null){
572                         return null;
573                     }
574                     if (mimeType.equals("text/x-dd-ejbjar3.0")){// NOI18N
575
inputSource = resolver.resolveEntity(EJBJAR_3_0_ID, "");
576                     } else if (mimeType.equals("text/x-dd-ejbjar2.1")) {// NOI18N
577
inputSource = resolver.resolveEntity(EJBJAR_2_1_ID, "");
578                     } else if (mimeType.equals("text/x-dd-application5.0")) {// NOI18N
579
inputSource = resolver.resolveEntity(APP_5_ID, "");
580                     }else if (mimeType.equals("text/x-dd-application1.4")) {// NOI18N
581
inputSource = resolver.resolveEntity(APP_1_4_ID, "");
582                     }else if (mimeType.equals("text/x-dd-client5.0")) {// NOI18N
583
inputSource = resolver.resolveEntity(APPCLIENT_5_ID, "");
584                     }else if (mimeType.equals("text/x-dd-client1.4")) {// NOI18N
585
inputSource = resolver.resolveEntity(APPCLIENT_1_4_ID, "");
586                     }else if (mimeType.equals("text/x-persistence1.0")) {// NOI18N
587
inputSource = resolver.resolveEntity(PERSISTENCE_ID, "");
588                     }else if (mimeType.equals("text/x-orm1.0")) {// NOI18N
589
inputSource = resolver.resolveEntity(PERSISTENCEORM_ID, "");
590                     }
591
592                     if (inputSource!=null) {
593                         return DTDUtil.parseDTD(true, inputSource);
594                     }
595                     
596                     
597                     if (is.getSystemId().endsWith("webservices.xml") ) { // NOI18N
598
// System.out.println("webservices tag");
599
inputSource = resolver.resolveEntity(WEBSERVICES_1_1_ID, "");
600                         if (inputSource!=null) {
601                             return DTDUtil.parseDTD(true, inputSource);
602                         }
603                         
604                         
605                     }
606                     
607                 } catch(SAXException JavaDoc e) {
608                 } catch(java.io.IOException JavaDoc e) {
609                     //System.out.println("eeee");
610
e.printStackTrace();
611                 }
612             }
613         }
614         return null;
615     }
616
617     /**
618      * Get registered URI for the given name or null if not registered.
619      * @return null if not registered
620      */

621     public String JavaDoc resolveURI(String JavaDoc name) {
622         // System.out.println("resolveURI(String name)="+name);
623
if (platformRootDir == null) {
624             return null;
625         }
626         if (!platformRootDir.exists()) {
627             return null;
628         }
629         String JavaDoc installRoot = platformRootDir.getAbsolutePath();
630         String JavaDoc prefix ="";
631         File JavaDoc file = new File JavaDoc(installRoot+"/lib/schemas/");
632         try{
633             prefix= file.toURI().toURL().toExternalForm();
634         }catch(Exception JavaDoc e){
635             
636         }
637         if (name.equals("http://java.sun.com/xml/ns/jax-rpc/ri/config")){
638             return prefix +"jax-rpc-ri-config.xsd";
639         }
640 // if (name.equals("http://java.sun.com/xml/ns/persistence")){
641
// System.out.println("prefix +persistence.xsd="+ prefix +"persistence.xsd");
642
// return prefix +"persistence.xsd";
643
// }
644
// ludo: this is meant to be this way.
645
if (name.equals("http://java.sun.com/xml/ns/j2eeppppppp")){
646             return prefix +"j2ee_web_services_1_1.xsd";
647         }
648         
649         return null;
650     }
651     /**
652      * Get registered URI for the given publicId or null if not registered.
653      * @return null if not registered
654      */

655     public String JavaDoc resolvePublic(String JavaDoc publicId) {
656         return null;
657     }
658 }
659
Popular Tags