KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > reasoner > rulesys > builtins > BaseBuiltin


1 /******************************************************************
2  * File: BaseBuiltin.java
3  * Created by: Dave Reynolds
4  * Created on: 10-Jun-2003
5  *
6  * (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
7  * [See end of file]
8  * $Id: BaseBuiltin.java,v 1.9 2005/02/21 12:17:09 andy_seaborne Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.builtins;
11
12 import com.hp.hpl.jena.reasoner.rulesys.*;
13 import com.hp.hpl.jena.graph.*;
14
15 /**
16  * Dummy implementation of the Builtin interface that specific
17  * implementations can inherit from.
18  *
19  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
20  * @version $Revision: 1.9 $ on $Date: 2005/02/21 12:17:09 $
21  */

22 public abstract class BaseBuiltin implements Builtin {
23
24     /** Base URI for jena builtins */
25     public static final String JavaDoc BASE_URI = "http://jena.hpl.hp.com/2003/RuleBuiltin/";
26     
27     /**
28      * Return the full URI which identifies this built in.
29      */

30     public String JavaDoc getURI() {
31         return BASE_URI + getName();
32     }
33     
34     /**
35      * Return the expected number of arguments for this functor or 0 if the number is flexible.
36      */

37     public int getArgLength() {
38         return 0;
39     }
40
41     /**
42      * Check the argument length.
43      */

44     public void checkArgs(int length, RuleContext context) {
45         int expected = getArgLength();
46         if (expected > 0 && expected != length) {
47             throw new BuiltinException(this, context, "builtin " + getName() + " requires " + expected + " arguments but saw " + length);
48         }
49     }
50     
51     /**
52      * This method is invoked when the builtin is called in a rule body.
53      * @param args the array of argument values for the builtin, this is an array
54      * of Nodes, some of which may be Node_RuleVariables.
55      * @param length the length of the argument list, may be less than the length of the args array
56      * for some rule engines
57      * @param context an execution context giving access to other relevant data
58      * @return return true if the buildin predicate is deemed to have succeeded in
59      * the current environment
60      */

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

75     public void headAction(Node[] args, int length, RuleContext context) {
76         throw new BuiltinException(this, context, "builtin " + getName() + " not usable in rule heads");
77     }
78     
79     /**
80      * Returns false if this builtin has side effects when run in a body clause,
81      * other than the binding of environment variables.
82      */

83     public boolean isSafe() {
84         // Default is safe!
85
return true;
86     }
87     
88     /**
89      * Return the n'th argument node after dererencing by what ever type of
90      * rule engine binding environment is appropriate.
91      */

92     public Node getArg(int n, Node[] args, RuleContext context) {
93         return context.getEnv().getGroundVersion(args[n]);
94     }
95
96 }
97
98
99
100 /*
101     (c) Copyright 2003, 2004, 2005 Hewlett-Packard Development Company, LP
102     All rights reserved.
103
104     Redistribution and use in source and binary forms, with or without
105     modification, are permitted provided that the following conditions
106     are met:
107
108     1. Redistributions of source code must retain the above copyright
109        notice, this list of conditions and the following disclaimer.
110
111     2. Redistributions in binary form must reproduce the above copyright
112        notice, this list of conditions and the following disclaimer in the
113        documentation and/or other materials provided with the distribution.
114
115     3. The name of the author may not be used to endorse or promote products
116        derived from this software without specific prior written permission.
117
118     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
119     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
120     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
121     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
122     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
123     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
124     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
125     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
126     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
127     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
128 */
Popular Tags