KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > ontology > impl > AbstractProfile


1 /*****************************************************************************
2  * Source code information
3  * -----------------------
4  * Original author Ian Dickinson, HP Labs Bristol
5  * Author email Ian.Dickinson@hp.com
6  * Package Jena 2
7  * Web http://sourceforge.net/projects/jena/
8  * Created 02-Apr-2003
9  * Filename $RCSfile: AbstractProfile.java,v $
10  * Revision $Revision: 1.7 $
11  * Release status $State: Exp $
12  *
13  * Last modified on $Date: 2005/02/21 12:06:05 $
14  * by $Author: andy_seaborne $
15  *
16  * (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
17  * (see footer for full conditions)
18  *****************************************************************************/

19
20 // Package
21
///////////////
22
package com.hp.hpl.jena.ontology.impl;
23
24
25 // Imports
26
///////////////
27
import com.hp.hpl.jena.rdf.model.*;
28 import com.hp.hpl.jena.graph.*;
29 import com.hp.hpl.jena.enhanced.*;
30 import com.hp.hpl.jena.util.*;
31 import com.hp.hpl.jena.ontology.*;
32
33 import java.util.*;
34
35
36
37 /**
38  * <p>
39  * Abstract base class to provide shared implementation for ontology language profiles.
40  * </p>
41  *
42  * @author Ian Dickinson, HP Labs
43  * (<a HREF="mailto:Ian.Dickinson@hp.com" >email</a>)
44  * @version CVS $Id: AbstractProfile.java,v 1.7 2005/02/21 12:06:05 andy_seaborne Exp $
45  */

46 public abstract class AbstractProfile
47     implements Profile
48 {
49     // Constants
50
//////////////////////////////////
51

52     // Static variables
53
//////////////////////////////////
54

55     // Instance variables
56
//////////////////////////////////
57

58     /** Map of aliases for resources */
59     protected OneToManyMap m_aliasesMap;
60     
61     
62     // Constructors
63
//////////////////////////////////
64

65     // External signature methods
66
//////////////////////////////////
67

68     /**
69      * <p>
70      * Answer true if the given resource has an alias in this profile.
71      * </p>
72      *
73      * @param res A resource (including properties) to test for an alias
74      * @return True if there is an alias for <code>res</code>
75      */

76     public boolean hasAliasFor( Resource res ) {
77         return aliasMap().containsKey( res );
78     }
79     
80     /**
81      * <p>
82      * Answer an alias for the given resource. If there is more than
83      * one such alias, a choice is made non-deterministically between the
84      * alternatives.
85      * </p>
86      *
87      * @param res A resource (including properties) to test for an alias
88      * @return The alias for <code>res</code>, or one of the aliases for <code>res</code> if more
89      * than one is defined, or null if no alias is defined for <code>res</code>.
90      *
91      */

92     public Resource getAliasFor( Resource res ) {
93         return (Resource) aliasMap().get( res );
94     }
95     
96     /**
97      * <p>
98      * Answer an iterator over the defined aliases for a resource.
99      * </p>
100      *
101      * @param res A resource (including properties)
102      * @return An iterator over the aliases for <code>res</code>. If there are
103      * no aliases, the empty iterator is returned.
104      */

105     public Iterator listAliasesFor( Resource res ) {
106         return aliasMap().getAll( res );
107     }
108
109     /**
110         Utility method: answer true iff the enhanced graph contains some triple which
111         has n as subject, p.asNode() as predicate, and any object.
112         
113          @param g an enhanced graph to search for triples
114          @param n some node
115          @param p a property containing a predicate node
116          @return true iff the graph contains (n, p, X) for some X
117     */

118     public static boolean containsSome( EnhGraph g, Node n, Property p ) {
119         return g.asGraph().contains( n, p.asNode(), Node.ANY );
120     }
121
122     // Internal implementation methods
123
//////////////////////////////////
124

125     /**
126      * Answer a table of binary mappings denoting that one resource is the
127      * alias for another (for example daml:Class and rdfs:Class).
128      */

129     protected abstract Resource[][] aliasTable();
130     
131     
132     /**
133      * <p>
134      * Prepare the local alias map by reading the alias table from the concrete sub-class.
135      * </p>
136      */

137     protected OneToManyMap aliasMap() {
138         if (m_aliasesMap == null) {
139             // aliases map not prepared yet, so initialise using the data from
140
// the concrete profile class
141
m_aliasesMap = new OneToManyMap();
142             Resource[][] aliases = aliasTable();
143             
144             for (int i = 0; i < aliases.length; i++) {
145                 // since alias relationship is symmetric, we record both directions
146
m_aliasesMap.put( aliases[i][0], aliases[i][1] );
147                 m_aliasesMap.put( aliases[i][1], aliases[i][0] );
148             }
149         }
150         
151         return m_aliasesMap;
152     }
153
154
155     //==============================================================================
156
// Inner class definitions
157
//==============================================================================
158

159 }
160
161
162 /*
163     (c) Copyright 2002, 2003, 2004, 2005 Hewlett-Packard Development Company, LP
164     All rights reserved.
165
166     Redistribution and use in source and binary forms, with or without
167     modification, are permitted provided that the following conditions
168     are met:
169
170     1. Redistributions of source code must retain the above copyright
171        notice, this list of conditions and the following disclaimer.
172
173     2. Redistributions in binary form must reproduce the above copyright
174        notice, this list of conditions and the following disclaimer in the
175        documentation and/or other materials provided with the distribution.
176
177     3. The name of the author may not be used to endorse or promote products
178        derived from this software without specific prior written permission.
179
180     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
181     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
182     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
183     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
184     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
185     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
186     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
187     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
188     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
189     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
190 */

191
192
Popular Tags