01: package org.ofbiz.rules.logikus;
02:
03: import org.ofbiz.rules.parse.*;
04: import org.ofbiz.rules.parse.tokens.*;
05: import org.ofbiz.rules.engine.*;
06:
07: /**
08: * <p><b>Title:</b> Atom Assembler
09: * <p><b>Description:</b> None
10: * <p>Copyright (c) 1999 Steven J. Metsker.
11: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
12: *
13: * <p>Permission is hereby granted, free of charge, to any person obtaining a
14: * copy of this software and associated documentation files (the "Software"),
15: * to deal in the Software without restriction, including without limitation
16: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
17: * and/or sell copies of the Software, and to permit persons to whom the
18: * Software is furnished to do so, subject to the following conditions:
19: *
20: * <p>The above copyright notice and this permission notice shall be included
21: * in all copies or substantial portions of the Software.
22: *
23: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
24: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
25: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
26: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
27: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
28: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
29: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
30: *
31: * <br>
32: * <p>Exchanges a token on an assembly's stack with an atom
33: * that has the token's value as its functor.
34: *
35: * @author Steven J. Metsker
36: * @version 1.0
37: */
38: public class AtomAssembler extends Assembler {
39:
40: /**
41: * Exchanges a token on an assembly's stack with an atom
42: * that has the token's value as its functor. In the case
43: * of a quoted string, this assembler removes the quotes,
44: * so that a string such as "Smith" becomes just Smith. In
45: * the case of a number, this assembler pushes a NumberFact.
46: *
47: * @param Assembly the assembly to work on
48: */
49: public void workOn(Assembly a) {
50: Token t = (Token) a.pop();
51:
52: // remove quotes from quoted string
53: if (t.isQuotedString()) {
54: String s = t.sval();
55: String plain = s.substring(1, s.length() - 1);
56:
57: a.push(new Atom(plain));
58: } else if (t.isNumber()) {
59: a.push(new NumberFact(t.nval()));
60: } else {
61: a.push(new Atom(t.value()));
62: }
63: }
64: }
|