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.domainsupport;
016:
017: import java.util.Collection;
018: import java.util.HashSet;
019: import java.util.Iterator;
020: import java.util.Set;
021:
022: import javax.jmi.reflect.RefObject;
023:
024: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Service;
025: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
026: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AggregationTypeEnum;
027: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
028: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
029: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
031:
032: /** This class holds details about Entity State Selector
033: * being processed. Used internally in the Assistant impl */
034: class SourceEntityHelper {
035: private ModelAssistantImpl mModelAssistantImpl;
036:
037: SourceEntityHelper(ModelAssistantImpl pModelAssistantImpl) {
038: mModelAssistantImpl = pModelAssistantImpl;
039: }
040:
041: // Handle the creation of the domain
042: void onJustCreated(Entity pEntity) {
043: // Automatically create operations, structures and messages pertained to the entity - if possible
044: String lEntityName = pEntity.getName();
045: if (lEntityName == null || lEntityName.length() == 0)
046: return; // Entity does not have a name
047: Domain lDomain = pEntity.getDomain();
048: if (lDomain == null)
049: return; // Entity is not associated with domain
050: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
051: .getSystem();
052: if (lSystem == null)
053: return; // Domain is not associated with system
054: String lDomainName = lDomain.getName();
055: if (lDomainName == null || lDomainName.length() == 0)
056: return; // Domain does not have a name
057: String lServicemoduleName = StylesheetImpl
058: .getDomainSupportServicemoduleName(lDomainName);
059: Servicemodule lServicemodule = lSystem
060: .findServicemodule(lServicemoduleName);
061: if (lServicemodule == null)
062: return; // There is no support servicemodule yet
063: // Work on structures
064: mModelAssistantImpl.mTargetEntityKeyStructureHelper
065: .ensurePresent(lServicemodule, pEntity, lEntityName);
066: mModelAssistantImpl.mTargetEntityDetailsStructureHelper
067: .ensurePresent(lServicemodule, pEntity, lEntityName);
068: // Work on messages found in modifiable entity
069: if (pEntity.isModifiable())
070: mModelAssistantImpl.mTargetVersionMismatchMessageHelper
071: .ensurePresent(lServicemodule, pEntity, lEntityName);
072: else
073: mModelAssistantImpl.mTargetVersionMismatchMessageHelper
074: .ensureAbsent(lServicemodule, lEntityName);
075: // Work on messages found in the entities with the primary keys
076: if (!pEntity.getPrimaryKeyElements().isEmpty())
077: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
078: .ensurePresent(lServicemodule, pEntity, lEntityName);
079: else
080: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
081: .ensureAbsent(lServicemodule, lEntityName);
082:
083: // Work on domain support operations
084: String lDomainSupportServiceName = StylesheetImpl
085: .getDataManagementServiceName(lDomainName);
086: Service lDomainSupportService = lServicemodule
087: .findService(lDomainSupportServiceName);
088: // Iterate through references and ensure that reference related elements are dealt with
089: for (Iterator lEntityReferencesIterator = pEntity
090: .getCombinedReferences().iterator(); lEntityReferencesIterator
091: .hasNext();) {
092: AssociationRole lReference = (AssociationRole) lEntityReferencesIterator
093: .next();
094: // Work on entity reference related domain support operations
095: if (lDomainSupportService != null) {
096: String lReferencePluralName = lReference
097: .getPluralName();
098: if (lReferencePluralName != null) {
099: AssociationRole lOppositeRole = lReference
100: .getOppositeRole();
101: if (lOppositeRole != null
102: && lReference.isPlural()
103: && lOppositeRole.isPlural()
104: && AggregationTypeEnum.AGGREGATION
105: .equals(lOppositeRole
106: .getAggregationType())) {
107: mModelAssistantImpl.mTargetAddReferencedEntityOperationHelper
108: .ensurePresent(lDomainSupportService,
109: lReference, lEntityName,
110: lReferencePluralName);
111: mModelAssistantImpl.mTargetRemoveReferencedEntityOperationHelper
112: .ensurePresent(lDomainSupportService,
113: lReference, lEntityName,
114: lReferencePluralName);
115: mModelAssistantImpl.mTargetGetAllReferencedEntitiesOperationHelper
116: .ensurePresent(lDomainSupportService,
117: lReference, lEntityName,
118: lReferencePluralName);
119: } else {
120: mModelAssistantImpl.mTargetAddReferencedEntityOperationHelper
121: .ensureAbsent(lDomainSupportService,
122: lEntityName,
123: lReferencePluralName);
124: mModelAssistantImpl.mTargetRemoveReferencedEntityOperationHelper
125: .ensureAbsent(lDomainSupportService,
126: lEntityName,
127: lReferencePluralName);
128: mModelAssistantImpl.mTargetGetAllReferencedEntitiesOperationHelper
129: .ensureAbsent(lDomainSupportService,
130: lEntityName,
131: lReferencePluralName);
132: }
133: }
134: }
135: }
136: }
137:
138: // Handle the deletion of the domain
139: void onDeleting(Entity pEntity) {
140: String lEntityName = pEntity.getName();
141: if (lEntityName == null || lEntityName.length() == 0)
142: return; // Entity does not have a name
143: Domain lDomain = pEntity.getDomain();
144: if (lDomain == null)
145: return; // Entity is not associated with domain
146: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
147: .getSystem();
148: if (lSystem == null)
149: return; // Domain is not associated with system
150: String lDomainName = lDomain.getName();
151: if (lDomainName == null || lDomainName.length() == 0)
152: return; // Domain does not have a name yet
153: String lServicemoduleName = StylesheetImpl
154: .getDomainSupportServicemoduleName(lDomainName);
155: Servicemodule lServicemodule = lSystem
156: .findServicemodule(lServicemoduleName);
157: if (lServicemodule == null)
158: return; // There is no support servicemodule yet
159: // Work on structures
160: mModelAssistantImpl.mTargetEntityKeyStructureHelper
161: .ensureAbsent(lServicemodule, lEntityName);
162: mModelAssistantImpl.mTargetEntityDetailsStructureHelper
163: .ensureAbsent(lServicemodule, lEntityName);
164: // Work on messages found in modifiable entity
165: mModelAssistantImpl.mTargetVersionMismatchMessageHelper
166: .ensureAbsent(lServicemodule, lEntityName);
167: // Work on messages found in the entities with the primary keys
168: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
169: .ensureAbsent(lServicemodule, lEntityName);
170:
171: // Work on domain support operations
172: String lDomainSupportServiceName = StylesheetImpl
173: .getDataManagementServiceName(lDomainName);
174: Service lDomainSupportService = lServicemodule
175: .findService(lDomainSupportServiceName);
176: if (lDomainSupportService == null)
177: return; // There is no support servicemodule yet
178: // Work on operations which depend on the plural name
179: String lEntityPluralName = pEntity.getPluralName();
180: // Iterate through references and ensure that reference related elements are absent
181: for (Iterator lEntityReferencesIterator = pEntity
182: .getCombinedReferences().iterator(); lEntityReferencesIterator
183: .hasNext();) {
184: AssociationRole lReference = (AssociationRole) lEntityReferencesIterator
185: .next();
186: // Work on entity reference related domain support operations
187: if (lDomainSupportService != null) {
188: String lReferencePluralName = lReference
189: .getPluralName();
190: if (lReferencePluralName != null) {
191: mModelAssistantImpl.mTargetAddReferencedEntityOperationHelper
192: .ensureAbsent(lDomainSupportService,
193: lEntityName, lReferencePluralName);
194: mModelAssistantImpl.mTargetRemoveReferencedEntityOperationHelper
195: .ensureAbsent(lDomainSupportService,
196: lEntityName, lReferencePluralName);
197: mModelAssistantImpl.mTargetGetAllReferencedEntitiesOperationHelper
198: .ensureAbsent(lDomainSupportService,
199: lEntityName, lReferencePluralName);
200: }
201: }
202: }
203: }
204:
205: // Handle changes to references of the domain
206: void onChangingReference(Entity pEntity, String pReferenceName,
207: RefObject pReferencedModelElementToRemove,
208: RefObject pReferencedModelElementToAdd) {
209: String lEntityName = pEntity.getName();
210: if (lEntityName == null || lEntityName.length() == 0)
211: return; // Entity does not have a name
212: Domain lDomain = pEntity.getDomain();
213: if (lDomain == null)
214: return; // Entity is not associated with domain
215: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
216: .getSystem();
217: if (lSystem == null)
218: return; // Domain is not associated with system
219: String lDomainName = lDomain.getName();
220: if (lDomainName == null || lDomainName.length() == 0)
221: return; // Domain does not have a name
222: String lServicemoduleName = StylesheetImpl
223: .getDomainSupportServicemoduleName(lDomainName);
224: Servicemodule lServicemodule = lSystem
225: .findServicemodule(lServicemoduleName);
226: if (lServicemodule == null)
227: return; // There is no support servicemodule yet
228: // Detect the change of the entity's supertype
229: if (pReferenceName.equals("supertype")) {
230: // For this entity as well as all supertype entities
231: // (1) We need to remove all attributes from the old supertype and add all attributes from the new supertype
232: //TODO: I think that we need to remove all primary key elements from the old supertype and add all prmary key elements of the new supertype
233:
234: // Collect what needs to be done first
235: Set lAttributesToAdd = new HashSet();
236: if (pReferencedModelElementToAdd != null) {
237: Entity lNewSupertype = (Entity) pReferencedModelElementToAdd;
238: lAttributesToAdd.addAll(lNewSupertype
239: .getCombinedAttributes());
240: }
241: Set lAttributesToRemove = new HashSet();
242: if (pReferencedModelElementToRemove != null) {
243: Entity lOldSupertype = (Entity) pReferencedModelElementToRemove;
244: lAttributesToRemove.addAll(lOldSupertype
245: .getCombinedAttributes());
246: }
247: Set lAllEntitiesToConsider = new HashSet();
248: lAllEntitiesToConsider.add(pEntity);
249: lAllEntitiesToConsider
250: .addAll(pEntity.getCombinedSubtypes());
251: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
252: .iterator(); lEntityElementsIterator.hasNext();) {
253: Entity lEntityElement = (Entity) lEntityElementsIterator
254: .next();
255: String lEntityElementName = lEntityElement.getName();
256: if (lEntityElementName == null
257: || lEntityElementName.length() == 0)
258: continue; // Entity does not have a name
259: Collection lEntityElementPrimaryKeyElements = lEntityElement
260: .getPrimaryKeyElements();
261: for (Iterator lAttributesToRemoveIterator = lAttributesToRemove
262: .iterator(); lAttributesToRemoveIterator
263: .hasNext();) {
264: Attribute lAttributeToRemove = (Attribute) lAttributesToRemoveIterator
265: .next();
266: mModelAssistantImpl.mTargetEntityDetailsStructureHelper
267: .attribute_EnsureAbsent(lServicemodule,
268: lEntityElement, lAttributeToRemove
269: .getName());
270: mModelAssistantImpl.mTargetEntityKeyStructureHelper
271: .primaryKeyAttribute_EnsureAbsent(
272: lServicemodule, lEntityElement,
273: lAttributeToRemove.getName());
274: }
275: for (Iterator lAttributesToAddIterator = lAttributesToAdd
276: .iterator(); lAttributesToAddIterator.hasNext();) {
277: Attribute lAttributeToAdd = (Attribute) lAttributesToAddIterator
278: .next();
279: mModelAssistantImpl.mTargetEntityDetailsStructureHelper
280: .attribute_EnsurePresent(lServicemodule,
281: lEntityElement, lAttributeToAdd
282: .getName(), lAttributeToAdd
283: .getDescription(),
284: lAttributeToAdd.getDataType());
285: if (lEntityElementPrimaryKeyElements
286: .contains(lAttributeToAdd))
287: mModelAssistantImpl.mTargetEntityKeyStructureHelper
288: .primaryKeyAttribute_EnsurePresent(
289: lServicemodule, lEntityElement,
290: lAttributeToAdd.getName(),
291: lAttributeToAdd
292: .getDescription(),
293: lAttributeToAdd.getDataType());
294: }
295: }
296: }
297: return; // Thats it
298: }
299: }
|