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.modelassistant.metabossmodel.implicittypes;
016:
017: import java.util.Collection;
018: import java.util.List;
019:
020: import javax.jmi.reflect.ConstraintViolationException;
021:
022: import com.metaboss.sdlctools.models.ModelRepositoryException;
023: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
024: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
025:
026: /** This class holds details about Entity. Used internally in the Assistant impl */
027: class EntityHelper {
028: private ModelAssistantImpl mModelAssistantImpl;
029:
030: // This helper is looking at the conditions and ensuring the inegrity of the data type
031: // it will create the missing data type and delete exta one if necessary
032: static void verifyEntityIntegrity(Collection pViolations,
033: ModelAssistantImpl pModelAssistantImpl, Entity lEntity,
034: List pUnprocessedDataTypes, HelperContext pHelperContext) {
035: // Get all enterprise datatypes
036: DataType lBooleanFlagDataType = pHelperContext
037: .getBooleanFlagDataType();
038: if (lBooleanFlagDataType == null)
039: return; // No mandatory data type
040: DataType lActualCollectionContainsFlagDataType = lEntity
041: .getCollectionContainsFlagDataType();
042: if (lActualCollectionContainsFlagDataType == null
043: || lActualCollectionContainsFlagDataType
044: .equals(lBooleanFlagDataType) == false)
045: pViolations.add(new ConstraintViolationException(lEntity,
046: lEntity.refMetaObject(),
047: "The Entity CollectionContainsFlag data type must be set to "
048: + lBooleanFlagDataType.getRef()
049: + " data type."));
050: DataType lActualCollectionEmptyFlagDataType = lEntity
051: .getCollectionEmptyFlagDataType();
052: if (lActualCollectionEmptyFlagDataType == null
053: || lActualCollectionEmptyFlagDataType
054: .equals(lBooleanFlagDataType) == false)
055: pViolations.add(new ConstraintViolationException(lEntity,
056: lEntity.refMetaObject(),
057: "The Entity CollectionEmptyFlag data type must be set to "
058: + lBooleanFlagDataType.getRef()
059: + " data type."));
060:
061: DataType lCollectionOffsetDataType = pHelperContext
062: .getCollectionOffsetDataType();
063: if (lCollectionOffsetDataType == null)
064: return; // No mandatory data type
065: DataType lActualCollectionOffsetDataType = lEntity
066: .getCollectionOffsetDataType();
067: if (lActualCollectionOffsetDataType == null
068: || lActualCollectionOffsetDataType
069: .equals(lCollectionOffsetDataType) == false)
070: pViolations.add(new ConstraintViolationException(lEntity,
071: lEntity.refMetaObject(),
072: "The Entity CollectionOffset data type must be set to "
073: + lBooleanFlagDataType.getRef()
074: + " data type."));
075:
076: DataType lCollectionSizeDataType = pHelperContext
077: .getCollectionSizeDataType();
078: if (lCollectionSizeDataType == null)
079: return; // No mandatory data type
080: DataType lActualCollectionSizeDataType = lEntity
081: .getCollectionSizeDataType();
082: if (lActualCollectionSizeDataType == null
083: || lActualCollectionSizeDataType
084: .equals(lCollectionSizeDataType) == false)
085: pViolations.add(new ConstraintViolationException(lEntity,
086: lEntity.refMetaObject(),
087: "The Entity CollectionSize data type must be set to "
088: + lBooleanFlagDataType.getRef()
089: + " data type."));
090:
091: DataType lSubsetSizeDataType = pHelperContext
092: .getSubsetSizeDataType();
093: if (lSubsetSizeDataType == null)
094: return; // No mandatory data type
095: DataType lActualSubsetSizeDataType = lEntity
096: .getSubsetSizeDataType();
097: if (lActualSubsetSizeDataType == null
098: || lActualSubsetSizeDataType
099: .equals(lSubsetSizeDataType) == false)
100: pViolations.add(new ConstraintViolationException(lEntity,
101: lEntity.refMetaObject(),
102: "The Entity SubsetSize data type must be set to "
103: + lBooleanFlagDataType.getRef()
104: + " data type."));
105:
106: // Now call specific helpers to help with validation entity related data types
107: // Work on Instance id data type
108: EntityInstanceIdDataTypeHelper
109: .verifyEntityInstanceIdDataTypeIntegrity(pViolations,
110: pModelAssistantImpl, lEntity,
111: pUnprocessedDataTypes, pHelperContext);
112: // Work on Version Id data type
113: EntityVersionIdDataTypeHelper
114: .verifyEntityVersionIdDataTypeIntegrity(pViolations,
115: pModelAssistantImpl, lEntity,
116: pUnprocessedDataTypes, pHelperContext);
117: // Work on State data type
118: EntityStateDataTypeHelper.verifyEntityStateDataTypeIntegrity(
119: pViolations, pModelAssistantImpl, lEntity,
120: pUnprocessedDataTypes, pHelperContext);
121: // Work on Ordering Instruction data type
122: EntityOrderingInstructionsDataTypeHelper
123: .verifyEntityOrderingInstructionDataTypeIntegrity(
124: pViolations, pModelAssistantImpl, lEntity,
125: pUnprocessedDataTypes, pHelperContext);
126: }
127:
128: // This helper is looking at the conditions and ensuring the inegrity of the data type
129: // it will create the missing data type and delete exta one if necessary
130: static void ensureEntityIntegrity(
131: ModelAssistantImpl pModelAssistantImpl, Entity pEntity,
132: List pUnprocessedDataTypes, HelperContext pHelperContext)
133: throws ModelRepositoryException {
134: // Get all enterprise datatypes
135: DataType lBooleanFlagDataType = pHelperContext
136: .getBooleanFlagDataType();
137: if (lBooleanFlagDataType == null)
138: return; // No mandatory data type
139: pEntity.setCollectionContainsFlagDataType(lBooleanFlagDataType);
140: pEntity.setCollectionEmptyFlagDataType(lBooleanFlagDataType);
141:
142: DataType lCollectionOffsetDataType = pHelperContext
143: .getCollectionOffsetDataType();
144: if (lCollectionOffsetDataType == null)
145: return; // No mandatory data type
146: pEntity.setCollectionOffsetDataType(lCollectionOffsetDataType);
147:
148: DataType lCollectionSizeDataType = pHelperContext
149: .getCollectionSizeDataType();
150: if (lCollectionSizeDataType == null)
151: return; // No mandatory data type
152: pEntity.setCollectionSizeDataType(lCollectionSizeDataType);
153:
154: DataType lSubsetSizeDataType = pHelperContext
155: .getSubsetSizeDataType();
156: if (lSubsetSizeDataType == null)
157: return; // No mandatory data type
158: pEntity.setSubsetSizeDataType(lSubsetSizeDataType);
159:
160: // Now call specific helpers to help with entity related data types
161: // Work on Instance id data type
162: EntityInstanceIdDataTypeHelper
163: .ensureEntityInstanceIdDataTypeIntegrity(
164: pModelAssistantImpl, pEntity,
165: pUnprocessedDataTypes, pHelperContext);
166: // Work on Version Id data type
167: EntityVersionIdDataTypeHelper
168: .ensureEntityVersionIdDataTypeIntegrity(
169: pModelAssistantImpl, pEntity,
170: pUnprocessedDataTypes, pHelperContext);
171: // Work on State data type
172: EntityStateDataTypeHelper.ensureEntityStateDataTypeIntegrity(
173: pModelAssistantImpl, pEntity, pUnprocessedDataTypes,
174: pHelperContext);
175: // Work on Ordering Instruction data type
176: EntityOrderingInstructionsDataTypeHelper
177: .ensureEntityOrderingInstructionDataTypeIntegrity(
178: pModelAssistantImpl, pEntity,
179: pUnprocessedDataTypes, pHelperContext);
180: }
181: }
|