View Javadoc

1   /*
2    * $Id: GenericThing.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  import java.util.Map;
12  
13  /***
14   * Class node implementation for general non-language things.  Tags that are
15   * not recognized as an element from the rdf, rdfs, or owl namespace are
16   * treated as either generic things or generic predicates based on their 
17   * context.  That is, if a generic tag's parent is a property node, the generic
18   * is treated as a thing; if the generic's parent is a class node, the
19   * generic is treated as a predicate.
20   * @author jlerner
21   * @see com.bbn.swede.core.dom.ClassNode
22   * @see com.bbn.swede.core.dom.PropertyNode
23   * @see com.bbn.swede.core.dom.GenericPredicate
24   */
25  public class GenericThing extends ClassNode
26  {
27     /***
28      * The qualified name of the generic thing.
29      */
30     protected String _sQName;
31  
32     /***
33      * Creates a generic thing node with discrete begin and end tags.
34      * @param sQName The qualified name of the node's tag.
35      */
36     public GenericThing(String sQName)
37     {
38        _sQName = sQName;
39  
40        //reinitialize the regions since the qname wasn't set yet when TagNode's
41        //constructor tried to do it
42        initRegions(false);
43     }
44     
45     /***
46      * Creates a generic thing node as either a singleton or with descrete
47      * begin and end tags.
48      * @param sQName The qualified name of the node's tag.
49      * @param bSingleton <code>true</code> to create a singleton tag, 
50      * <code>false</code> to create discrete begin and end tags.
51      */
52     public GenericThing(String sQName, boolean bSingleton)
53     {
54        super(bSingleton);
55        _sQName = sQName;
56        
57        //reinitialize the regions since the qname wasn't set yet when TagNode's
58        //constructor tried to do it
59        initRegions(bSingleton);
60     }
61  
62     /*
63      *  (non-Javadoc)
64      * @see com.bbn.swede.core.dom.OASTNode#allowedChildren()
65      */
66     protected int[] allowedChildren()
67     {
68        return null;
69     }
70  
71     /*
72      *  (non-Javadoc)
73      * @see com.bbn.swede.core.dom.OASTNode#getNodeType()
74      */
75     public int getNodeType()
76     {
77        return GENERICTHING;
78     }
79  
80     /*
81      *  (non-Javadoc)
82      * @see com.bbn.swede.core.dom.OASTNode#getUri()
83      */
84     public String getUri()
85     {
86        String sNS = getNamespace();
87        if (sNS.length() == 0)
88        {
89           String sDefault = getDefaultNamespace();
90           if (sDefault == null)
91           {
92              sDefault = getOWLDocument().getURI() + "#";
93           }
94           return sDefault + getName();
95        }
96        Map map = getNamespaces();
97        String sUri = (String) map.get(sNS);
98        if (sUri == null)
99        {
100          return null;
101       }
102       return sUri + getName();
103    }
104 
105    /*
106     *  (non-Javadoc)
107     * @see com.bbn.swede.core.dom.OASTNode#getNamespace()
108     */
109    public String getNamespace()
110    {
111       int iPos = _sQName.indexOf(':');
112       if (iPos < 0)
113       {
114          return "";
115       }
116       return _sQName.substring(0, iPos);
117    }
118 
119    /***
120     * Sets the generic thing's qualified name.
121     * @param sQName The new QName.
122     */
123    public void setQName(String sQName)
124    {
125       _sQName = sQName;
126    }
127    
128    /*
129     *  (non-Javadoc)
130     * @see com.bbn.swede.core.dom.OASTNode#getQName()
131     */
132    public String getQName()
133    {
134       return _sQName;
135    }
136 
137    /*
138     *  (non-Javadoc)
139     * @see com.bbn.swede.core.dom.OASTNode#getName()
140     */
141    public String getName()
142    {
143       int iPos = _sQName.indexOf(':');
144       if (iPos < 0)
145       {
146          return _sQName;
147       }
148       return _sQName.substring(iPos + 1);
149    }
150 
151 }