01: package org.drools.decisiontable.model;
02:
03: /*
04: * Copyright 2005 JBoss Inc
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */
18:
19: import java.util.Iterator;
20: import java.util.LinkedList;
21: import java.util.List;
22:
23: /**
24: * @author <a href="mailto:michael.neale@gmail.com"> Michael Neale </a>
25: *
26: * This is the top of the parse tree. Represents a package of rules once it has
27: * been parsed from the spreadsheet. Also is the launching point for dumping out
28: * the DRL.
29: */
30: public class Package implements DRLJavaEmitter {
31:
32: private String _name;
33:
34: private List _imports;
35:
36: private List _variables; // List of the application data Variable Objects
37:
38: private List _rules;
39:
40: private Functions _functions;
41:
42: public Package(final String name) {
43: this ._name = name;
44: this ._imports = new LinkedList();
45: this ._variables = new LinkedList();
46: this ._rules = new LinkedList();
47: this ._functions = new Functions();
48: }
49:
50: public void addImport(final Import imp) {
51: this ._imports.add(imp);
52: }
53:
54: public void addVariable(final Global varz) {
55: this ._variables.add(varz);
56: }
57:
58: public void addRule(final Rule rule) {
59: this ._rules.add(rule);
60: }
61:
62: public void addFunctions(final String listing) {
63: this ._functions.setFunctionsListing(listing);
64: }
65:
66: public String getName() {
67: return this ._name;
68: }
69:
70: public List getImports() {
71: return this ._imports;
72: }
73:
74: public List getVariables() {
75: return this ._variables;
76: }
77:
78: public List getRules() {
79: return this ._rules;
80: }
81:
82: public void renderDRL(final DRLOutput out) {
83: out.writeLine("package " + this ._name.replace(' ', '_') + ";");
84: out.writeLine("#generated from Decision Table");
85: renderDRL(this ._imports, out);
86: renderDRL(this ._variables, out);
87: this ._functions.renderDRL(out);
88: renderDRL(this ._rules, out);
89:
90: }
91:
92: private void renderDRL(final List list, final DRLOutput out) {
93: for (final Iterator it = list.iterator(); it.hasNext();) {
94: final DRLJavaEmitter emitter = (DRLJavaEmitter) it.next();
95: emitter.renderDRL(out);
96: }
97: }
98:
99: }
|