001: package org.drools.eclipse.core;
002:
003: import java.util.ArrayList;
004: import java.util.List;
005:
006: /**
007: * This represents a package.
008: *
009: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
010: */
011: public class Package extends DroolsElement {
012:
013: private String packageName;
014: private List rules = new ArrayList();
015: private List functions = new ArrayList();
016: private List expanders = new ArrayList();
017: private List imports = new ArrayList();
018: private List globals = new ArrayList();
019: private List queries = new ArrayList();
020: private List templates = new ArrayList();
021:
022: Package(RuleSet parent, String packageName) {
023: super (parent);
024: this .packageName = packageName == null ? "(default package)"
025: : packageName;
026: }
027:
028: public RuleSet getParentRuleSet() {
029: return (RuleSet) getParent();
030: }
031:
032: public String getPackageName() {
033: return packageName;
034: }
035:
036: public int getType() {
037: return PACKAGE;
038: }
039:
040: public DroolsElement[] getChildren() {
041: List children = new ArrayList();
042: children.addAll(rules);
043: children.addAll(queries);
044: children.addAll(globals);
045: children.addAll(functions);
046: children.addAll(expanders);
047: children.addAll(imports);
048: children.addAll(templates);
049: return (DroolsElement[]) children.toArray(new DroolsElement[0]);
050: }
051:
052: public String toString() {
053: return packageName;
054: }
055:
056: // These are helper methods for creating the model and should not
057: // be used directly. Use DroolsModelBuilder instead.
058:
059: void addRule(Rule rule) {
060: rules.add(rule);
061: }
062:
063: void removeRule(Rule rule) {
064: rules.remove(rule);
065: }
066:
067: void addFunction(Function function) {
068: functions.add(function);
069: }
070:
071: void removeFunction(Function function) {
072: functions.remove(function);
073: }
074:
075: void addExpander(Expander expander) {
076: expanders.add(expander);
077: }
078:
079: void removeExpander(Expander expander) {
080: expanders.remove(expander);
081: }
082:
083: void addImport(Import imp) {
084: imports.add(imp);
085: }
086:
087: void removeImport(Import imp) {
088: imports.remove(imp);
089: }
090:
091: void addGlobal(Global global) {
092: globals.add(global);
093: }
094:
095: void removeGlobal(Global global) {
096: globals.remove(global);
097: }
098:
099: void addQuery(Query query) {
100: queries.add(query);
101: }
102:
103: void removeQuery(Query query) {
104: queries.remove(query);
105: }
106:
107: void addTemplate(Template template) {
108: templates.add(template);
109: }
110:
111: void removeTemplate(Template template) {
112: templates.remove(template);
113: }
114:
115: }
|