001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.sdlctools.models.impl.metabossmodel.datadictionarymodel;
016:
017: import java.util.Collection;
018: import java.util.Collections;
019: import java.util.HashSet;
020: import java.util.Iterator;
021: import java.util.Set;
022:
023: import org.netbeans.mdr.storagemodel.StorableObject;
024:
025: import com.metaboss.sdlctools.models.metabossmodel.ModelElement;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionary;
027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
030:
031: public abstract class DataDictionaryImpl extends AbstractNamespaceImpl
032: implements DataDictionary {
033: // Required constructor
034: protected DataDictionaryImpl(StorableObject storable) {
035: super (storable);
036: }
037:
038: /** Returns read-only collection of referenced datadictionaries */
039: public Collection getReferencedDataDictionaries() {
040: Set lReferencedDataDictionaries = new HashSet();
041: for (Iterator lTypesIterator = getCombinedTypes().iterator(); lTypesIterator
042: .hasNext();) {
043: ModelElement lTypeElement = (ModelElement) lTypesIterator
044: .next();
045: if (lTypeElement instanceof Structure) {
046: Structure lStructure = (Structure) lTypeElement;
047: DataDictionary lDataDictionary = lStructure
048: .getOwnerDataDictionary();
049: if (lDataDictionary != null
050: && lDataDictionary.equals(this ) == false)
051: lReferencedDataDictionaries.add(lDataDictionary);
052: } else if (lTypeElement instanceof Message) {
053: Message lMessage = (Message) lTypeElement;
054: DataDictionary lDataDictionary = lMessage
055: .getOwnerDataDictionary();
056: if (lDataDictionary != null
057: && lDataDictionary.equals(this ) == false)
058: lReferencedDataDictionaries.add(lDataDictionary);
059: } else if (lTypeElement instanceof DataType) {
060: DataType lDataType = (DataType) lTypeElement;
061: DataDictionary lDataDictionary = lDataType
062: .getOwnerDataDictionary();
063: if (lDataDictionary != null
064: && lDataDictionary.equals(this ) == false)
065: lReferencedDataDictionaries.add(lDataDictionary);
066: }
067: }
068: return Collections
069: .unmodifiableCollection(lReferencedDataDictionaries);
070: }
071:
072: /** Returns read-only collection of referenced datadictionaries */
073: public Collection getCombinedReferencedDataDictionaries() {
074: Set lReferencedDataDictionaries = new HashSet();
075: // Put this dictionary in the list to prevent recursion
076: lReferencedDataDictionaries.add(this );
077: populateCombinedReferencedDataDictionaries(lReferencedDataDictionaries);
078: // Remove this dictionary from the list.
079: lReferencedDataDictionaries.remove(this );
080: return Collections
081: .unmodifiableCollection(lReferencedDataDictionaries);
082: }
083:
084: /** Returns read-only collection of referenced datadictionaries */
085: private void populateCombinedReferencedDataDictionaries(
086: Set pAlreadyProcessedDataDictionaries) {
087: for (Iterator lTypesIterator = getCombinedTypes().iterator(); lTypesIterator
088: .hasNext();) {
089: ModelElement lTypeElement = (ModelElement) lTypesIterator
090: .next();
091: if (lTypeElement instanceof Structure) {
092: Structure lStructure = (Structure) lTypeElement;
093: DataDictionary lDataDictionary = lStructure
094: .getOwnerDataDictionary();
095: if (lDataDictionary != null
096: && lDataDictionary.equals(this ) == false
097: && pAlreadyProcessedDataDictionaries
098: .contains(lDataDictionary) == false) {
099: pAlreadyProcessedDataDictionaries
100: .add(lDataDictionary);
101: ((DataDictionaryImpl) lDataDictionary)
102: .populateCombinedReferencedDataDictionaries(pAlreadyProcessedDataDictionaries);
103: }
104: } else if (lTypeElement instanceof DataType) {
105: DataType lDataType = (DataType) lTypeElement;
106: DataDictionary lDataDictionary = lDataType
107: .getOwnerDataDictionary();
108: if (lDataDictionary != null
109: && lDataDictionary.equals(this ) == false
110: && pAlreadyProcessedDataDictionaries
111: .contains(lDataDictionary) == false) {
112: pAlreadyProcessedDataDictionaries
113: .add(lDataDictionary);
114: ((DataDictionaryImpl) lDataDictionary)
115: .populateCombinedReferencedDataDictionaries(pAlreadyProcessedDataDictionaries);
116: }
117: }
118: }
119: }
120: }
|