KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > deployment > node > XMLElement


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23
24 package com.sun.enterprise.deployment.node;
25
26 import org.xml.sax.Attributes JavaDoc;
27 import org.xml.sax.helpers.NamespaceSupport JavaDoc;
28
29 /**
30  * This class represents a XML element in an XML file
31  *
32  * @author Jerome Dochez
33  * @version
34  */

35 public class XMLElement extends java.lang.Object JavaDoc {
36
37     private String JavaDoc qName;
38     private String JavaDoc prefix=null;
39     private NamespaceSupport JavaDoc namespaces=null;
40     
41     /** Creates new XMLElement */
42     public XMLElement(String JavaDoc qName) {
43         this(qName, null);
44     }
45
46     public XMLElement(String JavaDoc qName, NamespaceSupport JavaDoc namespaceSupport) {
47         if (qName.indexOf(':')!=-1) {
48             prefix = qName.substring(0, qName.indexOf(':'));
49             this.qName = qName.substring(qName.indexOf(':')+1);
50         } else {
51             this.qName = qName;
52         }
53         // can be null
54
namespaces = namespaceSupport;
55     }
56     
57     public String JavaDoc getQName() {
58         return qName;
59     }
60     
61     public String JavaDoc toString() {
62         return qName;
63     }
64     
65     public String JavaDoc getPrefix() {
66         return prefix;
67     }
68
69     /**
70      * Map a prefix to a namespaceURI based on the namespace context
71      * of this XML element.
72      */

73     public String JavaDoc getPrefixURIMapping(String JavaDoc prefixToResolve) {
74         return ( (namespaces != null) && (prefixToResolve != null) ) ?
75             namespaces.getURI(prefixToResolve) : null;
76     }
77
78     public String JavaDoc getCompleteName() {
79         if (prefix!=null) {
80             return prefix+":"+qName;
81         } else {
82             return qName;
83         }
84     }
85    
86     public boolean equals(XMLElement other ) {
87         return qName.equals(other.getQName());
88     }
89 }
90
Popular Tags