1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
3
* ***** BEGIN LICENSE BLOCK *****
4
* Version: MPL 1.1/GPL 2.0
6
* The contents of this file are subject to the Mozilla Public License Version
7
* 1.1 (the "License"); you may not use this file except in compliance with
8
* the License. You may obtain a copy of the License at
9
* http://www.mozilla.org/MPL/
11
* Software distributed under the License is distributed on an "AS IS" basis,
12
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13
* for the specific language governing rights and limitations under the
16
* The Original Code is Rhino code, released
19
* The Initial Developer of the Original Code is
20
* Netscape Communications Corporation.
21
* Portions created by the Initial Developer are Copyright (C) 1997-2000
22
* the Initial Developer. All Rights Reserved.
28
* Alternatively, the contents of this file may be used under the terms of
29
* the GNU General Public License Version 2 or later (the "GPL"), in which
30
* case the provisions of the GPL are applicable instead of those above. If
31
* you wish to allow use of your version of this file only under the terms of
32
* the GPL and not to allow others to use your version of this file under the
33
* MPL, indicate your decision by deleting the provisions above and replacing
34
* them with the notice and other provisions required by the GPL. If you do
35
* not delete the provisions above, a recipient may use your version of this
36
* file under either the MPL or the GPL.
38
* ***** END LICENSE BLOCK ***** */
40
package org.mozilla.javascript.xml.impl.xmlbeans;
42
import org.mozilla.javascript.Context;
43
import org.mozilla.javascript.Kit;
44
import org.mozilla.javascript.Ref;
45
import org.mozilla.javascript.ScriptRuntime;
46
import org.mozilla.javascript.Undefined;
48
class XMLName extends Ref
50
static final long serialVersionUID = 3832176310755686977L;
53
private String localName;
54
private boolean isAttributeName;
55
private boolean isDescendants;
56
private XMLObjectImpl xmlObject;
58
private XMLName(String uri, String localName)
61
this.localName = localName;
64
static XMLName formStar()
66
return new XMLName(null, "*");
69
static XMLName formProperty(String uri, String localName)
71
return new XMLName(uri, localName);
74
void initXMLObject(XMLObjectImpl xmlObject)
76
if (xmlObject == null) throw new IllegalArgumentException();
77
if (this.xmlObject != null) throw new IllegalStateException();
78
this.xmlObject = xmlObject;
91
boolean isAttributeName()
93
return isAttributeName;
96
void setAttributeName()
98
if (isAttributeName) throw new IllegalStateException();
99
isAttributeName = true;
102
boolean isDescendants()
104
return isDescendants;
107
void setIsDescendants()
109
if (isDescendants) throw new IllegalStateException();
110
isDescendants = true;
113
public boolean has(Context cx)
115
if (xmlObject == null) {
118
return xmlObject.hasXMLProperty(this);
121
public Object get(Context cx)
123
if (xmlObject == null) {
124
throw ScriptRuntime.undefReadError(Undefined.instance,
127
return xmlObject.getXMLProperty(this);
130
public Object set(Context cx, Object value)
132
if (xmlObject == null) {
133
throw ScriptRuntime.undefWriteError(Undefined.instance,
137
// Assignment to descendants causes parse error on bad reference
138
// and this should not be called
139
if (isDescendants) throw Kit.codeBug();
140
xmlObject.putXMLProperty(this, value);
144
public boolean delete(Context cx)
146
if (xmlObject == null) {
149
xmlObject.deleteXMLProperty(this);
150
return !xmlObject.hasXMLProperty(this);
153
public String toString()
155
//return qname.localName();
156
StringBuffer buff = new StringBuffer();
157
if (isDescendants) buff.append("..");
158
if (isAttributeName) buff.append('@');
161
if(localName().equals("*")) {
162
return buff.toString();
165
buff.append('"').append(uri()).append('"');
167
buff.append(':').append(localName());
168
return buff.toString();