001: package org.drools.lang.descr;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.util.ArrayList;
020: import java.util.Collections;
021: import java.util.Iterator;
022: import java.util.List;
023:
024: public class PackageDescr extends BaseDescr {
025: /**
026: *
027: */
028: private static final long serialVersionUID = 400L;
029: private final String name;
030: private final String documentation;
031:
032: private List imports = Collections.EMPTY_LIST;
033: private List functionImports = Collections.EMPTY_LIST;
034: private List attributes = Collections.EMPTY_LIST;
035: private List globals = Collections.EMPTY_LIST;
036: private List factTemplates = Collections.EMPTY_LIST;
037: private List functions = Collections.EMPTY_LIST;
038: private List rules = Collections.EMPTY_LIST;
039:
040: public PackageDescr(final String name) {
041: this (name, "");
042: }
043:
044: public PackageDescr(final String name, final String documentation) {
045: this .name = name;
046: this .documentation = documentation;
047: }
048:
049: public String getName() {
050: return this .name;
051: }
052:
053: public String getDocumentation() {
054: return this .documentation;
055: }
056:
057: public void addImport(final ImportDescr importEntry) {
058: if (this .imports == Collections.EMPTY_LIST) {
059: this .imports = new ArrayList();
060: }
061: this .imports.add(importEntry);
062: }
063:
064: public List getImports() {
065: return this .imports;
066: }
067:
068: public void addFunctionImport(
069: final FunctionImportDescr importFunction) {
070: if (this .functionImports == Collections.EMPTY_LIST) {
071: this .functionImports = new ArrayList();
072: }
073: this .functionImports.add(importFunction);
074: }
075:
076: public List getFunctionImports() {
077: return this .functionImports;
078: }
079:
080: public void addGlobal(final GlobalDescr global) {
081: if (this .globals == Collections.EMPTY_LIST) {
082: this .globals = new ArrayList();
083: }
084: this .globals.add(global);
085: }
086:
087: public List getGlobals() {
088: return this .globals;
089: }
090:
091: public void addAttribute(final AttributeDescr attribute) {
092: if (this .attributes == Collections.EMPTY_LIST) {
093: this .attributes = new ArrayList();
094: }
095: this .attributes.add(attribute);
096: }
097:
098: public List getAttributes() {
099: return this .attributes;
100: }
101:
102: public void addFactTemplate(final FactTemplateDescr factTemplate) {
103: if (this .factTemplates == Collections.EMPTY_LIST) {
104: this .factTemplates = new ArrayList(1);
105: }
106: this .factTemplates.add(factTemplate);
107: }
108:
109: public List getFactTemplates() {
110: return this .factTemplates;
111: }
112:
113: public void addFunction(final FunctionDescr function) {
114: if (this .functions == Collections.EMPTY_LIST) {
115: this .functions = new ArrayList(1);
116: }
117: this .functions.add(function);
118: }
119:
120: public List getFunctions() {
121: return this .functions;
122: }
123:
124: public void addRule(final RuleDescr rule) {
125: if (this .rules == Collections.EMPTY_LIST) {
126: this .rules = new ArrayList(1);
127: }
128: for (Iterator iter = attributes.iterator(); iter.hasNext();) {
129: AttributeDescr at = (AttributeDescr) iter.next();
130: boolean overridden = false;
131: //check for attr in rule
132: for (Iterator iterator = rule.getAttributes().iterator(); iterator
133: .hasNext();) {
134: AttributeDescr ruleAt = (AttributeDescr) iterator
135: .next();
136: if (ruleAt.getName().equals(at.getName())) {
137: overridden = true;
138: }
139: }
140: if (!overridden) {
141: rule.addAttribute(at);
142: }
143: }
144: this .rules.add(rule);
145: }
146:
147: public List getRules() {
148: return this.rules;
149: }
150: }
|