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