KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > j2ee > ddloaders > ejb > DDGrammarQueryManager


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.ddloaders.ejb;
21 import java.util.Enumeration JavaDoc;
22 import org.w3c.dom.Element JavaDoc;
23 import org.w3c.dom.Node JavaDoc;
24 import org.xml.sax.*;
25 //import org.netbeans.modules.xml.api.model.DTDUtil;
26
import org.netbeans.api.xml.services.UserCatalog;
27
28 /** DD Grammar provided code completion for web.xml specified by XML schema.
29  *
30  * @author mk115033
31  */

32 public class DDGrammarQueryManager extends org.netbeans.modules.xml.api.model.GrammarQueryManager
33 {
34     private static final String JavaDoc XMLNS_ATTR="xmlns"; //NOI18N
35
private static final String JavaDoc WEB_APP_TAG="web-app"; //NOI18N
36

37     public java.util.Enumeration JavaDoc enabled(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) {
38         if (ctx.getFileObject() == null) return null;
39         Enumeration JavaDoc en = ctx.getDocumentChildren();
40         while (en.hasMoreElements()) {
41             Node JavaDoc next = (Node JavaDoc) en.nextElement();
42             if (next.getNodeType() == next.DOCUMENT_TYPE_NODE) {
43                 return null; // null for web.xml specified by DTD
44
} else if (next.getNodeType() == next.ELEMENT_NODE) {
45                 Element JavaDoc element = (Element JavaDoc) next;
46                 String JavaDoc tag = element.getTagName();
47                 if (WEB_APP_TAG.equals(tag)) { // NOI18N
48
String JavaDoc xmlns = element.getAttribute(XMLNS_ATTR);
49         /*ludo if (xmlns!=null && DDCatalog.J2EE_NS.equals(xmlns)) //NOI18N
50                             return org.openide.util.Enumerations.singleton (next);
51                             ***/

52                     }
53                 }
54         }
55         
56         return null;
57     }
58     
59     public java.beans.FeatureDescriptor JavaDoc getDescriptor() {
60         return new java.beans.FeatureDescriptor JavaDoc();
61     }
62     
63     /** Returns pseudo DTD for code completion
64     */

65     public org.netbeans.modules.xml.api.model.GrammarQuery getGrammar(org.netbeans.modules.xml.api.model.GrammarEnvironment ctx) {
66         UserCatalog catalog = UserCatalog.getDefault();
67         /**if (catalog != null) {
68             EntityResolver resolver = catalog.getEntityResolver();
69             if (resolver != null) {
70                 try {
71                     InputSource inputSource = resolver.resolveEntity(DDCatalog.WEB_APP_2_4_ID, null);
72                     if (inputSource!=null) {
73                         return DTDUtil.parseDTD(true, inputSource);
74                     }
75                 } catch(SAXException e) {
76                 } catch(java.io.IOException e) {
77                 }
78             }
79         }ludo*/

80         return null;
81     }
82     
83 }
84
Popular Tags