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.systemimplementationmodel;
016:
017: import java.io.IOException;
018: import java.util.ArrayList;
019: import java.util.Collection;
020: import java.util.Collections;
021: import java.util.HashSet;
022: import java.util.Iterator;
023: import java.util.List;
024: import java.util.Set;
025:
026: import javax.jmi.reflect.ConstraintViolationException;
027:
028: import org.apache.commons.logging.Log;
029: import org.apache.commons.logging.LogFactory;
030: import org.netbeans.mdr.storagemodel.StorableObject;
031:
032: import tudresden.ocl.MetaBossOclTree;
033: import tudresden.ocl.NameCreator;
034: import tudresden.ocl.OclException;
035: import tudresden.ocl.OclTree;
036: import tudresden.ocl.check.types.ModelFacade;
037: import tudresden.ocl.parser.OclParserException;
038:
039: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
040: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
041: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
042: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.ModelFacadeForOCLCompiler;
043: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
044: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
045: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRoleCardinalityEnum;
046: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
047: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AttributeStereotypeEnum;
048: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
049: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotype;
050: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityStereotypeEnum;
051: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.PrimaryKeyElement;
052: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
053: import com.metaboss.sdlctools.models.metabossmodel.statemachinemodel.StateMachine;
054:
055: public abstract class EntityImpl extends ModelElementImpl implements
056: Entity {
057: // Commons Logging instance.
058: private static final Log sLogger = LogFactory
059: .getLog(EntityImpl.class);
060:
061: // Required constructor
062: protected EntityImpl(StorableObject storable) {
063: super (storable);
064: }
065:
066: // Verify certain constraints
067: protected Collection _verify(Collection pViolations) {
068: // First call superclass
069: Collection lViolations = super ._verify(pViolations);
070:
071: // Constraint #1 - If entity is modifiable - version id data type must be present
072: if (isModifiable()) {
073: if (getVersionIdDataType() == null)
074: lViolations
075: .add(new ConstraintViolationException(this ,
076: refMetaObject(),
077: "Modifiable entity must have the Version Id data type reference."));
078: }
079:
080: // Constraint #2 - If entity has a state machine - state data type must be present
081: StateMachine lStateMachine = getStateMachine();
082: DataType lStateDataType = getStateDataType();
083: boolean lHasAttributesUsedForOrdering = !getCombinedAttributesUsedForOrdering()
084: .isEmpty();
085: DataType lOrderingInstructionDataType = getOrderingInstructionDataType();
086: if (lStateMachine != null) {
087: if (lStateDataType == null)
088: lViolations
089: .add(new ConstraintViolationException(this ,
090: refMetaObject(),
091: "Entity with a state machine must have the State data type reference."));
092: } else {
093: if (lStateDataType != null)
094: lViolations
095: .add(new ConstraintViolationException(this ,
096: refMetaObject(),
097: "Entity without a state machine must not have the State data type reference."));
098: }
099:
100: // Constraint #3 - If entity or its supertypes has orderable attributes - the ordering instructions data type should be present
101: if (lHasAttributesUsedForOrdering == true) {
102: if (lOrderingInstructionDataType == null)
103: lViolations
104: .add(new ConstraintViolationException(
105: this ,
106: refMetaObject(),
107: "Ordering intructions DataType reference is missing. Entity with orderable attributes must be associated with corresponding Ordering instructions enumerable DataType."));
108: } else {
109: if (lOrderingInstructionDataType != null)
110: lViolations
111: .add(new ConstraintViolationException(
112: this ,
113: refMetaObject(),
114: "Ordering intructions DataType reference is not required. Entity without orderable attributes must not be associated with Ordering instructions enumerable DataType."));
115: }
116:
117: // Constraint #4 - Combined list or references and attributes must not have duplicate names
118: {
119: Set lDuplicateNames = null;
120: Set lUsedNames = new HashSet();
121: for (Iterator lAttributesIterator = getCombinedAttributes()
122: .iterator(); lAttributesIterator.hasNext();) {
123: Attribute lAtribute = (Attribute) lAttributesIterator
124: .next();
125: String lAttributeName = lAtribute.getName();
126: if (lUsedNames.contains(lAttributeName)) {
127: if (lDuplicateNames == null)
128: lDuplicateNames = new HashSet();
129: lDuplicateNames.add(lAttributeName);
130: } else
131: lUsedNames.add(lAttributeName);
132: }
133: for (Iterator lReferencesIterator = getCombinedReferences()
134: .iterator(); lReferencesIterator.hasNext();) {
135: AssociationRole lReference = (AssociationRole) lReferencesIterator
136: .next();
137: String lReferenceName = lReference.getName();
138: if (lUsedNames.contains(lReferenceName)) {
139: if (lDuplicateNames == null)
140: lDuplicateNames = new HashSet();
141: lDuplicateNames.add(lReferenceName);
142: } else
143: lUsedNames.add(lReferenceName);
144: }
145: // Report if there is anything to report
146: if (lDuplicateNames != null) {
147: // We have a problem !
148: // Report if there is anything to report
149: for (Iterator lDuplicateNamesIterator = lDuplicateNames
150: .iterator(); lDuplicateNamesIterator.hasNext();) {
151: lViolations
152: .add(new ConstraintViolationException(
153: this ,
154: refMetaObject(),
155: "Entity has two or more references and/or attributes with the name '"
156: + ((String) lDuplicateNamesIterator
157: .next())
158: + "'. All attributes and references within entity must have unique names (This includes supertypes)."));
159: }
160: }
161: }
162: // Constraint #5 - Primary key elements must not be optional or modifiable
163: {
164: for (Iterator lPrimaryKeyElementsIterator = getPrimaryKeyElements()
165: .iterator(); lPrimaryKeyElementsIterator.hasNext();) {
166: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
167: .next();
168: if (lPrimaryKeyElement instanceof Attribute) {
169: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
170: if (lAttribute.isOptional())
171: lViolations
172: .add(new ConstraintViolationException(
173: lAttribute,
174: lAttribute.refMetaObject(),
175: "This attribute is not allowed to be a part of primary key. Only attributes with stereotypes '"
176: + AttributeStereotypeEnum.MANDATORY
177: + "' and '"
178: + AttributeStereotypeEnum.CREATE_STAMP
179: + "' can be included in the primary key."));
180: } else if (lPrimaryKeyElement instanceof AssociationRole) {
181: AssociationRole lAssociationRole = (AssociationRole) lPrimaryKeyElement;
182: if (!lAssociationRole.getCardinality().equals(
183: AssociationRoleCardinalityEnum.ONE))
184: lViolations
185: .add(new ConstraintViolationException(
186: lAssociationRole,
187: lAssociationRole
188: .refMetaObject(),
189: "This reference is not allowed to be a part of primary key. Only references with cardinality '"
190: + AssociationRoleCardinalityEnum.ONE
191: + "' can be included in the primary key."));
192: }
193: }
194: }
195: // Constraint #6 - Compile every constraint and check syntax
196: if (!getConstraints().isEmpty()) {
197: ModelFacade lModelFacade = ModelFacadeForOCLCompiler
198: .createForEntityContext(this );
199: NameCreator lNameCreator = new NameCreator();
200: String lEntityName = getName();
201: String lContextName = lEntityName.substring(0, 1)
202: .toUpperCase()
203: + lEntityName.substring(1);
204: String lConstraintStringStart = "context " + lContextName
205: + " inv : ";
206: for (Iterator lConstraintsIterator = getConstraints()
207: .iterator(); lConstraintsIterator.hasNext();) {
208: ModelElementConstraint lModelElementConstraint = (ModelElementConstraint) lConstraintsIterator
209: .next();
210: String lExpressionString = lModelElementConstraint
211: .getOclExpression();
212: if (lExpressionString != null
213: && lExpressionString.trim().length() > 0) {
214: String lConstraintString = lConstraintStringStart
215: + lModelElementConstraint
216: .getOclExpression();
217: try {
218: OclTree lConstraintTree = MetaBossOclTree
219: .createTree(lConstraintString,
220: lModelFacade);
221: lConstraintTree.setNameCreator(lNameCreator);
222: lConstraintTree.assureTypes();
223: } catch (IOException e) {
224: sLogger
225: .error(
226: "Caught unexpected exception during model validation",
227: e);
228: } catch (OclException e) {
229: lViolations
230: .add(new ConstraintViolationException(
231: lModelElementConstraint,
232: lModelElementConstraint
233: .refMetaObject(), e
234: .getMessage()
235: + ". Constraint text: "
236: + lConstraintString));
237: } catch (OclParserException e) {
238: lViolations
239: .add(new ConstraintViolationException(
240: lModelElementConstraint,
241: lModelElementConstraint
242: .refMetaObject(), e
243: .getMessage()
244: + ". Constraint text: "
245: + lConstraintString));
246: }
247: }
248: }
249: }
250: return lViolations;
251: }
252:
253: // Returns true if this entity is modifieable
254: public boolean isModifiable() {
255: EntityStereotype lStereotype = getStereotype();
256: return (lStereotype != null)
257: && (lStereotype.equals(EntityStereotypeEnum.CARD_FILE));
258: }
259:
260: /** Returns the association role of the owner of this entity or null if this entity is not owned by anyone */
261: public AssociationRole getOwnerReference() {
262: Collection lCombinedReferences = getCombinedReferences();
263: if (!lCombinedReferences.isEmpty()) {
264: for (Iterator lCombinedReferencesIterator = lCombinedReferences
265: .iterator(); lCombinedReferencesIterator.hasNext();) {
266: AssociationRole lReference = (AssociationRole) lCombinedReferencesIterator
267: .next();
268: if (AggregationTypeEnum.COMPOSITION.equals(lReference
269: .getAggregationType()))
270: return lReference;
271: }
272: }
273: return null;
274: }
275:
276: // Helper. Returns array of all association roles from this entity and it's supertypes
277: public Collection getCombinedReferences() {
278: List lReferences = new ArrayList();
279: lReferences.addAll(getReferences());
280: Entity lSupertype = getSupertype();
281: if (lSupertype != null)
282: lReferences.addAll(lSupertype.getCombinedReferences());
283: return Collections.unmodifiableCollection(lReferences);
284: }
285:
286: // Helper. Returns array of all association roles from this entity and it's supertypes
287: public Collection getCombinedRoles() {
288: List lRoles = new ArrayList();
289: lRoles.addAll(getRoles());
290: Entity lSupertype = getSupertype();
291: if (lSupertype != null)
292: lRoles.addAll(lSupertype.getCombinedRoles());
293: return Collections.unmodifiableCollection(lRoles);
294: }
295:
296: // Helper. Returns array of all association roles referenced from this entity, excluding its supertypes
297: public Collection getReferences() {
298: List lReferences = new ArrayList();
299: Collection lRoles = getRoles();
300: if (!lRoles.isEmpty()) {
301: for (Iterator lRolesIterator = lRoles.iterator(); lRolesIterator
302: .hasNext();) {
303: AssociationRole lRole = (AssociationRole) lRolesIterator
304: .next();
305: lReferences.add(lRole.getOppositeRole());
306: }
307: }
308: return Collections.unmodifiableCollection(lReferences);
309: }
310:
311: /**
312: * @param pSelectorName
313: * @return Reference with requsted name or return null if none found
314: */
315: public AssociationRole findReference(String pReferenceName) {
316: Collection lRoles = getRoles();
317: if (!lRoles.isEmpty()) {
318: for (Iterator lRolesIterator = lRoles.iterator(); lRolesIterator
319: .hasNext();) {
320: AssociationRole lRole = (AssociationRole) lRolesIterator
321: .next();
322: AssociationRole lReference = lRole.getOppositeRole();
323: if (pReferenceName.equals(lReference.getName()))
324: return lReference;
325: }
326: }
327: return null;
328: }
329:
330: /**
331: * @param pSelectorName
332: * @return Reference with requsted name or return null if none found
333: */
334: public AssociationRole findCombinedReference(String pReferenceName) {
335: Collection lRoles = getRoles();
336: if (!lRoles.isEmpty()) {
337: for (Iterator lRolesIterator = lRoles.iterator(); lRolesIterator
338: .hasNext();) {
339: AssociationRole lRole = (AssociationRole) lRolesIterator
340: .next();
341: AssociationRole lReference = lRole.getOppositeRole();
342: if (pReferenceName.equals(lReference.getName()))
343: return lReference;
344: }
345: }
346: Entity lSupertype = getSupertype();
347: if (lSupertype != null)
348: return lSupertype.findCombinedReference(pReferenceName);
349: return null;
350: }
351:
352: /**
353: * @param pSelectorName
354: * @return Reference with requsted name or throws exception if none found
355: */
356: public AssociationRole getReference(String pReferenceName) {
357: AssociationRole lFoundReference = findReference(pReferenceName);
358: // Throw exception if nothing found
359: if (lFoundReference == null)
360: throw new IllegalArgumentException(
361: "Unable to locate Reference named '"
362: + pReferenceName
363: + "' in Entity. EntityRef: " + getRef());
364: return lFoundReference;
365: }
366:
367: /** Returns array of all attributes from this entity and it's supertypes */
368: public Collection getCombinedAttributes() {
369: ArrayList lAttributes = new ArrayList();
370: Entity lEntity = this ;
371: do {
372: lAttributes.addAll(lEntity.getAttributes());
373: lEntity = lEntity.getSupertype();
374: } while (lEntity != null);
375: return Collections.unmodifiableCollection(lAttributes);
376: }
377:
378: // Helper. Returns array of all subtypes (not only immedate ones)
379: public Collection getCombinedSubtypes() {
380: ArrayList lCombinedSubtypes = new ArrayList();
381: Collection lSubtypes = getSubtypes();
382: if (!lSubtypes.isEmpty()) {
383: for (Iterator lSubtypesIterator = lSubtypes.iterator(); lSubtypesIterator
384: .hasNext();) {
385: Entity lSubtype = (Entity) lSubtypesIterator.next();
386: lCombinedSubtypes.add(lSubtype);
387: lCombinedSubtypes
388: .addAll(lSubtype.getCombinedSubtypes());
389: }
390: }
391: return Collections.unmodifiableCollection(lCombinedSubtypes);
392: }
393:
394: /** @return collection of references, which are parts of many-to-many association and
395: * where we are the aggregators */
396: public Collection getAgregatedManyToManyReferences() {
397: List lAgregatedManyToManyReferences = new ArrayList();
398: Collection lRoles = getRoles();
399: if (!lRoles.isEmpty()) {
400: for (Iterator lRolesIterator = lRoles.iterator(); lRolesIterator
401: .hasNext();) {
402: AssociationRole lRole = (AssociationRole) lRolesIterator
403: .next();
404: if (!AggregationTypeEnum.AGGREGATION.equals(lRole
405: .getAggregationType()))
406: continue; // Only after where we are agregators
407: if (!lRole.isPlural())
408: continue; // Only after many to many
409: AssociationRole lReference = lRole.getOppositeRole();
410: if (!lReference.isPlural())
411: continue; // Only after many to many
412: lAgregatedManyToManyReferences.add(lReference);
413: }
414: }
415: return Collections
416: .unmodifiableCollection(lAgregatedManyToManyReferences);
417: }
418:
419: /** @return collection of references, which are parts of many-to-many association and
420: * where we are the aggregators */
421: public Collection getCombinedAgregatedManyToManyReferences() {
422: List lCombinedAgregatedManyToManyReferences = new ArrayList();
423: Collection lRoles = this .getCombinedRoles();
424: if (!lRoles.isEmpty()) {
425: for (Iterator lRolesIterator = lRoles.iterator(); lRolesIterator
426: .hasNext();) {
427: AssociationRole lRole = (AssociationRole) lRolesIterator
428: .next();
429: if (!AggregationTypeEnum.AGGREGATION.equals(lRole
430: .getAggregationType()))
431: continue; // Only after where we are agregators
432: if (!lRole.isPlural())
433: continue; // Only after many to many
434: AssociationRole lReference = lRole.getOppositeRole();
435: if (!lReference.isPlural())
436: continue; // Only after many to many
437: lCombinedAgregatedManyToManyReferences.add(lReference);
438: }
439: }
440: return Collections
441: .unmodifiableCollection(lCombinedAgregatedManyToManyReferences);
442: }
443:
444: /** @return Collection of attributes which can be used for ordering. */
445: public Collection getAttributesUsedForOrdering() {
446: ArrayList lAttributesUsedForOrdering = new ArrayList();
447: Collection lAttributes = getAttributes();
448: if (!lAttributes.isEmpty()) {
449: for (Iterator lAttributesIterator = lAttributes.iterator(); lAttributesIterator
450: .hasNext();) {
451: Attribute lAttribute = (Attribute) lAttributesIterator
452: .next();
453: if (lAttribute.isUsedForOrdering())
454: lAttributesUsedForOrdering.add(lAttribute);
455: }
456: }
457: return Collections
458: .unmodifiableCollection(lAttributesUsedForOrdering);
459: }
460:
461: /** @return Collection of attributes which can be used for ordering. */
462: public Collection getCombinedAttributesUsedForOrdering() {
463: ArrayList lAttributesUsedForOrdering = new ArrayList();
464: Collection lCombinedAttributes = getCombinedAttributes();
465: if (!lCombinedAttributes.isEmpty()) {
466: for (Iterator lCombinedAttributesIterator = lCombinedAttributes
467: .iterator(); lCombinedAttributesIterator.hasNext();) {
468: Attribute lAttribute = (Attribute) lCombinedAttributesIterator
469: .next();
470: if (lAttribute.isUsedForOrdering())
471: lAttributesUsedForOrdering.add(lAttribute);
472: }
473: }
474: return Collections
475: .unmodifiableCollection(lAttributesUsedForOrdering);
476: }
477:
478: /**
479: * @param pAttributeName
480: * @return Attribute describing given field or throws exception if none found
481: */
482: public Attribute getAttribute(String pAttributeName) {
483: Attribute lFoundAttribute = findAttribute(pAttributeName);
484: // Throw exception if nothing found
485: if (lFoundAttribute == null)
486: throw new IllegalArgumentException(
487: "Unable to locate Attribute named '"
488: + pAttributeName
489: + "' in Entity. EntityRef: " + getRef());
490: return lFoundAttribute;
491: }
492:
493: /**
494: * @param pAttributeName
495: * @return Attribute describing given field or null if none found
496: */
497: public Attribute findAttribute(String pAttributeName) {
498: Collection lAttributes = getAttributes();
499: if (!lAttributes.isEmpty()) {
500: for (Iterator lAttributesIterator = lAttributes.iterator(); lAttributesIterator
501: .hasNext();) {
502: Attribute lAttribute = (Attribute) lAttributesIterator
503: .next();
504: if (lAttribute.getName().equals(pAttributeName))
505: return lAttribute;
506: }
507: }
508: return null;
509: }
510:
511: /**
512: * @param pAttributeName
513: * @return Attribute with the given name or null if none found
514: */
515: public Attribute findCombinedAttribute(String pAttributeName) {
516: Collection lAttributes = getAttributes();
517: if (!lAttributes.isEmpty()) {
518: for (Iterator lAttributesIterator = lAttributes.iterator(); lAttributesIterator
519: .hasNext();) {
520: Attribute lAttribute = (Attribute) lAttributesIterator
521: .next();
522: if (lAttribute.getName().equals(pAttributeName))
523: return lAttribute;
524: }
525: }
526: Entity lSupertype = getSupertype();
527: if (lSupertype != null)
528: return lSupertype.findCombinedAttribute(pAttributeName);
529: return null;
530: }
531:
532: /**
533: * @param pSelectorName
534: * @return Selector with requsted name or throws exception if none found
535: */
536: public Selector getSelector(String pSelectorName) {
537: Selector lFoundSelector = findSelector(pSelectorName);
538: // Throw exception if nothing found
539: if (lFoundSelector == null)
540: throw new IllegalArgumentException(
541: "Unable to locate Selector named '" + pSelectorName
542: + "' in Entity. EntityRef: " + getRef());
543: return lFoundSelector;
544: }
545:
546: /**
547: * @param pSelectorName
548: * @return Selector with requested name or null if none found
549: */
550: public Selector findSelector(String pSelectorName) {
551: Collection lSelectors = getSelectors();
552: if (!lSelectors.isEmpty()) {
553: for (Iterator lSelectorsIterator = lSelectors.iterator(); lSelectorsIterator
554: .hasNext();) {
555: Selector lSelector = (Selector) lSelectorsIterator
556: .next();
557: if (pSelectorName.equals(lSelector.getName()))
558: return lSelector;
559: }
560: }
561: return null;
562: }
563:
564: /**
565: * @param pSelectorName
566: * @return Selector with requested name or null if none found
567: */
568: public Selector findCombinedSelector(String pSelectorName) {
569: Collection lSelectors = getSelectors();
570: if (!lSelectors.isEmpty()) {
571: for (Iterator lSelectorsIterator = lSelectors.iterator(); lSelectorsIterator
572: .hasNext();) {
573: Selector lSelector = (Selector) lSelectorsIterator
574: .next();
575: if (pSelectorName.equals(lSelector.getName()))
576: return lSelector;
577: }
578: }
579: Entity lSupertype = getSupertype();
580: if (lSupertype != null)
581: return lSupertype.findCombinedSelector(pSelectorName);
582: return null;
583: }
584:
585: /**
586: * @param pConstraintName
587: * @return Constraint with the given name or throws exception if none found
588: */
589: public ModelElementConstraint getConstraint(String pConstraintName) {
590: ModelElementConstraint lFoundConstraint = findConstraint(pConstraintName);
591: // Throw exception if nothing found
592: if (lFoundConstraint == null)
593: throw new IllegalArgumentException(
594: "Unable to locate Constraint named '"
595: + pConstraintName
596: + "' in Entity. EntityRef: " + getRef());
597: return lFoundConstraint;
598: }
599:
600: /**
601: * @param pConstraintName
602: * @return Constraint with the given name or null if none found
603: */
604: public ModelElementConstraint findConstraint(String pConstraintName) {
605: Collection lConstraints = getConstraints();
606: if (!lConstraints.isEmpty()) {
607: for (Iterator lConstraintsIterator = lConstraints
608: .iterator(); lConstraintsIterator.hasNext();) {
609: ModelElementConstraint lConstraint = (ModelElementConstraint) lConstraintsIterator
610: .next();
611: if (lConstraint.getName().equals(pConstraintName))
612: return lConstraint;
613: }
614: }
615: return null;
616: }
617:
618: /** Returns array of all Constraints from this Entity and it's supertypes */
619: public Collection getCombinedConstraints() {
620: ArrayList lConstraints = new ArrayList();
621: Entity lEntity = this ;
622: do {
623: lConstraints.addAll(lEntity.getConstraints());
624: lEntity = lEntity.getSupertype();
625: } while (lEntity != null);
626: return Collections.unmodifiableCollection(lConstraints);
627: }
628:
629: // Returns list of DataTypes, Structures and Messages used in the Servicemodule. This includes owned and referenced elements
630: public Collection getCombinedTypes() {
631: Set lCombinedTypes = new HashSet();
632: // Look at the special types
633: lCombinedTypes.add(getCollectionContainsFlagDataType());
634: lCombinedTypes.add(getCollectionEmptyFlagDataType());
635: lCombinedTypes.add(getCollectionOffsetDataType());
636: lCombinedTypes.add(getCollectionSizeDataType());
637: lCombinedTypes.add(getSubsetSizeDataType());
638: lCombinedTypes.add(getInstanceIdDataType());
639: if (isModifiable())
640: lCombinedTypes.add(getVersionIdDataType());
641: if (getStateMachine() != null)
642: lCombinedTypes.add(getStateDataType());
643: // Interrogate the attribute types
644: for (Iterator lAttributesIterator = getAttributes().iterator(); lAttributesIterator
645: .hasNext();) {
646: Attribute lAttribute = (Attribute) lAttributesIterator
647: .next();
648: lCombinedTypes.add(lAttribute.getDataType());
649: }
650: // Interrogate the selectors
651: for (Iterator lSelectorsIterator = getSelectors().iterator(); lSelectorsIterator
652: .hasNext();) {
653: Selector lSelector = (Selector) lSelectorsIterator.next();
654: lCombinedTypes.addAll(lSelector.getCombinedTypes());
655: }
656:
657: Entity lSupertypeEntity = getSupertype();
658: if (lSupertypeEntity != null)
659: lCombinedTypes.addAll(lSupertypeEntity.getCombinedTypes());
660:
661: return java.util.Collections
662: .unmodifiableCollection(lCombinedTypes);
663: }
664: }
|