001: /*
002: * $Id: NamespaceImpl.java,v 1.2 2006/04/01 06:01:34 jeffsuttor Exp $
003: */
004:
005: /*
006: * The contents of this file are subject to the terms
007: * of the Common Development and Distribution License
008: * (the License). You may not use this file except in
009: * compliance with the License.
010: *
011: * You can obtain a copy of the license at
012: * https://glassfish.dev.java.net/public/CDDLv1.0.html.
013: * See the License for the specific language governing
014: * permissions and limitations under the License.
015: *
016: * When distributing Covered Code, include this CDDL
017: * Header Notice in each file and include the License file
018: * at https://glassfish.dev.java.net/public/CDDLv1.0.html.
019: * If applicable, add the following below the CDDL Header,
020: * with the fields enclosed by brackets [] replaced by
021: * you own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * [Name of File] [ver.__] [Date]
025: *
026: * Copyright 2006 Sun Microsystems Inc. All Rights Reserved
027: */
028:
029: package com.sun.xml.stream.events;
030:
031: import javax.xml.stream.events.Namespace;
032: import javax.xml.stream.events.XMLEvent;
033: import javax.xml.namespace.QName;
034:
035: import javax.xml.XMLConstants;
036:
037: /**
038: *
039: * @author Neeraj Bajaj,K.Venugopal@sun.com Sun Microsystems.
040: */
041: public class NamespaceImpl extends AttributeImpl implements Namespace {
042:
043: public NamespaceImpl() {
044: init();
045: }
046:
047: /** Creates a new instance of NamespaceImpl */
048: public NamespaceImpl(String namespaceURI) {
049: super (XMLConstants.XMLNS_ATTRIBUTE,
050: XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
051: XMLConstants.DEFAULT_NS_PREFIX, namespaceURI, null);
052: init();
053: }
054:
055: public NamespaceImpl(String prefix, String namespaceURI) {
056: super (XMLConstants.XMLNS_ATTRIBUTE,
057: XMLConstants.XMLNS_ATTRIBUTE_NS_URI, prefix,
058: namespaceURI, null);
059: init();
060: }
061:
062: public boolean isDefaultNamespaceDeclaration() {
063: QName name = this .getName();
064:
065: if (name != null
066: && (name.getLocalPart()
067: .equals(XMLConstants.DEFAULT_NS_PREFIX)))
068: return true;
069: return false;
070: }
071:
072: void setPrefix(String prefix) {
073: if (prefix == null)
074: setName(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
075: XMLConstants.DEFAULT_NS_PREFIX,
076: XMLConstants.XMLNS_ATTRIBUTE));
077: else
078: // new QName(uri, localpart, prefix)
079: setName(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,
080: prefix, XMLConstants.XMLNS_ATTRIBUTE));
081: }
082:
083: public String getPrefix() {
084: //for a namespace declaration xmlns:prefix="uri" to get the prefix we have to get the
085: //local name if this declaration is stored as QName.
086: QName name = this .getName();
087: if (name != null)
088: return name.getLocalPart();
089: return null;
090: }
091:
092: public String getNamespaceURI() {
093: //we are treating namespace declaration as attribute -- so URI is stored as value
094: //xmlns:prefix="Value"
095: return this .getValue();
096: }
097:
098: void setNamespaceURI(String uri) {
099: //we are treating namespace declaration as attribute -- so URI is stored as value
100: //xmlns:prefix="Value"
101: this .setValue(uri);
102: }
103:
104: protected void init() {
105: setEventType(XMLEvent.NAMESPACE);
106: }
107:
108: public int getEventType() {
109: return XMLEvent.NAMESPACE;
110: }
111:
112: public boolean isNamespace() {
113: return true;
114: }
115: }
|