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.enterprisemodel;
016:
017: import java.util.Collection;
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: import org.netbeans.mdr.storagemodel.StorableObject;
023:
024: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
025: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.AbstractNamespace;
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.Namespace;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Message;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.MessageField;
031:
032: public abstract class MessageImpl extends ModelElementImpl implements
033: Message {
034: // Required constructor
035: protected MessageImpl(StorableObject storable) {
036: super (storable);
037: }
038:
039: /**
040: * @param pFieldName
041: * @return requested MessageField or throws exception if none found
042: */
043: public MessageField getField(String pFieldName) {
044: MessageField lFoundField = findField(pFieldName);
045: // Throw exception if nothing found
046: if (lFoundField == null)
047: throw new IllegalArgumentException(
048: "Unable to locate MessageField named '"
049: + pFieldName + "' in Message. MessageRef: "
050: + getRef());
051: return lFoundField;
052: }
053:
054: /**
055: * @param pMessageFieldName
056: * @return requested MessageField or null if none found
057: */
058: public MessageField findField(String pMessageFieldName) {
059: Collection lMessageFields = getFields();
060: if (!lMessageFields.isEmpty()) {
061: for (Iterator lMessageFieldsIterator = lMessageFields
062: .iterator(); lMessageFieldsIterator.hasNext();) {
063: MessageField lMessageField = (MessageField) lMessageFieldsIterator
064: .next();
065: if (lMessageField.getName().equals(pMessageFieldName))
066: return lMessageField;
067: }
068: }
069: return null;
070: }
071:
072: /** @return All combined types used in this message */
073: public Collection getCombinedTypes() {
074: Set lCombinedTypes = new HashSet();
075: Collection lMessageFields = getFields();
076: if (!lMessageFields.isEmpty()) {
077: for (Iterator lMessageFieldsIterator = lMessageFields
078: .iterator(); lMessageFieldsIterator.hasNext();) {
079: MessageField lMessageField = (MessageField) lMessageFieldsIterator
080: .next();
081: DataType lDataType = lMessageField.getDataType();
082: if (lDataType != null) {
083: if (!lCombinedTypes.contains(lDataType))
084: lCombinedTypes.add(lDataType);
085: }
086: }
087: }
088: return java.util.Collections
089: .unmodifiableCollection(lCombinedTypes);
090: }
091:
092: // Returns owner data dictionary, if this message belongs to the dictionary or null if none found
093: public DataDictionary getOwnerDataDictionary() {
094: AbstractNamespace lNamespace = getNamespace();
095: if (lNamespace == null)
096: return null; // May belong to the Servicemodule
097: if (lNamespace instanceof DataDictionary)
098: return (DataDictionary) lNamespace; // Found data dictionary - just return it
099: return ((Namespace) lNamespace).getOwnerDataDictionary();
100: }
101: }
|