01: package org.ofbiz.rules.logikus;
02:
03: import java.util.*;
04: import org.ofbiz.rules.engine.*;
05: import org.ofbiz.rules.parse.*;
06: import org.ofbiz.rules.parse.tokens.*;
07:
08: /**
09: * <p><b>Title:</b> List Assembler
10: * <p><b>Description:</b> None
11: * <p>Copyright (c) 1999 Steven J. Metsker.
12: * <p>Copyright (c) 2001 The Open For Business Project - www.ofbiz.org
13: *
14: * <p>Permission is hereby granted, free of charge, to any person obtaining a
15: * copy of this software and associated documentation files (the "Software"),
16: * to deal in the Software without restriction, including without limitation
17: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
18: * and/or sell copies of the Software, and to permit persons to whom the
19: * Software is furnished to do so, subject to the following conditions:
20: *
21: * <p>The above copyright notice and this permission notice shall be included
22: * in all copies or substantial portions of the Software.
23: *
24: * <p>THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
25: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
26: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
27: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
28: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
29: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
30: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
31: *
32: * <br>
33: * <p>Pops the terms of a list from an assembly's stack, builds
34: * the list, and pushes it.
35: *
36: * @author Steven J. Metsker
37: * @version 1.0
38: */
39: public class ListAssembler extends Assembler {
40:
41: /**
42: * Pops the terms of a list from an assembly's stack, builds
43: * the list, and pushes it.
44: * <p>
45: * This method expects a series of terms to lie on top of a
46: * stack, with an open bracket token lying beneath. If there
47: * is no '[' marker, this class will throw an <code>
48: * EmptistackException</code>.
49: *
50: * @param Assembly the assembly to work on
51: */
52: public void workOn(Assembly a) {
53: Token fence = new Token('[');
54: List termVector = elementsAbove(a, fence);
55: Term[] termArray = StructureWithTermsAssembler
56: .vectorReversedIntoTerms(termVector);
57:
58: if (termArray.length == 0) {
59: a.push(Structure.emptyList);
60: } else {
61: a.push(Structure.list(termArray));
62: }
63: }
64: }
|