KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > xquark > xquery > parser > QName


1 /*
2  * This file belongs to the XQuark distribution.
3  * Copyright (C) 2003 Universite de Versailles Saint-Quentin.
4  *
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307.
18  * You can also get it at http://www.gnu.org/licenses/lgpl.html
19  *
20  * For more information on this software, see http://www.xquark.org.
21  */

22
23 package org.xquark.xquery.parser;
24
25 import org.xquark.util.NamespaceContext;
26 import org.xquark.xquery.typing.TypeException;
27 import org.xquark.util.NamespaceContext;
28
29 public class QName extends XQueryExpression implements Cloneable JavaDoc {
30
31     private static final String JavaDoc RCSRevision = "$Revision: 1.14 $";
32     private static final String JavaDoc RCSName = "$Name: $";
33
34     protected String JavaDoc namespace = null;
35     protected String JavaDoc prefixname = null;
36     // cannot be null or empty string
37
protected String JavaDoc localname = null;
38     // namespacecontext
39
NamespaceContext namespaceContext = null;
40
41     // #############################################################################
42
// VISITOR STUFF
43
// #############################################################################
44

45     public void accept(ParserVisitor visitor) throws XQueryException {
46         visitor.visit(this);
47     }
48
49     // #############################################################################
50
// CONSTRUCTOR STUFF
51
// #############################################################################
52

53     public QName(String JavaDoc localname, XQueryModule parentModule) throws TypeException, XQueryException {
54         setLocalName(localname);
55         setParentModule(parentModule);
56     }
57
58     public QName(String JavaDoc namespace, String JavaDoc prefixname, String JavaDoc localname, XQueryModule parentModule, NamespaceContext namespaceContext) throws TypeException, XQueryException {
59         setNameSpace(namespace);
60         setPrefixName(prefixname);
61         setLocalName(localname);
62         setParentModule(parentModule);
63         this.namespaceContext = namespaceContext;
64     }
65
66     // #############################################################################
67
// ATTRIBUTE ACCESS STUFF
68
// #############################################################################
69

70     public String JavaDoc toString() {
71         return toString(false, false, false);
72     }
73
74     public String JavaDoc getStringValue() {
75         return getStringValue(false, false);
76     }
77
78     public String JavaDoc getLocalName() {
79         return localname;
80     }
81     public void setLocalName(String JavaDoc localname) throws XQueryException {
82         if (localname == null || localname.equals(""))
83             throw new XQueryException("local name of QName cannot be empty string");
84         this.localname = localname;
85     }
86
87     public String JavaDoc getPrefixName() {
88         return prefixname;
89     }
90     public void setPrefixName(String JavaDoc prefixname) {
91         this.prefixname = prefixname;
92     }
93
94     public String JavaDoc getNameSpace() {
95         return namespace;
96     }
97     public void setNameSpace(String JavaDoc namespace) {
98         this.namespace = namespace;
99     }
100
101     public String JavaDoc getName() {
102         return localname;
103     }
104     public void setName(String JavaDoc name) {
105         localname = name;
106     }
107     public NamespaceContext getNamespaceContext() {
108         return namespaceContext;
109     }
110
111     public boolean equals(XQueryExpression expr) {
112         if (expr instanceof QName) {
113             if (!localname.equals(((QName) expr).getLocalName()))
114                 return false;
115             if (namespace == null && ((QName) expr).getNameSpace() == null)
116                 return true;
117             if (namespace != null && namespace.equals(((QName) expr).getNameSpace()))
118                 return true;
119         }
120         if (expr instanceof Value) {
121             if (namespace == null && localname.equals(((Value) expr).getValue()))
122                 return true;
123         }
124         return false;
125     }
126
127 }
128
Popular Tags