001: /*
002: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: *
025: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
026: */
027:
028: /*
029: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
030: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
031: *
032: * This code is free software; you can redistribute it and/or modify it
033: * under the terms of the GNU General Public License version 2 only, as
034: * published by the Free Software Foundation. Sun designates this
035: * particular file as subject to the "Classpath" exception as provided
036: * by Sun in the LICENSE file that accompanied this code.
037: *
038: * This code is distributed in the hope that it will be useful, but WITHOUT
039: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
040: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
041: * version 2 for more details (a copy is included in the LICENSE file that
042: * accompanied this code).
043: *
044: * You should have received a copy of the GNU General Public License version
045: * 2 along with this work; if not, write to the Free Software Foundation,
046: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
047: *
048: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
049: * CA 95054 USA or visit www.sun.com if you need additional information or
050: * have any questions.
051: *
052: * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC.
053: *
054: */
055:
056: package com.sun.xml.internal.fastinfoset.stax.events;
057:
058: import javax.xml.namespace.QName;
059: import javax.xml.stream.events.Namespace;
060:
061: import com.sun.xml.internal.fastinfoset.stax.events.Util;
062:
063: public class NamespaceBase extends AttributeBase implements Namespace {
064: //J2SE1.5.0 javax.xml.XMLConstants
065: static final String DEFAULT_NS_PREFIX = "";
066: static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace";
067: static final String XML_NS_PREFIX = "xml";
068: static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/";
069: static final String XMLNS_ATTRIBUTE = "xmlns";
070: static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema";
071: static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = "http://www.w3.org/2001/XMLSchema-instance";
072:
073: //is this namespace default declaration?
074: private boolean defaultDeclaration = false;
075:
076: /** a namespace attribute has a form: xmlns:NCName="URI reference" */
077: public NamespaceBase(String namespaceURI) {
078: super (XMLNS_ATTRIBUTE, "", namespaceURI);
079: setEventType(NAMESPACE);
080: }
081:
082: /**
083: * Create a new Namespace
084: * @param prefix prefix of a namespace is the local name for an attribute
085: * @param namespaceURI the uri reference of a namespace is the value for an attribute
086: */
087: public NamespaceBase(String prefix, String namespaceURI) {
088: super (XMLNS_ATTRIBUTE, prefix, namespaceURI);
089: setEventType(NAMESPACE);
090: if (Util.isEmptyString(prefix)) {
091: defaultDeclaration = true;
092: }
093: }
094:
095: void setPrefix(String prefix) {
096: if (prefix == null)
097: setName(new QName(XMLNS_ATTRIBUTE_NS_URI,
098: DEFAULT_NS_PREFIX, XMLNS_ATTRIBUTE));
099: else
100: // new QName(uri, localpart, prefix)
101: setName(new QName(XMLNS_ATTRIBUTE_NS_URI, prefix,
102: XMLNS_ATTRIBUTE));
103: }
104:
105: public String getPrefix() {
106: if (defaultDeclaration)
107: return "";
108: return super .getLocalName();
109: }
110:
111: /**
112: * set Namespace URI reference (xmlns:prefix = "uri")
113: * @param uri the uri reference of a namespace is the value for an attribute
114: */
115: void setNamespaceURI(String uri) {
116: setValue(uri);
117: }
118:
119: public String getNamespaceURI() {
120: return getValue();
121: }
122:
123: public boolean isNamespace() {
124: return true;
125: }
126:
127: public boolean isDefaultNamespaceDeclaration() {
128: return defaultDeclaration;
129: }
130:
131: }
|