KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: Builtin.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: Builtin.java,v 1.8 2005/02/21 12:16:56 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys;
11
12 import com.hp.hpl.jena.graph.*;
13
14 /**
15  * Rules employ builtins to do all tests and actions other than simple triple
16  * matches and triple creation.
17  * <p>
18  * Builtins can be invoked in two contexts. In the head of forward rules they perform
19  * some action based on the variable bindings generated by the body and additional context
20  * (the graph being reasoned over, the set of triples bound by the body). In the body
21  * of rules they perform tests, and additional variable bindings.
22  * <p>
23  * The mapping from the rule definition (which uses functors to hold the parsed call)
24  * to the java implementation of the builtin is done via the
25  * {@link BuiltinRegistry BuiltinRegistry} which can
26  * be user extended.
27  *
28  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
29  * @version $Revision: 1.8 $ on $Date: 2005/02/21 12:16:56 $
30  */

31 public interface Builtin {
32
33     /**
34      * Return a convenient name for this builtin, normally this will be the name of the
35      * functor that will be used to invoke it and will often be the final component of the
36      * URI.
37      */

38     public String JavaDoc getName();
39     
40     /**
41      * Return the full URI which identifies this built in.
42      */

43     public String JavaDoc getURI();
44     
45     /**
46      * Return the expected number of arguments for this functor or 0 if the number is flexible.
47      */

48     public int getArgLength();
49     
50     /**
51      * This method is invoked when the builtin is called in a rule body.
52      * @param args the array of argument values for the builtin, this is an array
53      * of Nodes, some of which may be Node_RuleVariables.
54      * @param length the length of the argument list, may be less than the length of the args array
55      * for some rule engines
56      * @param context an execution context giving access to other relevant data
57      * @return return true if the buildin predicate is deemed to have succeeded in
58      * the current environment
59      */

60     public boolean bodyCall(Node[] args, int length, RuleContext context);
61     
62     /**
63      * This method is invoked when the builtin is called in a rule head.
64      * Such a use is only valid in a forward rule.
65      * @param args the array of argument values for the builtin, this is an array
66      * of Nodes.
67      * @param length the length of the argument list, may be less than the length of the args array
68      * for some rule engines
69      * @param context an execution context giving access to other relevant data
70      */

71     public void headAction(Node[] args, int length, RuleContext context);
72     
73     /**
74      * Returns false if this builtin has side effects when run in a body clause,
75      * other than the binding of environment variables.
76      */

77     public boolean isSafe();
78 }
79
80 /*
81     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
82     All rights reserved.
83
84     Redistribution and use in source and binary forms, with or without
85     modification, are permitted provided that the following conditions
86     are met:
87
88     1. Redistributions of source code must retain the above copyright
89        notice, this list of conditions and the following disclaimer.
90
91     2. Redistributions in binary form must reproduce the above copyright
92        notice, this list of conditions and the following disclaimer in the
93        documentation and/or other materials provided with the distribution.
94
95     3. The name of the author may not be used to endorse or promote products
96        derived from this software without specific prior written permission.
97
98     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
99     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
100     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
101     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
102     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
103     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
104     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
105     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
106     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
107     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
108 */

109
Popular Tags