~mrooney/etherpad/ubuntu

« back to all changes in this revision

Viewing changes to trunk/trunk/infrastructure/rhino1_7R1/deprecatedsrc/org/mozilla/javascript/xml/impl/xmlbeans/XMLName.java

  • Committer: Aaron Iba
  • Date: 2009-12-18 07:40:23 UTC
  • Revision ID: hg-v1:a9f8774a2e00cc15b35857471fecea17f649e3c9
initial code push

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: java; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*-
 
2
 *
 
3
 * ***** BEGIN LICENSE BLOCK *****
 
4
 * Version: MPL 1.1/GPL 2.0
 
5
 *
 
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/
 
10
 *
 
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
 
14
 * License.
 
15
 *
 
16
 * The Original Code is Rhino code, released
 
17
 * May 6, 1999.
 
18
 *
 
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.
 
23
 *
 
24
 * Contributor(s):
 
25
 *   Igor Bukanov
 
26
 *   Milen Nankov
 
27
 *
 
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.
 
37
 *
 
38
 * ***** END LICENSE BLOCK ***** */
 
39
 
 
40
package org.mozilla.javascript.xml.impl.xmlbeans;
 
41
 
 
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;
 
47
 
 
48
class XMLName extends Ref
 
49
{
 
50
    static final long serialVersionUID = 3832176310755686977L;
 
51
 
 
52
    private String uri;
 
53
    private String localName;
 
54
    private boolean isAttributeName;
 
55
    private boolean isDescendants;
 
56
    private XMLObjectImpl xmlObject;
 
57
 
 
58
    private XMLName(String uri, String localName)
 
59
    {
 
60
        this.uri = uri;
 
61
        this.localName = localName;
 
62
    }
 
63
 
 
64
    static XMLName formStar()
 
65
    {
 
66
        return new XMLName(null, "*");
 
67
    }
 
68
 
 
69
    static XMLName formProperty(String uri, String localName)
 
70
    {
 
71
        return new XMLName(uri, localName);
 
72
    }
 
73
 
 
74
    void initXMLObject(XMLObjectImpl xmlObject)
 
75
    {
 
76
        if (xmlObject == null) throw new IllegalArgumentException();
 
77
        if (this.xmlObject != null) throw new IllegalStateException();
 
78
        this.xmlObject = xmlObject;
 
79
    }
 
80
 
 
81
    String uri()
 
82
    {
 
83
        return uri;
 
84
    }
 
85
 
 
86
    String localName()
 
87
    {
 
88
        return localName;
 
89
    }
 
90
 
 
91
    boolean isAttributeName()
 
92
    {
 
93
        return isAttributeName;
 
94
    }
 
95
 
 
96
    void setAttributeName()
 
97
    {
 
98
        if (isAttributeName) throw new IllegalStateException();
 
99
        isAttributeName = true;
 
100
    }
 
101
 
 
102
    boolean isDescendants()
 
103
    {
 
104
        return isDescendants;
 
105
    }
 
106
 
 
107
    void setIsDescendants()
 
108
    {
 
109
        if (isDescendants) throw new IllegalStateException();
 
110
        isDescendants = true;
 
111
    }
 
112
 
 
113
    public boolean has(Context cx)
 
114
    {
 
115
        if (xmlObject == null) {
 
116
            return false;
 
117
        }
 
118
        return xmlObject.hasXMLProperty(this);
 
119
    }
 
120
 
 
121
    public Object get(Context cx)
 
122
    {
 
123
        if (xmlObject == null) {
 
124
            throw ScriptRuntime.undefReadError(Undefined.instance,
 
125
                                               toString());
 
126
        }
 
127
        return xmlObject.getXMLProperty(this);
 
128
    }
 
129
 
 
130
    public Object set(Context cx, Object value)
 
131
    {
 
132
        if (xmlObject == null) {
 
133
            throw ScriptRuntime.undefWriteError(Undefined.instance,
 
134
                                                toString(),
 
135
                                                value);
 
136
        }
 
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);
 
141
        return value;
 
142
    }
 
143
 
 
144
    public boolean delete(Context cx)
 
145
    {
 
146
        if (xmlObject == null) {
 
147
            return true;
 
148
        }
 
149
        xmlObject.deleteXMLProperty(this);
 
150
        return !xmlObject.hasXMLProperty(this);
 
151
    }
 
152
 
 
153
    public String toString()
 
154
    {
 
155
        //return qname.localName();
 
156
        StringBuffer buff = new StringBuffer();
 
157
        if (isDescendants) buff.append("..");
 
158
        if (isAttributeName) buff.append('@');
 
159
        if (uri == null) {
 
160
            buff.append('*');
 
161
            if(localName().equals("*")) {
 
162
                return buff.toString();
 
163
            }
 
164
        } else {
 
165
            buff.append('"').append(uri()).append('"');
 
166
        }
 
167
        buff.append(':').append(localName());
 
168
        return buff.toString();
 
169
    }
 
170
 
 
171
}