001: /******************************************************************
002: * File: BuildinRegistry.java
003: * Created by: Dave Reynolds
004: * Created on: 11-Apr-2003
005: *
006: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
007: * [See end of file]
008: * $Id: BuiltinRegistry.java,v 1.26 2008/01/02 12:07:46 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys;
010:
011: import com.hp.hpl.jena.reasoner.rulesys.builtins.*;
012: import java.util.*;
013:
014: /** * A registry for mapping functor names on java objects (instances
015: * of subclasses of Builtin) which implement their behvaiour.
016: * <p>
017: * This is currently implemented as a singleton to simply any future
018: * move to support different sets of builtins.
019: *
020: * @see Builtin * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a> * @version $Revision: 1.26 $ on $Date: 2008/01/02 12:07:46 $ */
021: public class BuiltinRegistry {
022:
023: /** The single global static registry */
024: public static BuiltinRegistry theRegistry;
025:
026: /** Mapping from functor name to Builtin implementing it */
027: protected Map builtins = new HashMap();
028:
029: /** Mapping from URI of builtin to implementation */
030: protected Map builtinsByURI = new HashMap();
031:
032: // Static initilizer for the singleton instance
033: static {
034: theRegistry = new BuiltinRegistry();
035:
036: theRegistry.register(new Print());
037: theRegistry.register(new AddOne());
038: theRegistry.register(new LessThan());
039: theRegistry.register(new GreaterThan());
040: theRegistry.register(new LE());
041: theRegistry.register(new GE());
042: theRegistry.register(new Equal());
043: theRegistry.register(new NotFunctor());
044: theRegistry.register(new IsFunctor());
045: theRegistry.register(new NotEqual());
046: theRegistry.register(new MakeTemp());
047: theRegistry.register(new NoValue());
048: theRegistry.register(new Remove());
049: theRegistry.register(new Drop());
050: theRegistry.register(new Sum());
051: theRegistry.register(new Difference());
052: theRegistry.register(new Product());
053: theRegistry.register(new Quotient());
054: theRegistry.register(new Bound());
055: theRegistry.register(new Unbound());
056: theRegistry.register(new IsLiteral());
057: theRegistry.register(new NotLiteral());
058: theRegistry.register(new IsBNode());
059: theRegistry.register(new NotBNode());
060: theRegistry.register(new IsDType());
061: theRegistry.register(new NotDType());
062: theRegistry.register(new CountLiteralValues());
063: theRegistry.register(new Max());
064: theRegistry.register(new Min());
065: theRegistry.register(new ListLength());
066: theRegistry.register(new ListEntry());
067: theRegistry.register(new ListEqual());
068: theRegistry.register(new ListNotEqual());
069: theRegistry.register(new ListContains());
070: theRegistry.register(new ListNotContains());
071: theRegistry.register(new ListMapAsSubject());
072: theRegistry.register(new ListMapAsObject());
073:
074: theRegistry.register(new MakeInstance());
075: theRegistry.register(new Table());
076: theRegistry.register(new TableAll());
077:
078: theRegistry.register(new Hide());
079:
080: theRegistry.register(new StrConcat());
081: theRegistry.register(new UriConcat());
082: theRegistry.register(new Regex());
083:
084: theRegistry.register(new Now());
085:
086: // Special purposes support functions for OWL
087: theRegistry.register(new AssertDisjointPairs());
088: }
089:
090: /**
091: * Construct an empty registry
092: */
093: public BuiltinRegistry() {
094: }
095:
096: /**
097: * Register an implementation for a given builtin functor.
098: * @param functor the name of the functor used to invoke the builtin
099: * @param impl the implementation of the builtin
100: */
101: public void register(String functor, Builtin impl) {
102: builtins.put(functor, impl);
103: builtinsByURI.put(impl.getURI(), impl);
104: }
105:
106: /**
107: * Register an implementation for a given builtin using its default name.
108: * @param impl the implementation of the builtin
109: */
110: public void register(Builtin impl) {
111: builtins.put(impl.getName(), impl);
112: builtinsByURI.put(impl.getURI(), impl);
113: }
114:
115: /**
116: * Find the implementation of the given builtin functor.
117: * @param functor the name of the functor being invoked.
118: * @return a Builtin or null if there is none registered under that name
119: */
120: public Builtin getImplementation(String functor) {
121: return (Builtin) builtins.get(functor);
122: }
123:
124: /**
125: * Find the implementation of the given builtin functor.
126: * @param uri the URI of the builtin to be retrieved
127: * @return a Builtin or null if there is none registered under that name
128: */
129: public Builtin getImplementationByURI(String uri) {
130: return (Builtin) builtinsByURI.get(uri);
131: }
132:
133: }
134:
135: /*
136: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
137: All rights reserved.
138:
139: Redistribution and use in source and binary forms, with or without
140: modification, are permitted provided that the following conditions
141: are met:
142:
143: 1. Redistributions of source code must retain the above copyright
144: notice, this list of conditions and the following disclaimer.
145:
146: 2. Redistributions in binary form must reproduce the above copyright
147: notice, this list of conditions and the following disclaimer in the
148: documentation and/or other materials provided with the distribution.
149:
150: 3. The name of the author may not be used to endorse or promote products
151: derived from this software without specific prior written permission.
152:
153: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
154: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
155: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
156: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
157: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
158: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
159: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
160: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
161: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
162: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
163: */
|