View Javadoc

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