View Javadoc

1   /*   Copyright 2004 BEA Systems, Inc.
2    *
3    *   Licensed under the Apache License, Version 2.0 (the "License");
4    *   you may not use this file except in compliance with the License.
5    *   You may obtain a copy of the License at
6    *
7    *       http://www.apache.org/licenses/LICENSE-2.0
8    *
9    *   Unless required by applicable law or agreed to in writing, software
10   *   distributed under the License is distributed on an "AS IS" BASIS,
11   *   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   *   See the License for the specific language governing permissions and
13   *   limitations under the License.
14   */
15  
16  package com.bea.xml.stream;
17  
18  import javax.xml.stream.events.XMLEvent;
19  import javax.xml.namespace.QName;
20  
21  /***
22   * <p> The default implementation of the namespace class </p>
23   */
24  
25  public class NamespaceBase extends AttributeBase 
26    implements javax.xml.stream.events.Namespace
27  {
28    boolean declaresDefaultNamespace=false;
29    public NamespaceBase(String prefix,
30                         String namespaceURI) 
31    {
32      super("xmlns",
33            prefix,
34            namespaceURI);
35      declaresDefaultNamespace=false;
36    }
37  
38    public NamespaceBase(String namespaceURI)
39    {
40      super("xmlns",
41            "",
42            namespaceURI);
43      declaresDefaultNamespace=true;
44    }
45  
46    public int getEventType() { return XMLEvent.NAMESPACE; }
47    public boolean isAttribute() { return false; }
48    public boolean isNamespace() { return true; }
49    public String getPrefix() {
50      if (declaresDefaultNamespace) return "";
51      return super.getLocalName();
52    }
53    public String getNamespaceURI() {
54      return super.getValue();
55    }
56    public boolean isDefaultNamespaceDeclaration() {
57      return declaresDefaultNamespace;
58    }
59    public String toString() {
60      if (declaresDefaultNamespace) 
61        return "xmlns='"+getNamespaceURI()+"'";
62      else
63        return "xmlns:"+getPrefix()+"='"+getNamespaceURI()+"'";
64    }
65  
66  }