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.ArrayList;
018: import java.util.Collection;
019: import java.util.Collections;
020: import java.util.Iterator;
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.DataDictionaryModelPackage;
026: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Property;
027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.PropertyDescriptor;
028:
029: public abstract class PropertyDescriptorImpl extends ModelElementImpl
030: implements PropertyDescriptor {
031: // Required constructor
032: protected PropertyDescriptorImpl(StorableObject storable) {
033: super (storable);
034: }
035:
036: // Helper. Returns array of all subtypes (not only immedate ones)
037: public Collection getCombinedPropertyDescriptors() {
038: ArrayList lCombinedPropertyDescriptors = new ArrayList();
039: Collection lSubPropertyDescriptors = getSubPropertyDescriptors();
040: if (!lSubPropertyDescriptors.isEmpty()) {
041: Iterator lSubPropertyDescriptorsIterator = lSubPropertyDescriptors
042: .iterator();
043: while (lSubPropertyDescriptorsIterator.hasNext()) {
044: PropertyDescriptor lSubPropertyDescriptor = (PropertyDescriptor) lSubPropertyDescriptorsIterator
045: .next();
046: lCombinedPropertyDescriptors
047: .add(lSubPropertyDescriptor);
048: lCombinedPropertyDescriptors
049: .addAll(lSubPropertyDescriptor
050: .getCombinedPropertyDescriptors());
051: }
052: }
053: return Collections
054: .unmodifiableCollection(lCombinedPropertyDescriptors);
055: }
056:
057: /**
058: * @param pName
059: * @return PropertyDescriptor with specified name or throws exception if none found
060: */
061: public PropertyDescriptor getPropertyDescriptor(String pName) {
062: PropertyDescriptor lFoundPropertyDescriptor = findPropertyDescriptor(pName);
063: // Throw exception if nothing found
064: if (lFoundPropertyDescriptor == null)
065: throw new IllegalArgumentException(
066: "Unable to locate sub PropertyDescriptor named '"
067: + pName
068: + "' in PropertyDescriptor. PropertyDescriptorRef: "
069: + getRef());
070: return lFoundPropertyDescriptor;
071: }
072:
073: /**
074: * @param pName
075: * @return PropertyDescriptor with specified name or null if none found
076: */
077: public PropertyDescriptor findPropertyDescriptor(String pName) {
078: Collection lPropertyDescriptors = getSubPropertyDescriptors();
079: if (!lPropertyDescriptors.isEmpty()) {
080: for (Iterator lPropertyDescriptorsIterator = lPropertyDescriptors
081: .iterator(); lPropertyDescriptorsIterator.hasNext();) {
082: PropertyDescriptor lPropertyDescriptor = (PropertyDescriptor) lPropertyDescriptorsIterator
083: .next();
084: if (lPropertyDescriptor.getName().equals(pName))
085: return lPropertyDescriptor;
086: }
087: }
088: return null;
089: }
090:
091: /** Creates property described by this descriptor */
092: public Property createProperty(String pValue, Integer pArrayIndex) {
093: Property lProperty = ((DataDictionaryModelPackage) refImmediatePackage())
094: .getProperty().createProperty();
095: lProperty.setName(getName());
096: lProperty.setDescription(getDescription());
097: if (pValue != null)
098: lProperty.setValue(pValue);
099: getProperties().add(lProperty);
100: return lProperty;
101: }
102: }
|