Thu, 12 Oct 2017 19:44:07 +0800
merge
1 /*
2 * Copyright (c) 2005, 2010, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25 /*
26 * Copyright (C) 2004-2011
27 *
28 * Permission is hereby granted, free of charge, to any person obtaining a copy
29 * of this software and associated documentation files (the "Software"), to deal
30 * in the Software without restriction, including without limitation the rights
31 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
32 * copies of the Software, and to permit persons to whom the Software is
33 * furnished to do so, subject to the following conditions:
34 *
35 * The above copyright notice and this permission notice shall be included in
36 * all copies or substantial portions of the Software.
37 *
38 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
39 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
40 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
41 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
42 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
43 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
44 * THE SOFTWARE.
45 */
46 package com.sun.xml.internal.rngom.digested;
48 import org.xml.sax.Locator;
49 import org.w3c.dom.Element;
51 import javax.xml.namespace.QName;
52 import java.util.Map;
53 import java.util.HashMap;
54 import java.util.List;
55 import java.util.ArrayList;
56 import java.util.Collections;
58 /**
59 * Annotation.
60 *
61 * @author Kohsuke Kawaguchi (kk@kohsuke.org)
62 */
63 public class DAnnotation {
65 /**
66 * Instance reserved to be empty.
67 */
68 static final DAnnotation EMPTY = new DAnnotation();
70 /**
71 * Keyed by QName.
72 */
73 final Map<QName,Attribute> attributes = new HashMap<QName,Attribute>();
75 /**
76 * List of nested elements.
77 */
78 final List<Element> contents = new ArrayList<Element>();
80 /**
81 * Attribute.
82 */
83 public static class Attribute {
84 private final String ns;
85 private final String localName;
86 private final String prefix;
88 private String value;
89 private Locator loc;
91 public Attribute(String ns, String localName, String prefix) {
92 this.ns = ns;
93 this.localName = localName;
94 this.prefix = prefix;
95 }
97 public Attribute(String ns, String localName, String prefix, String value, Locator loc) {
98 this.ns = ns;
99 this.localName = localName;
100 this.prefix = prefix;
101 this.value = value;
102 this.loc = loc;
103 }
105 /**
106 * Gets the namespace URI of this attribute.
107 *
108 * @return
109 * can be empty (to represent the default namespace), but never null.
110 */
111 public String getNs() {
112 return ns;
113 }
115 /**
116 * Gets the local name of this attribute.
117 *
118 * @return
119 * always non-null.
120 */
121 public String getLocalName() {
122 return localName;
123 }
125 /**
126 * Gets the prefix of thie attribute.
127 *
128 * @return
129 * null if this attribute didn't have a prefix.
130 */
131 public String getPrefix() {
132 return prefix;
133 }
135 /**
136 * Gets the attribute value.
137 *
138 * @return
139 * never null.
140 */
141 public String getValue() {
142 return value;
143 }
145 /**
146 * Gets the location in the source schema file where this annotation was present.
147 *
148 * @return
149 * never null.
150 */
151 public Locator getLoc() {
152 return loc;
153 }
154 }
156 /**
157 * Gets the attribute of a given name.
158 *
159 * @param nsUri
160 * can be empty but must not be null.
161 * @return
162 * null if no such attribute is found.
163 */
164 public Attribute getAttribute( String nsUri, String localName ) {
165 return getAttribute(new QName(nsUri,localName));
166 }
168 public Attribute getAttribute( QName n ) {
169 return attributes.get(n);
170 }
172 /**
173 * Gets the read-only view of all the attributes.
174 *
175 * @return
176 * can be empty but never null.
177 * the returned map is read-only.
178 */
179 public Map<QName,Attribute> getAttributes() {
180 return Collections.unmodifiableMap(attributes);
181 }
183 /**
184 * Gets the read-only view of all the child elements of this annotation.
185 *
186 * @return
187 * can be empty but never null.
188 * the returned list is read-only.
189 */
190 public List<Element> getChildren() {
191 return Collections.unmodifiableList(contents);
192 }
193 }