01: /******************************************************************
02: * File: Print.java
03: * Created by: Dave Reynolds
04: * Created on: 11-Apr-2003
05: *
06: * (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
07: * [See end of file]
08: * $Id: Print.java,v 1.10 2008/01/02 12:06:20 andy_seaborne Exp $
09: *****************************************************************/package com.hp.hpl.jena.reasoner.rulesys.builtins;
10:
11: import com.hp.hpl.jena.reasoner.rulesys.*;
12: import com.hp.hpl.jena.util.PrintUtil;
13: import com.hp.hpl.jena.graph.*;
14:
15: /**
16: * Print its argument list as a side effect
17: *
18: * @author <a href="mailto:der@hplb.hpl.hp.com">Dave Reynolds</a>
19: * @version $Revision: 1.10 $ on $Date: 2008/01/02 12:06:20 $
20: */
21: public class Print extends BaseBuiltin {
22:
23: /**
24: * Return a name for this builtin, normally this will be the name of the
25: * functor that will be used to invoke it.
26: */
27: public String getName() {
28: return "print";
29: }
30:
31: /**
32: * This method is invoked when the builtin is called in a rule body.
33: * @param args the array of argument values for the builtin, this is an array
34: * of Nodes, some of which may be Node_RuleVariables.
35: * @param length the length of the argument list, may be less than the length of the args array
36: * for some rule engines
37: * @param context an execution context giving access to other relevant data
38: * @return return true if the buildin predicate is deemed to have succeeded in
39: * the current environment
40: */
41: public boolean bodyCall(Node[] args, int length, RuleContext context) {
42: print(args, length, context);
43: return true;
44: }
45:
46: /**
47: * This method is invoked when the builtin is called in a rule head.
48: * Such a use is only valid in a forward rule.
49: * @param args the array of argument values for the builtin, this is an array
50: * of Nodes.
51: * @param context an execution context giving access to other relevant data
52: */
53: public void headAction(Node[] args, int length, RuleContext context) {
54: print(args, length, context);
55: }
56:
57: /**
58: * Print a node list to stdout
59: */
60: public void print(Node[] args, int length, RuleContext context) {
61: for (int i = 0; i < length; i++) {
62: System.out.print(PrintUtil.print(getArg(i, args, context))
63: + " ");
64: }
65: System.out.println("");
66: }
67: }
68:
69: /*
70: (c) Copyright 2003, 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
71: All rights reserved.
72:
73: Redistribution and use in source and binary forms, with or without
74: modification, are permitted provided that the following conditions
75: are met:
76:
77: 1. Redistributions of source code must retain the above copyright
78: notice, this list of conditions and the following disclaimer.
79:
80: 2. Redistributions in binary form must reproduce the above copyright
81: notice, this list of conditions and the following disclaimer in the
82: documentation and/or other materials provided with the distribution.
83:
84: 3. The name of the author may not be used to endorse or promote products
85: derived from this software without specific prior written permission.
86:
87: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
88: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
89: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
90: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
91: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
92: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
93: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
94: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
95: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
96: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
97: */
|