KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > BuiltinRegistry


1 /******************************************************************
2  * File: BuildinRegistry.java
3  * Created by: Dave Reynolds
4  * Created on: 11-Apr-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: BuiltinRegistry.java,v 1.18 2005/04/12 10:59:03 der Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys;
11
12 import com.hp.hpl.jena.reasoner.rulesys.builtins.*;
13 import java.util.*;
14
15 /** * A registry for mapping functor names on java objects (instances
16  * of subclasses of Builtin) which implement their behvaiour.
17  * <p>
18  * This is currently implemented as a singleton to simply any future
19  * move to support different sets of builtins.
20  *
21  * @see Builtin * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a> * @version $Revision: 1.18 $ on $Date: 2005/04/12 10:59:03 $ */

22 public class BuiltinRegistry {
23
24     /** The single global static registry */
25     public static BuiltinRegistry theRegistry;
26     
27     /** Mapping from functor name to Builtin implementing it */
28     protected Map builtins = new HashMap();
29     
30     /** Mapping from URI of builtin to implementation */
31     protected Map builtinsByURI = new HashMap();
32     
33     // Static initilizer for the singleton instance
34
static {
35         theRegistry = new BuiltinRegistry();
36         
37         theRegistry.register(new Print());
38         theRegistry.register(new AddOne());
39         theRegistry.register(new LessThan());
40         theRegistry.register(new GreaterThan());
41         theRegistry.register(new LE());
42         theRegistry.register(new GE());
43         theRegistry.register(new Equal());
44         theRegistry.register(new NotFunctor());
45         theRegistry.register(new IsFunctor());
46         theRegistry.register(new NotEqual());
47         theRegistry.register(new MakeTemp());
48         theRegistry.register(new NoValue());
49         theRegistry.register(new Remove());
50         theRegistry.register(new Sum());
51         theRegistry.register(new Difference());
52         theRegistry.register(new Product());
53         theRegistry.register(new Bound());
54         theRegistry.register(new Unbound());
55         theRegistry.register(new IsLiteral());
56         theRegistry.register(new NotLiteral());
57         theRegistry.register(new IsBNode());
58         theRegistry.register(new NotBNode());
59         theRegistry.register(new IsDType());
60         theRegistry.register(new NotDType());
61         theRegistry.register(new CountLiteralValues());
62         theRegistry.register(new Max());
63         theRegistry.register(new Min());
64         theRegistry.register(new ListLength());
65         theRegistry.register(new ListEqual());
66         theRegistry.register(new ListNotEqual());
67         theRegistry.register(new ListContains());
68         theRegistry.register(new ListNotContains());
69         theRegistry.register(new ListMapAsSubject());
70         theRegistry.register(new ListMapAsObject());
71         
72         theRegistry.register(new MakeInstance());
73         theRegistry.register(new Table());
74         theRegistry.register(new TableAll());
75         
76         theRegistry.register(new Hide());
77         
78         // Special purposes support functions for OWL
79
theRegistry.register(new AssertDisjointPairs());
80     }
81     
82     /**
83      * Construct an empty registry
84      */

85     public BuiltinRegistry() {
86     }
87     
88     /**
89      * Register an implementation for a given builtin functor.
90      * @param functor the name of the functor used to invoke the builtin
91      * @param impl the implementation of the builtin
92      */

93     public void register(String JavaDoc functor, Builtin impl) {
94         builtins.put(functor, impl);
95         builtinsByURI.put(impl.getURI(), impl);
96     }
97    
98     /**
99      * Register an implementation for a given builtin using its default name.
100      * @param impl the implementation of the builtin
101      */

102     public void register(Builtin impl) {
103         builtins.put(impl.getName(), impl);
104         builtinsByURI.put(impl.getURI(), impl);
105     }
106     
107     /**
108      * Find the implementation of the given builtin functor.
109      * @param functor the name of the functor being invoked.
110      * @return a Builtin or null if there is none registered under that name
111      */

112     public Builtin getImplementation(String JavaDoc functor) {
113         return (Builtin)builtins.get(functor);
114     }
115     
116     /**
117      * Find the implementation of the given builtin functor.
118      * @param uri the URI of the builtin to be retrieved
119      * @return a Builtin or null if there is none registered under that name
120      */

121     public Builtin getImplementationByURI(String JavaDoc uri) {
122         return (Builtin)builtinsByURI.get(uri);
123     }
124     
125 }
126
127 /*
128     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
129     All rights reserved.
130
131     Redistribution and use in source and binary forms, with or without
132     modification, are permitted provided that the following conditions
133     are met:
134
135     1. Redistributions of source code must retain the above copyright
136        notice, this list of conditions and the following disclaimer.
137
138     2. Redistributions in binary form must reproduce the above copyright
139        notice, this list of conditions and the following disclaimer in the
140        documentation and/or other materials provided with the distribution.
141
142     3. The name of the author may not be used to endorse or promote products
143        derived from this software without specific prior written permission.
144
145     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
146     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
147     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
148     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
149     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
150     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
151     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
152     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
153     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
154     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
155 */

156
Popular Tags