001: /******************************************************************
002: * File: Hide.java
003: * Created by: Dave Reynolds
004: * Created on: 31-Jan-2004
005: *
006: * (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
007: * [See end of file]
008: * $Id: Hide.java,v 1.7 2008/01/02 12:06:21 andy_seaborne Exp $
009: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.builtins;
010:
011: import com.hp.hpl.jena.reasoner.InfGraph;
012: import com.hp.hpl.jena.reasoner.rulesys.*;
013: import com.hp.hpl.jena.graph.*;
014:
015: /**
016: * Register a node as to be hidden from query
017: * result iterators.
018: *
019: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
020: * @version $Revision: 1.7 $ on $Date: 2008/01/02 12:06:21 $
021: */
022: public class Hide extends BaseBuiltin {
023:
024: /**
025: * Return a name for this builtin, normally this will be the name of the
026: * functor that will be used to invoke it.
027: */
028: public String getName() {
029: return "hide";
030: }
031:
032: /**
033: * This method is invoked when the builtin is called in a rule body.
034: * @param args the array of argument values for the builtin, this is an array
035: * of Nodes, some of which may be Node_RuleVariables.
036: * @param length the length of the argument list, may be less than the length of the args array
037: * for some rule engines
038: * @param context an execution context giving access to other relevant data
039: * @return return true if the buildin predicate is deemed to have succeeded in
040: * the current environment
041: */
042: public boolean bodyCall(Node[] args, int length, RuleContext context) {
043: doHide(args, length, context);
044: return true;
045: }
046:
047: /**
048: * This method is invoked when the builtin is called in a rule head.
049: * Such a use is only valid in a forward rule.
050: * @param args the array of argument values for the builtin, this is an array
051: * of Nodes.
052: * @param length the length of the argument list, may be less than the length of the args array
053: * for some rule engines
054: * @param context an execution context giving access to other relevant data
055: */
056: public void headAction(Node[] args, int length, RuleContext context) {
057: doHide(args, length, context);
058: }
059:
060: /**
061: * Shared implementation applicable to head or body
062: */
063: private void doHide(Node[] args, int length, RuleContext context) {
064: InfGraph g = context.getGraph();
065: if (g instanceof FBRuleInfGraph) {
066: for (int i = 0; i < length; i++) {
067: ((FBRuleInfGraph) g).hideNode(args[i]);
068: }
069: } else {
070: throw new BuiltinException(this , context,
071: "hide only available for FB rule engines");
072: }
073: }
074: }
075:
076: /*
077: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
078: All rights reserved.
079:
080: Redistribution and use in source and binary forms, with or without
081: modification, are permitted provided that the following conditions
082: are met:
083:
084: 1. Redistributions of source code must retain the above copyright
085: notice, this list of conditions and the following disclaimer.
086:
087: 2. Redistributions in binary form must reproduce the above copyright
088: notice, this list of conditions and the following disclaimer in the
089: documentation and/or other materials provided with the distribution.
090:
091: 3. The name of the author may not be used to endorse or promote products
092: derived from this software without specific prior written permission.
093:
094: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
095: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
096: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
097: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
098: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
099: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
100: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
101: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
102: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
103: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
104: */
|