001: /*
002: * Copyright 2006 JBoss Inc
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.drools.lang.dsl;
018:
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.LinkedList;
022: import java.util.List;
023:
024: import org.drools.lang.dsl.DSLMappingEntry.Section;
025:
026: /**
027: * This is a default implementation of the DSL Mapping interface
028: * capable of storing a list of DSLMappingEntries and managing it.
029: *
030: * @author etirelli
031: */
032: public class DefaultDSLMapping implements DSLMapping {
033:
034: private String identifier;
035: private String description;
036: private List entries;
037:
038: public DefaultDSLMapping() {
039: this ("");
040: }
041:
042: public DefaultDSLMapping(final String identifier) {
043: this .identifier = identifier;
044: this .entries = new LinkedList();
045: }
046:
047: /**
048: * Add one entry to the list of the entries
049: * @param entry
050: */
051: public void addEntry(final DSLMappingEntry entry) {
052: this .entries.add(entry);
053: }
054:
055: /**
056: * Adds all entries in the given list to this DSL Mapping
057: * @param entries
058: */
059: public void addEntries(final List entries) {
060: this .entries.addAll(entries);
061: }
062:
063: /**
064: * Returns an unmodifiable list of entries
065: */
066: public List getEntries() {
067: return Collections.unmodifiableList(this .entries);
068: }
069:
070: /**
071: * Returns the list of mappings for the given section
072: * @param section
073: * @return
074: */
075: public List getEntries(final Section section) {
076: final List list = new LinkedList();
077: for (final Iterator it = this .entries.iterator(); it.hasNext();) {
078: final DSLMappingEntry entry = (DSLMappingEntry) it.next();
079: if (entry.getSection().equals(section)) {
080: list.add(entry);
081: }
082: }
083: return list;
084: }
085:
086: /**
087: * Returns the identifier for this mapping
088: */
089: public String getIdentifier() {
090: return this .identifier;
091: }
092:
093: /**
094: * @inheritDoc
095: */
096: public void removeEntry(final DSLMappingEntry entry) {
097: this .entries.remove(entry);
098: }
099:
100: /**
101: * @inheritDoc
102: */
103: public String getDescription() {
104: return this .description;
105: }
106:
107: /**
108: * @inheritDoc
109: */
110: public void setDescription(final String description) {
111: this .description = description;
112: }
113:
114: /**
115: * @inheritDoc
116: */
117: public void setIdentifier(final String identifier) {
118: this.identifier = identifier;
119: }
120:
121: }
|