Path: blob/aarch64-shenandoah-jdk8u272-b10/jaxp/src/com/sun/xml/internal/stream/events/NamespaceImpl.java
86414 views
/*1* Copyright (c) 2005, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation. Oracle designates this7* particular file as subject to the "Classpath" exception as provided8* by Oracle in the LICENSE file that accompanied this code.9*10* This code is distributed in the hope that it will be useful, but WITHOUT11* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or12* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License13* version 2 for more details (a copy is included in the LICENSE file that14* accompanied this code).15*16* You should have received a copy of the GNU General Public License version17* 2 along with this work; if not, write to the Free Software Foundation,18* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.19*20* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA21* or visit www.oracle.com if you need additional information or have any22* questions.23*/2425package com.sun.xml.internal.stream.events;2627import javax.xml.stream.events.Namespace;28import javax.xml.stream.events.XMLEvent;29import javax.xml.namespace.QName;3031import javax.xml.XMLConstants;32/**33*34* @author Neeraj Bajaj,[email protected] Sun Microsystems.35*/36public class NamespaceImpl extends AttributeImpl implements Namespace{3738public NamespaceImpl( ) {39init();40}4142/** Creates a new instance of NamespaceImpl */43public NamespaceImpl(String namespaceURI) {44super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,namespaceURI,null);45init();46}4748public NamespaceImpl(String prefix, String namespaceURI){49super(XMLConstants.XMLNS_ATTRIBUTE,XMLConstants.XMLNS_ATTRIBUTE_NS_URI,prefix,namespaceURI,null);50init();51}5253public boolean isDefaultNamespaceDeclaration() {54QName name = this.getName();5556if(name != null && (name.getLocalPart().equals(XMLConstants.DEFAULT_NS_PREFIX)))57return true;58return false;59}6061void setPrefix(String prefix){62if(prefix == null)63setName(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,XMLConstants.DEFAULT_NS_PREFIX,XMLConstants.XMLNS_ATTRIBUTE));64else// new QName(uri, localpart, prefix)65setName(new QName(XMLConstants.XMLNS_ATTRIBUTE_NS_URI,prefix,XMLConstants.XMLNS_ATTRIBUTE));66}6768public String getPrefix() {69//for a namespace declaration xmlns:prefix="uri" to get the prefix we have to get the70//local name if this declaration is stored as QName.71QName name = this.getName();72if(name != null)73return name.getLocalPart();74return null;75}7677public String getNamespaceURI() {78//we are treating namespace declaration as attribute -- so URI is stored as value79//xmlns:prefix="Value"80return this.getValue();81}8283void setNamespaceURI(String uri) {84//we are treating namespace declaration as attribute -- so URI is stored as value85//xmlns:prefix="Value"86this.setValue(uri);87}8889protected void init(){90setEventType(XMLEvent.NAMESPACE);91}9293public int getEventType(){94return XMLEvent.NAMESPACE;95}9697public boolean isNamespace(){98return true;99}100}101102103