1/* 2 * Copyright (c) 2004, 2012, 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 * THIS FILE WAS MODIFIED BY SUN MICROSYSTEMS, INC. 26 */ 27 28package com.sun.xml.internal.fastinfoset.stax.events; 29 30import javax.xml.namespace.QName; 31import javax.xml.stream.events.Namespace; 32 33 34public class NamespaceBase extends AttributeBase implements Namespace{ 35 //J2SE1.5.0 javax.xml.XMLConstants 36 static final String DEFAULT_NS_PREFIX = ""; 37 static final String XML_NS_URI = "http://www.w3.org/XML/1998/namespace"; 38 static final String XML_NS_PREFIX = "xml"; 39 static final String XMLNS_ATTRIBUTE_NS_URI = "http://www.w3.org/2000/xmlns/"; 40 static final String XMLNS_ATTRIBUTE = "xmlns"; 41 static final String W3C_XML_SCHEMA_NS_URI = "http://www.w3.org/2001/XMLSchema"; 42 static final String W3C_XML_SCHEMA_INSTANCE_NS_URI = "http://www.w3.org/2001/XMLSchema-instance"; 43 44 //is this namespace default declaration? 45 private boolean defaultDeclaration = false; 46 47 /** a namespace attribute has a form: xmlns:NCName="URI reference" */ 48 public NamespaceBase(String namespaceURI) { 49 super(XMLNS_ATTRIBUTE, "", namespaceURI); 50 setEventType(NAMESPACE); 51 } 52 53 /** 54 * Create a new Namespace 55 * @param prefix prefix of a namespace is the local name for an attribute 56 * @param namespaceURI the uri reference of a namespace is the value for an attribute 57 */ 58 public NamespaceBase(String prefix, String namespaceURI){ 59 super(XMLNS_ATTRIBUTE, prefix, namespaceURI); 60 setEventType(NAMESPACE); 61 if (Util.isEmptyString(prefix)) { 62 defaultDeclaration=true; 63 } 64 } 65 66 void setPrefix(String prefix){ 67 if(prefix == null) 68 setName(new QName(XMLNS_ATTRIBUTE_NS_URI,DEFAULT_NS_PREFIX,XMLNS_ATTRIBUTE)); 69 else// new QName(uri, localpart, prefix) 70 setName(new QName(XMLNS_ATTRIBUTE_NS_URI,prefix,XMLNS_ATTRIBUTE)); 71 } 72 73 public String getPrefix() { 74 if (defaultDeclaration) return ""; 75 return super.getLocalName(); 76 } 77 78 79 /** 80 * set Namespace URI reference (xmlns:prefix = "uri") 81 * @param uri the uri reference of a namespace is the value for an attribute 82 */ 83 void setNamespaceURI(String uri) { 84 setValue(uri); 85 } 86 public String getNamespaceURI() { 87 return getValue(); 88 } 89 90 91 public boolean isNamespace(){ 92 return true; 93 } 94 95 public boolean isDefaultNamespaceDeclaration() { 96 return defaultDeclaration; 97 } 98 99 100} 101