You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by ri...@apache.org on 2010/03/23 19:53:51 UTC
svn commit: r926728 - in /geronimo/specs/trunk/geronimo-stax-api_1.0_spec:
pom.xml src/main/java/javax/xml/namespace/QName.java
Author: rickmcguire
Date: Tue Mar 23 18:53:51 2010
New Revision: 926728
URL: http://svn.apache.org/viewvc?rev=926728&view=rev
Log:
Add a QName class to api and export the javax.xml.namespace package
Added:
geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java (with props)
Modified:
geronimo/specs/trunk/geronimo-stax-api_1.0_spec/pom.xml
Modified: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/pom.xml
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/pom.xml?rev=926728&r1=926727&r2=926728&view=diff
==============================================================================
--- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/pom.xml (original)
+++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/pom.xml Tue Mar 23 18:53:51 2010
@@ -78,7 +78,7 @@
<Specification-Title>JSR-137 Streaming API for XML 1.0</Specification-Title>
<Specification-Vendor>Sun Microsystems, Inc.</Specification-Vendor>
<Specification-Version>1.0</Specification-Version>
- <Export-Package>javax.xml.stream*;version=1.0.1</Export-Package>
+ <Export-Package>javax.xml.stream*;version=1.0,javax.xml.namespace*;version=1.0</Export-Package>
<Import-Package>org.apache.geronimo.osgi.registry.api;resolution:=optional,*</Import-Package>
<Private-Package>org.apache.geronimo.osgi.locator</Private-Package>
<Bundle-Activator>org.apache.geronimo.osgi.locator.Activator</Bundle-Activator>
Added: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java
URL: http://svn.apache.org/viewvc/geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java?rev=926728&view=auto
==============================================================================
--- geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java (added)
+++ geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java Tue Mar 23 18:53:51 2010
@@ -0,0 +1,125 @@
+/*
+ **
+ ** Licensed to the Apache Software Foundation (ASF) under one
+ ** or more contributor license agreements. See the NOTICE file
+ ** distributed with this work for additional information
+ ** regarding copyright ownership. The ASF licenses this file
+ ** to you under the Apache License, Version 2.0 (the
+ ** "License"); you may not use this file except in compliance
+ ** with the License. You may obtain a copy of the License at
+ **
+ ** http://www.apache.org/licenses/LICENSE-2.0
+ **
+ ** Unless required by applicable law or agreed to in writing,
+ ** software distributed under the License is distributed on an
+ ** "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ ** KIND, either express or implied. See the License for the
+ ** specific language governing permissions and limitations
+ ** under the License.
+ */
+package javax.xml.namespace;
+
+import java.io.Serializable;
+import javax.xml.XMLConstants;
+
+public class QName implements Serializable {
+ // not specified in the javadoc, but this is what appears to be used.
+ private static final long serialVersionUID = -9120448754896609940L;
+ // the namespace URI of this qualified name
+ private final String namespaceURI;
+ // the local part of the name
+ private final String localPart;
+ // the name prefix string
+ private final String prefix;
+
+ public QName(String localPart) {
+ // default both the URI and the prefix
+ this("", localPart, XMLConstants.DEFAULT_NS_PREFIX);
+ }
+
+ public QName(String namespaceURI, String localPart) {
+ // the default prefix is defined in XMLConstants
+ this(namespaceURI, localPart, XMLConstants.DEFAULT_NS_PREFIX);
+ }
+
+ public QName(String namespaceURI, String localPart, String prefix) {
+ // there is a default in constants as well
+ this.namespaceURI = namespaceURI == null ? "" : namespaceURI;
+
+ // both the local part and the prefix are required
+ if (localPart == null) {
+ throw new IllegalArgumentException("local part is required when creating a QName");
+ }
+ this.localPart = localPart;
+
+ if (prefix == null) {
+ throw new IllegalArgumentException("prefix is required when creating a QName");
+ }
+ this.prefix = prefix;
+ }
+
+ public final boolean equals(Object other) {
+ if (other == null || !(other instanceof QName)) {
+ return false;
+ }
+
+ QName qName = (QName)other;
+
+ // only the namespace and localPart are considered. the prefix is not used.
+ return namespaceURI.equals(qName.namespaceURI) && localPart.equals(qName.localPart);
+ }
+
+ public final int hashCode() {
+ // uses both the namespace and localpart as a combined hash.
+ return namespaceURI.hashCode() ^ localPart.hashCode();
+ }
+
+ public String getNamespaceURI() {
+ return namespaceURI;
+ }
+
+ public String getLocalPart() {
+ return localPart;
+ }
+
+ public String getPrefix() {
+ return prefix;
+ }
+
+ public String toString() {
+ // if no real URI, this is just the local part, otherwise
+ // use the braces syntax.
+ if (namespaceURI.length() == 0) {
+ return localPart;
+ }
+ else {
+ return "{" + namespaceURI + "}" + localPart;
+ }
+ }
+
+ public static QName valueOf(String source) {
+ // a name is required
+ if (source == null) {
+ throw new IllegalArgumentException("source QName string is required");
+ }
+
+ // if this is a null string or it does not start with '{', treat this
+ // as a local part alone.
+ if (source.length() == 0 || source.charAt(0) != '{') {
+ return new QName(source);
+ }
+
+ // Namespace URI and local part specified
+ int uriEnd = source.indexOf('}');
+ if (uriEnd == -1) {
+ throw new IllegalArgumentException("Incorrect QName syntax: " + source);
+ }
+
+ String uri = source.substring(1, uriEnd);
+ if (uri.length() == 0) {
+ throw new IllegalArgumentException("Null namespace URI in QName value: " + source);
+ }
+ // no prefix possible here, just the URI and the local part
+ return new QName(uri, source.substring(uriEnd + 1));
+ }
+}
Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java
------------------------------------------------------------------------------
svn:keywords = Date Revision
Propchange: geronimo/specs/trunk/geronimo-stax-api_1.0_spec/src/main/java/javax/xml/namespace/QName.java
------------------------------------------------------------------------------
svn:mime-type = text/plain