KickJava   Java API By Example, From Geeks To Geeks.

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


1 /******************************************************************
2  * File: Hide.java
3  * Created by: Dave Reynolds
4  * Created on: 31-Jan-2004
5  *
6  * (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
7  * [See end of file]
8  * $Id: Hide.java,v 1.4 2005/04/08 14:20:49 der Exp $
9  *****************************************************************/

10 package com.hp.hpl.jena.reasoner.rulesys.builtins;
11
12 import com.hp.hpl.jena.reasoner.InfGraph;
13 import com.hp.hpl.jena.reasoner.rulesys.*;
14 import com.hp.hpl.jena.graph.*;
15
16 /**
17  * Register a node as to be hidden from query
18  * result iterators.
19  *
20  * @author <a HREF="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
21  * @version $Revision: 1.4 $ on $Date: 2005/04/08 14:20:49 $
22  */

23 public class Hide extends BaseBuiltin {
24
25     /**
26      * Return a name for this builtin, normally this will be the name of the
27      * functor that will be used to invoke it.
28      */

29     public String JavaDoc getName() {
30         return "hide";
31     }
32
33     /**
34      * This method is invoked when the builtin is called in a rule body.
35      * @param args the array of argument values for the builtin, this is an array
36      * of Nodes, some of which may be Node_RuleVariables.
37      * @param length the length of the argument list, may be less than the length of the args array
38      * for some rule engines
39      * @param context an execution context giving access to other relevant data
40      * @return return true if the buildin predicate is deemed to have succeeded in
41      * the current environment
42      */

43     public boolean bodyCall(Node[] args, int length, RuleContext context) {
44         doHide(args, length, context);
45         return true;
46     }
47     
48     
49     /**
50      * This method is invoked when the builtin is called in a rule head.
51      * Such a use is only valid in a forward rule.
52      * @param args the array of argument values for the builtin, this is an array
53      * of Nodes.
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      */

58      public void headAction(Node[] args, int length, RuleContext context) {
59         doHide(args, length, context);
60     }
61
62     /**
63      * Shared implementation applicable to head or body
64      */

65     private void doHide(Node[] args, int length, RuleContext context ) {
66         InfGraph g = context.getGraph();
67         if (g instanceof FBRuleInfGraph) {
68             for (int i = 0; i < length; i++) {
69                 ((FBRuleInfGraph)g).hideNode(args[i]);
70             }
71         } else {
72             throw new BuiltinException(this, context, "hide only available for FB rule engines");
73         }
74     }
75 }
76
77
78
79 /*
80     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
81     All rights reserved.
82
83     Redistribution and use in source and binary forms, with or without
84     modification, are permitted provided that the following conditions
85     are met:
86
87     1. Redistributions of source code must retain the above copyright
88        notice, this list of conditions and the following disclaimer.
89
90     2. Redistributions in binary form must reproduce the above copyright
91        notice, this list of conditions and the following disclaimer in the
92        documentation and/or other materials provided with the distribution.
93
94     3. The name of the author may not be used to endorse or promote products
95        derived from this software without specific prior written permission.
96
97     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
98     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
99     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
100     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
101     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
102     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
103     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
104     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
105     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
106     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
107 */
Popular Tags