View Javadoc

1   /*
2    * $Id: Namespace.java,v 1.9 2005/05/31 23:28:07 jlerner Exp $
3    *
4    * Copyright (c) 1999-2004, BBN Technologies, LLC.
5    * All rights reserved.
6    * http://www.daml.org/legal/opensource/bbn_license.html
7    */
8   
9   package com.bbn.swede.core.dom;
10  
11  /***
12   * Custom attribute node implementation for XML namespaces.  This class handles
13   * both named namespaces and the default namespace.
14   * @author jlerner
15   */
16  public class Namespace extends AttributeNode
17  {
18     /***
19      * The qualified name of the namespace attribute.  May be simply "xmlns"
20      * to indicate the default namespace.
21      */
22     protected String _sQName;
23     /***
24      * Creates a Namespace node.
25      * @param sQName The qualified name of the namespace attribute.  Must be
26      *               either "xmlns" or "xmlns:<i>foo</i>", where <i>foo</i> is
27      *               the desired namespace abbreviation.
28      * @param sValue The value of the attribute.
29      */
30     public Namespace(String sQName, String sValue)
31     {
32        super(sValue);
33        _sQName = sQName;
34        initRegions();
35     }
36  
37     /*
38      *  (non-Javadoc)
39      * @see com.bbn.swede.core.dom.OASTNode#getNodeType()
40      */
41     public int getNodeType()
42     {
43        return OASTNode.NAMESPACE;
44     }
45  
46     /*
47      *  (non-Javadoc)
48      * @see com.bbn.swede.core.dom.OASTNode#getQName()
49      */
50     public String getQName()
51     {
52        return _sQName;
53     }
54  
55     /***
56      * Retrieves the namespace abbreviation for this xmlns attribute.
57      * @return The namespace abbreviation, or an empty string if this is a
58      *         default namespace.
59      */
60     public String getAbbreviation()
61     {
62        int iPos = _sQName.indexOf(':');
63        if (iPos < 0) //default namespace
64        {
65           return "";
66        }
67        return _sQName.substring(iPos + 1);
68     }
69  }