0001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
0002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
0003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
0004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
0005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
0006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
0008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
0009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
0010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
0012: // POSSIBILITY OF SUCH DAMAGE.
0013: //
0014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
0015: package com.metaboss.sdlctools.models.modelassistant.metabossmodel.domainsupport;
0016:
0017: import java.util.ArrayList;
0018: import java.util.Collection;
0019: import java.util.HashSet;
0020: import java.util.Iterator;
0021: import java.util.Set;
0022:
0023: import javax.jmi.reflect.ConstraintViolationException;
0024: import javax.jmi.reflect.RefObject;
0025:
0026: import com.metaboss.sdlctools.models.metabossmodel.ModelElementConstraint;
0027: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataType;
0028: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.Structure;
0029: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.StructureField;
0030: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
0031: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.AssociationRole;
0032: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
0033: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
0034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
0035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.PrimaryKeyElement;
0036:
0037: /** This class containse helper methods dealing with the Entity key structure model element */
0038: class TargetEntityKeyStructureHelper {
0039: private ModelAssistantImpl mModelAssistantImpl;
0040:
0041: TargetEntityKeyStructureHelper(
0042: ModelAssistantImpl pModelAssistantImpl) {
0043: mModelAssistantImpl = pModelAssistantImpl;
0044:
0045: // Add entity Name attribute change listener
0046: mModelAssistantImpl
0047: .addAttributeChangeListener(
0048: Entity.class,
0049: "Name",
0050: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0051: public void onAttributeBeingUpdated(
0052: RefObject pModelElementBeingUpdated,
0053: String pAttributeName,
0054: Object pOldValue, Object pNewValue) {
0055: Entity lEntity = (Entity) pModelElementBeingUpdated;
0056: Domain lDomain = lEntity.getDomain();
0057: if (lDomain == null)
0058: return; // Entity is not associated with domain
0059: String lDomainName = lDomain.getName();
0060: if (lDomainName == null)
0061: return; // Domain does not have a name
0062: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0063: .getSystem();
0064: if (lSystem == null)
0065: return; // Domain is not associated with system
0066: Servicemodule lServicemodule = lSystem
0067: .findServicemodule(StylesheetImpl
0068: .getDomainSupportServicemoduleName(lDomainName));
0069: if (lServicemodule == null)
0070: return; // There is no support servicemodule yet
0071: if (pNewValue == null) {
0072: // Only old value is known - ensure that the element is deleted
0073: ensureAbsent(lServicemodule,
0074: (String) pOldValue);
0075: } else {
0076: // The element must be present - rename or create
0077: if (pOldValue != null)
0078: ensureRenamedPresent(
0079: lServicemodule,
0080: lEntity,
0081: (String) pOldValue,
0082: (String) pNewValue);
0083: else
0084: ensurePresent(lServicemodule,
0085: lEntity,
0086: (String) pNewValue);
0087: }
0088: }
0089: });
0090:
0091: // Add attribute Name attribute change listener
0092: mModelAssistantImpl
0093: .addAttributeChangeListener(
0094: Attribute.class,
0095: "Name",
0096: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0097: public void onAttributeBeingUpdated(
0098: RefObject pModelElementBeingUpdated,
0099: String pAttributeName,
0100: Object pOldValue, Object pNewValue) {
0101: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0102: Entity lEntity = lAttribute.getEntity();
0103: if (lEntity == null)
0104: return; // Attribute is not associated with entity
0105: Domain lDomain = lEntity.getDomain();
0106: if (lDomain == null)
0107: return; // Entity is not associated with domain
0108: String lDomainName = lDomain.getName();
0109: if (lDomainName == null)
0110: return; // Domain does not have a name
0111: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0112: .getSystem();
0113: if (lSystem == null)
0114: return; // Domain is not associated with system
0115: Servicemodule lServicemodule = lSystem
0116: .findServicemodule(StylesheetImpl
0117: .getDomainSupportServicemoduleName(lDomainName));
0118: if (lServicemodule == null)
0119: return; // There is no support servicemodule yet
0120: Set lAllEntitiesToConsider = new HashSet();
0121: lAllEntitiesToConsider.add(lEntity);
0122: lAllEntitiesToConsider.addAll(lEntity
0123: .getCombinedSubtypes());
0124: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0125: .iterator(); lEntityElementsIterator
0126: .hasNext();) {
0127: Entity lEntityElement = (Entity) lEntityElementsIterator
0128: .next();
0129: String lEntityName = lEntityElement
0130: .getName();
0131: if (lEntityName == null)
0132: continue; // Entity does not have a name
0133: if (pNewValue == null) {
0134: // Only old value is known - ensure that the element is deleted
0135: primaryKeyAttribute_EnsureAbsent(
0136: lServicemodule,
0137: lEntityElement,
0138: (String) pOldValue);
0139: } else {
0140: // New value is known - analyse the criteria and deal with the element accordingly
0141: if (lEntityElement
0142: .getPrimaryKeyElements()
0143: .contains(lAttribute)) {
0144: // The element must be present - rename or create
0145: if (pOldValue != null)
0146: primaryKeyAttribute_EnsureRenamedPresent(
0147: lServicemodule,
0148: lEntityElement,
0149: (String) pOldValue,
0150: (String) pNewValue,
0151: lAttribute
0152: .getDescription(),
0153: lAttribute
0154: .getDataType());
0155: else
0156: primaryKeyAttribute_EnsurePresent(
0157: lServicemodule,
0158: lEntityElement,
0159: (String) pNewValue,
0160: lAttribute
0161: .getDescription(),
0162: lAttribute
0163: .getDataType());
0164: } else {
0165: // The element must be absent - delete
0166: primaryKeyAttribute_EnsureAbsent(
0167: lServicemodule,
0168: lEntityElement,
0169: (String) pNewValue);
0170: if (pOldValue != null)
0171: primaryKeyAttribute_EnsureAbsent(
0172: lServicemodule,
0173: lEntityElement,
0174: (String) pOldValue);
0175: }
0176: }
0177: }
0178: }
0179: });
0180: // Add attribute Description attribute change listener
0181: mModelAssistantImpl
0182: .addAttributeChangeListener(
0183: Attribute.class,
0184: "Description",
0185: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0186: public void onAttributeBeingUpdated(
0187: RefObject pModelElementBeingUpdated,
0188: String pAttributeName,
0189: Object pOldValue, Object pNewValue) {
0190: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0191: String lAttributeName = lAttribute
0192: .getName();
0193: if (lAttributeName == null)
0194: return; // Attribute does not have a name
0195: Entity lEntity = lAttribute.getEntity();
0196: if (lEntity == null)
0197: return; // Attribute is not associated with entity
0198: Domain lDomain = lEntity.getDomain();
0199: if (lDomain == null)
0200: return; // Entity is not associated with domain
0201: String lDomainName = lDomain.getName();
0202: if (lDomainName == null)
0203: return; // Domain does not have a name
0204: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0205: .getSystem();
0206: if (lSystem == null)
0207: return; // Domain is not associated with system
0208: Servicemodule lServicemodule = lSystem
0209: .findServicemodule(StylesheetImpl
0210: .getDomainSupportServicemoduleName(lDomainName));
0211: if (lServicemodule == null)
0212: return; // There is no support servicemodule yet
0213: Set lAllEntitiesToConsider = new HashSet();
0214: lAllEntitiesToConsider.add(lEntity);
0215: lAllEntitiesToConsider.addAll(lEntity
0216: .getCombinedSubtypes());
0217: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0218: .iterator(); lEntityElementsIterator
0219: .hasNext();) {
0220: Entity lEntityElement = (Entity) lEntityElementsIterator
0221: .next();
0222: String lEntityName = lEntityElement
0223: .getName();
0224: if (lEntityName == null)
0225: continue; // Entity does not have a name
0226: if (lEntityElement
0227: .getPrimaryKeyElements()
0228: .contains(lAttribute))
0229: primaryKeyAttribute_EnsurePresent(
0230: lServicemodule,
0231: lEntityElement,
0232: lAttributeName,
0233: (String) pNewValue,
0234: lAttribute
0235: .getDataType());
0236: }
0237: }
0238: });
0239: // Add attribute dataType reference change listener
0240: mModelAssistantImpl
0241: .addReferenceChangeListener(
0242: Attribute.class,
0243: "dataType",
0244: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0245: public void onReferenceBeingUpdated(
0246: RefObject pModelElementBeingUpdated,
0247: String pReferenceName,
0248: RefObject pReferencedModelElementToRemove,
0249: RefObject pReferencedModelElementToAdd) {
0250: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0251: String lAttributeName = lAttribute
0252: .getName();
0253: if (lAttributeName == null)
0254: return; // Attribute does not have a name
0255: Entity lEntity = lAttribute.getEntity();
0256: if (lEntity == null)
0257: return; // Attribute is not associated with entity
0258: Domain lDomain = lEntity.getDomain();
0259: if (lDomain == null)
0260: return; // Entity is not associated with domain
0261: String lDomainName = lDomain.getName();
0262: if (lDomainName == null)
0263: return; // Domain does not have a name
0264: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0265: .getSystem();
0266: if (lSystem == null)
0267: return; // Domain is not associated with system
0268: Servicemodule lServicemodule = lSystem
0269: .findServicemodule(StylesheetImpl
0270: .getDomainSupportServicemoduleName(lDomainName));
0271: if (lServicemodule == null)
0272: return; // There is no support servicemodule yet
0273: Set lAllEntitiesToConsider = new HashSet();
0274: lAllEntitiesToConsider.add(lEntity);
0275: lAllEntitiesToConsider.addAll(lEntity
0276: .getCombinedSubtypes());
0277: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0278: .iterator(); lEntityElementsIterator
0279: .hasNext();) {
0280: Entity lEntityElement = (Entity) lEntityElementsIterator
0281: .next();
0282: String lEntityName = lEntityElement
0283: .getName();
0284: if (lEntityName == null)
0285: continue; // Entity does not have a name
0286: // Analyse the criteria and deal with the element accordingly
0287: if (lEntityElement
0288: .getPrimaryKeyElements()
0289: .contains(lAttribute)) {
0290: if (pReferencedModelElementToAdd != null) {
0291: // We can use ensure..... for the whole attribute
0292: primaryKeyAttribute_EnsurePresent(
0293: lServicemodule,
0294: lEntityElement,
0295: lAttributeName,
0296: lAttribute
0297: .getDescription(),
0298: (DataType) pReferencedModelElementToAdd);
0299: } else if (pReferencedModelElementToRemove != null) {
0300: // We need to use specific datatype ensure... in order not to trigger creation of the structure field
0301: primaryKeyAttributeDataType_EnsureAbsent(
0302: lServicemodule,
0303: lEntityElement,
0304: lAttributeName);
0305: }
0306: }
0307: }
0308: }
0309: });
0310: // Add attribute keyedEntity reference change listener
0311: mModelAssistantImpl
0312: .addReferenceChangeListener(
0313: Attribute.class,
0314: "keyedEntity",
0315: new ModelAssistantImpl.ModelElementReferenceChangeListener() {
0316: public void onReferenceBeingUpdated(
0317: RefObject pModelElementBeingUpdated,
0318: String pReferenceName,
0319: RefObject pReferencedModelElementToRemove,
0320: RefObject pReferencedModelElementToAdd) {
0321: Attribute lAttribute = (Attribute) pModelElementBeingUpdated;
0322: String lAttributeName = lAttribute
0323: .getName();
0324: if (lAttributeName == null)
0325: return; // Attribute does not have a name
0326: Entity lEntity = lAttribute.getEntity();
0327: if (lEntity == null)
0328: return; // Attribute is not associated with entity
0329: Domain lDomain = lEntity.getDomain();
0330: if (lDomain == null)
0331: return; // Entity is not associated with domain
0332: String lDomainName = lDomain.getName();
0333: if (lDomainName == null)
0334: return; // Domain does not have a name
0335: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0336: .getSystem();
0337: if (lSystem == null)
0338: return; // Domain is not associated with system
0339: Servicemodule lServicemodule = lSystem
0340: .findServicemodule(StylesheetImpl
0341: .getDomainSupportServicemoduleName(lDomainName));
0342: if (lServicemodule == null)
0343: return; // There is no support servicemodule yet
0344: if (pReferencedModelElementToRemove != null) {
0345: // Remove this attribute from key structures from the outgoing owner entity and all subtypes
0346: Entity lEntityToRemoveKeyFrom = (Entity) pReferencedModelElementToRemove;
0347: Set lAllEntitiesToConsider = new HashSet();
0348: lAllEntitiesToConsider
0349: .add(lEntityToRemoveKeyFrom);
0350: lAllEntitiesToConsider
0351: .addAll(lEntityToRemoveKeyFrom
0352: .getCombinedSubtypes());
0353: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0354: .iterator(); lEntityElementsIterator
0355: .hasNext();) {
0356: Entity lEntityElement = (Entity) lEntityElementsIterator
0357: .next();
0358: String lEntityName = lEntityElement
0359: .getName();
0360: if (lEntityName == null
0361: || lEntityName.length() == 0)
0362: continue; // Entity does not have a name
0363: // Key element is being deleted. Make sure it is not present in the key structure
0364: primaryKeyAttribute_EnsureAbsent(
0365: lServicemodule,
0366: lEntityElement,
0367: lAttributeName);
0368: }
0369: }
0370: if (pReferencedModelElementToAdd != null) {
0371: // Add this attribute to the key structure of the incoming entity and all subtypes
0372: Entity lEntityToAddKeyTo = (Entity) pReferencedModelElementToAdd;
0373: if (lEntityToAddKeyTo != null) {
0374: Set lAllEntitiesToConsider = new HashSet();
0375: lAllEntitiesToConsider
0376: .add(lEntityToAddKeyTo);
0377: lAllEntitiesToConsider
0378: .addAll(lEntityToAddKeyTo
0379: .getCombinedSubtypes());
0380: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0381: .iterator(); lEntityElementsIterator
0382: .hasNext();) {
0383: Entity lEntityElement = (Entity) lEntityElementsIterator
0384: .next();
0385: String lEntityName = lEntityElement
0386: .getName();
0387: if (lEntityName == null
0388: || lEntityName
0389: .length() == 0)
0390: continue; // Entity does not have a name
0391: // Key element is being added. Make sure it is present in the key structure
0392: primaryKeyAttribute_EnsurePresent(
0393: lServicemodule,
0394: lEntityElement,
0395: lAttributeName,
0396: lAttribute
0397: .getDescription(),
0398: lAttribute
0399: .getDataType());
0400: }
0401: }
0402: }
0403: }
0404: });
0405:
0406: // Add reference Name attribute change listener
0407: mModelAssistantImpl
0408: .addAttributeChangeListener(
0409: AssociationRole.class,
0410: "Name",
0411: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0412: public void onAttributeBeingUpdated(
0413: RefObject pModelElementBeingUpdated,
0414: String pAttributeName,
0415: Object pOldValue, Object pNewValue) {
0416: AssociationRole lAssociationRole = (AssociationRole) pModelElementBeingUpdated;
0417: Entity lEntity = lAssociationRole
0418: .getReferencingEntity();
0419: if (lEntity == null)
0420: return; // Attribute is not associated with entity
0421: Domain lDomain = lEntity.getDomain();
0422: if (lDomain == null)
0423: return; // Entity is not associated with domain
0424: String lDomainName = lDomain.getName();
0425: if (lDomainName == null)
0426: return; // Domain does not have a name
0427: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0428: .getSystem();
0429: if (lSystem == null)
0430: return; // Domain is not associated with system
0431: Servicemodule lServicemodule = lSystem
0432: .findServicemodule(StylesheetImpl
0433: .getDomainSupportServicemoduleName(lDomainName));
0434: if (lServicemodule == null)
0435: return; // There is no support servicemodule yet
0436: Set lAllEntitiesToConsider = new HashSet();
0437: lAllEntitiesToConsider.add(lEntity);
0438: lAllEntitiesToConsider.addAll(lEntity
0439: .getCombinedSubtypes());
0440: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0441: .iterator(); lEntityElementsIterator
0442: .hasNext();) {
0443: Entity lEntityElement = (Entity) lEntityElementsIterator
0444: .next();
0445: if (pNewValue == null) {
0446: // Only old value is known - ensure that the element is deleted
0447: primaryKeyReference_EnsureAbsent(
0448: lServicemodule,
0449: lEntityElement,
0450: (String) pOldValue);
0451: } else {
0452: // New value is known - analyse the criteria and deal with the element accordingly
0453: if (lEntityElement
0454: .getPrimaryKeyElements()
0455: .contains(
0456: lAssociationRole)) {
0457: // The element must be present - rename or create
0458: if (pOldValue != null)
0459: primaryKeyReference_EnsureRenamedPresent(
0460: lServicemodule,
0461: lEntityElement,
0462: (String) pOldValue,
0463: (String) pNewValue,
0464: lAssociationRole
0465: .getDescription(),
0466: lAssociationRole
0467: .getEntity());
0468: else
0469: primaryKeyReference_EnsurePresent(
0470: lServicemodule,
0471: lEntityElement,
0472: (String) pNewValue,
0473: lAssociationRole
0474: .getDescription(),
0475: lAssociationRole
0476: .getEntity());
0477: } else {
0478: // The element must be absent - delete
0479: primaryKeyReference_EnsureAbsent(
0480: lServicemodule,
0481: lEntityElement,
0482: (String) pNewValue);
0483: if (pOldValue != null)
0484: primaryKeyReference_EnsureAbsent(
0485: lServicemodule,
0486: lEntityElement,
0487: (String) pOldValue);
0488: }
0489: }
0490: }
0491: }
0492: });
0493: // Add reference Description attribute change listener
0494: mModelAssistantImpl
0495: .addAttributeChangeListener(
0496: AssociationRole.class,
0497: "Description",
0498: new ModelAssistantImpl.ModelElementAttributeChangeListener() {
0499: public void onAttributeBeingUpdated(
0500: RefObject pModelElementBeingUpdated,
0501: String pAttributeName,
0502: Object pOldValue, Object pNewValue) {
0503: AssociationRole lAssociationRole = (AssociationRole) pModelElementBeingUpdated;
0504: String lAssociationRoleName = lAssociationRole
0505: .getName();
0506: if (lAssociationRoleName == null)
0507: return; // Role does not have a name
0508: Entity lEntity = lAssociationRole
0509: .getReferencingEntity();
0510: if (lEntity == null)
0511: return; // Attribute is not associated with entity
0512: Domain lDomain = lEntity.getDomain();
0513: if (lDomain == null)
0514: return; // Entity is not associated with domain
0515: String lDomainName = lDomain.getName();
0516: if (lDomainName == null)
0517: return; // Domain does not have a name
0518: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
0519: .getSystem();
0520: if (lSystem == null)
0521: return; // Domain is not associated with system
0522: Servicemodule lServicemodule = lSystem
0523: .findServicemodule(StylesheetImpl
0524: .getDomainSupportServicemoduleName(lDomainName));
0525: if (lServicemodule == null)
0526: return; // There is no support servicemodule yet
0527: Set lAllEntitiesToConsider = new HashSet();
0528: lAllEntitiesToConsider.add(lEntity);
0529: lAllEntitiesToConsider.addAll(lEntity
0530: .getCombinedSubtypes());
0531: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
0532: .iterator(); lEntityElementsIterator
0533: .hasNext();) {
0534: Entity lEntityElement = (Entity) lEntityElementsIterator
0535: .next();
0536: if (lEntityElement
0537: .getPrimaryKeyElements()
0538: .contains(lAssociationRole))
0539: primaryKeyReference_EnsurePresent(
0540: lServicemodule,
0541: lEntityElement,
0542: lAssociationRoleName,
0543: (String) pNewValue,
0544: lAssociationRole
0545: .getEntity());
0546: }
0547: }
0548: });
0549: }
0550:
0551: // This helper verifies constraints which are dealing with entity structures
0552: void verifyConstraints(Collection pViolations,
0553: Servicemodule pServicemodule, Entity pEntity,
0554: Collection pUnclaimedStructures) {
0555: // Work on the Key structure
0556: String lKeyStructureName = StylesheetImpl
0557: .getEntityKeyStructureName(pEntity.getName());
0558: Structure lKeyStructure = pServicemodule
0559: .findStructure(lKeyStructureName);
0560: if (lKeyStructure == null) {
0561: pViolations
0562: .add(new ConstraintViolationException(
0563: pServicemodule,
0564: pServicemodule.refMetaObject(),
0565: "A Domain Support Servicemodule must have Key Structure for every Entity in the corresponding Domain. The '"
0566: + lKeyStructureName
0567: + "' Structure not found."));
0568: return;
0569: }
0570: // Claim the message
0571: pUnclaimedStructures.remove(lKeyStructure); // Claim the structure
0572: // Work on the fields
0573: if (pEntity != null) {
0574: // Copy aside the collection of the fields, so we can keep track of the unused ones
0575: Collection lUnclaimedFields = new ArrayList();
0576: lUnclaimedFields.addAll(lKeyStructure.getFields());
0577:
0578: // Work on instance id field
0579: {
0580: String lInstanceIdFieldName = StylesheetImpl
0581: .getEntityInstanceIdStructureFieldName(pEntity
0582: .getName(), pEntity
0583: .getInstanceIdAttributeNameOverride());
0584: StructureField lInstanceIdStructureField = lKeyStructure
0585: .findField(lInstanceIdFieldName);
0586: if (lInstanceIdStructureField != null) {
0587: // Claim the field
0588: lUnclaimedFields.remove(lInstanceIdStructureField);
0589:
0590: if (lInstanceIdStructureField.isArray())
0591: pViolations
0592: .add(new ConstraintViolationException(
0593: lInstanceIdStructureField,
0594: lInstanceIdStructureField
0595: .refMetaObject(),
0596: "An Instance Identifier field in the Key Structure must be singular. The '"
0597: + lInstanceIdFieldName
0598: + "' Field is an Array."));
0599: DataType lExpectedDataType = pEntity
0600: .getInstanceIdDataType();
0601: DataType lActualDataType = lInstanceIdStructureField
0602: .getDataType();
0603: if ((lExpectedDataType != null && lActualDataType == null)
0604: || (lExpectedDataType == null && lActualDataType != null)
0605: || (lExpectedDataType != null
0606: && lActualDataType != null && lActualDataType
0607: .equals(lExpectedDataType) == false))
0608: pViolations
0609: .add(new ConstraintViolationException(
0610: lInstanceIdStructureField,
0611: lInstanceIdStructureField
0612: .refMetaObject(),
0613: "The Instance Identifier field in the Key Structure must be of the same type as Entity Instance Identifier type."));
0614: } else
0615: pViolations
0616: .add(new ConstraintViolationException(
0617: lKeyStructure,
0618: lKeyStructure.refMetaObject(),
0619: "A Key Structure must contain the Entity Instance Identifier field for the asociated Entity. The '"
0620: + lInstanceIdFieldName
0621: + "' Field not found."));
0622: }
0623: // Work on primary key fields
0624: for (Iterator lPrimaryKeyElementsIterator = pEntity
0625: .getPrimaryKeyElements().iterator(); lPrimaryKeyElementsIterator
0626: .hasNext();) {
0627: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0628: .next();
0629: if (lPrimaryKeyElement instanceof Attribute) {
0630: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0631: String lAttributeFieldName = StylesheetImpl
0632: .getEntityAttributeStructureFieldName(lAttribute
0633: .getName());
0634: StructureField lAttributeStructureField = lKeyStructure
0635: .findField(lAttributeFieldName);
0636: if (lAttributeStructureField != null) {
0637: // Claim the field
0638: lUnclaimedFields
0639: .remove(lAttributeStructureField);
0640:
0641: if (lAttributeStructureField.isArray())
0642: pViolations
0643: .add(new ConstraintViolationException(
0644: lAttributeStructureField,
0645: lAttributeStructureField
0646: .refMetaObject(),
0647: "An Entity Primary Key element field in the Key Structure must be singular. The '"
0648: + lAttributeStructureField
0649: + "' Field is an Array."));
0650: // Verify data types
0651: DataType lExpectedDataType = lAttribute
0652: .getDataType();
0653: DataType lActualDataType = lAttributeStructureField
0654: .getDataType();
0655: if ((lExpectedDataType != null && lActualDataType == null)
0656: || (lExpectedDataType == null && lActualDataType != null)
0657: || (lExpectedDataType != null
0658: && lActualDataType != null && lActualDataType
0659: .equals(lExpectedDataType) == false))
0660: pViolations
0661: .add(new ConstraintViolationException(
0662: lAttributeStructureField,
0663: lAttributeStructureField
0664: .refMetaObject(),
0665: "The '"
0666: + lAttributeFieldName
0667: + "' field in the Key Structure must be of the same type as corresponding Entity Attribute."));
0668: } else
0669: pViolations
0670: .add(new ConstraintViolationException(
0671: lKeyStructure,
0672: lKeyStructure.refMetaObject(),
0673: "A Key Structure must contain all Entity Primary Key fields for the asociated Entity. The '"
0674: + lAttributeFieldName
0675: + "' Field not found."));
0676: } else if (lPrimaryKeyElement instanceof AssociationRole) {
0677: AssociationRole lReference = (AssociationRole) lPrimaryKeyElement;
0678: String lReferenceFieldName = StylesheetImpl
0679: .getEntityReferenceStructureFieldName(lReference
0680: .getName());
0681: StructureField lReferenceStructureField = lKeyStructure
0682: .findField(lReferenceFieldName);
0683: if (lReferenceStructureField != null) {
0684: // Claim the field
0685: lUnclaimedFields
0686: .remove(lReferenceStructureField);
0687:
0688: if (lReferenceStructureField.isArray())
0689: pViolations
0690: .add(new ConstraintViolationException(
0691: lReferenceStructureField,
0692: lReferenceStructureField
0693: .refMetaObject(),
0694: "An Entity Primary Key element field in the Key Structure must be singular. The '"
0695: + lReferenceStructureField
0696: + "' Field is an Array."));
0697: // Verify data types
0698: Structure lExpectedStructureType = lReference
0699: .getEntity() != null ? pServicemodule
0700: .findStructure(StylesheetImpl
0701: .getEntityKeyStructureName(lReference
0702: .getEntity().getName()))
0703: : null;
0704: Structure lActualStructureType = lReferenceStructureField
0705: .getStructureType();
0706: if ((lExpectedStructureType != null && lActualStructureType == null)
0707: || (lExpectedStructureType == null && lActualStructureType != null)
0708: || (lExpectedStructureType != null
0709: && lActualStructureType != null && lActualStructureType
0710: .equals(lExpectedStructureType) == false))
0711: pViolations
0712: .add(new ConstraintViolationException(
0713: lReferenceStructureField,
0714: lReferenceStructureField
0715: .refMetaObject(),
0716: "The '"
0717: + lReferenceFieldName
0718: + "' field in the Key Structure must be the Key Structure of the entity being referenced."));
0719: } else
0720: pViolations
0721: .add(new ConstraintViolationException(
0722: lKeyStructure,
0723: lKeyStructure.refMetaObject(),
0724: "A Key Structure must contain all Entity Primary Key fields for the asociated Entity. The '"
0725: + lReferenceFieldName
0726: + "' Field not found."));
0727: }
0728: }
0729:
0730: // Create errors for all unclaimed fields
0731: for (Iterator lUnclaimedFieldsIterator = lUnclaimedFields
0732: .iterator(); lUnclaimedFieldsIterator.hasNext();) {
0733: StructureField lUnclaimedField = (StructureField) lUnclaimedFieldsIterator
0734: .next();
0735: pViolations
0736: .add(new ConstraintViolationException(
0737: lUnclaimedField,
0738: lUnclaimedField.refMetaObject(),
0739: "A Key Structure must contain only Instance Identifier and Primary Key fields for the asociated Entity. The '"
0740: + lUnclaimedField.getName()
0741: + "' Field is unexpected."));
0742: }
0743:
0744: // Work on constraints
0745: // Copy aside the collection of the constraints, so we can delete the unused ones
0746: Collection lUnclaimedConstraints = new ArrayList();
0747: lUnclaimedConstraints
0748: .addAll(lKeyStructure.getConstraints());
0749: {
0750: // Work on the validation constraint. Either InstanceId or all of the primary key elements must be present
0751: String lConstraintName = StylesheetImpl
0752: .getEntityKeyStructureValidationConstraintName();
0753: ModelElementConstraint lModelElementConstraint = lKeyStructure
0754: .findConstraint(lConstraintName);
0755: if (lModelElementConstraint == null) {
0756: pViolations
0757: .add(new ConstraintViolationException(
0758: lKeyStructure,
0759: lKeyStructure.refMetaObject(),
0760: "A Key Structure must have well formed Constraint performing sanity check on the data. The '"
0761: + lConstraintName
0762: + "' Constraint is missing."));
0763: } else {
0764: // Claim the field
0765: lUnclaimedConstraints
0766: .remove(lModelElementConstraint);
0767: }
0768: }
0769: // Remove unclaimed constraints
0770: for (Iterator lUnclaimedConstraintsIterator = lUnclaimedConstraints
0771: .iterator(); lUnclaimedConstraintsIterator
0772: .hasNext();) {
0773: ModelElementConstraint lUnclaimedConstraint = (ModelElementConstraint) lUnclaimedConstraintsIterator
0774: .next();
0775: pViolations
0776: .add(new ConstraintViolationException(
0777: lUnclaimedConstraint,
0778: lUnclaimedConstraint.refMetaObject(),
0779: "A Key Structure must have well formed Constraint performing sanity check on the data. The '"
0780: + lUnclaimedConstraint
0781: .getName()
0782: + "' Constraint is unexpected."));
0783: }
0784:
0785: }
0786: }
0787:
0788: // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
0789: void rectifyModel(Servicemodule pServicemodule, Entity pEntity,
0790: Collection pUnclaimedStructures) {
0791: // Check if we have a structure and than just call ensurePresent
0792: String lKeyStructureName = StylesheetImpl
0793: .getEntityKeyStructureName(pEntity.getName());
0794: Structure lKeyStructure = pServicemodule
0795: .findStructure(lKeyStructureName);
0796: if (lKeyStructure != null)
0797: pUnclaimedStructures.remove(lKeyStructure); // Claim the structure
0798: // Now just call ensurePresent
0799: ensurePresent(pServicemodule, pEntity, pEntity.getName());
0800: }
0801:
0802: // This helper renames the key and details structures
0803: void ensureRenamedPresent(Servicemodule pServicemodule,
0804: Entity pEntity, String pOldEntityName, String pNewEntityName) {
0805: // Note that this method only deals with renaming and than calls the ensure present method
0806:
0807: String lOldKeyStructureName = StylesheetImpl
0808: .getEntityKeyStructureName(pOldEntityName);
0809: Structure lOldKeyStructure = pServicemodule
0810: .findStructure(lOldKeyStructureName);
0811: String lNewKeyStructureName = StylesheetImpl
0812: .getEntityKeyStructureName(pNewEntityName);
0813: Structure lNewKeyStructure = pServicemodule
0814: .findStructure(lNewKeyStructureName);
0815: // Be relaxed here - allow for all sorts of mishaps
0816: if (lOldKeyStructure != null) {
0817: if (lNewKeyStructure != null) {
0818: // New and old structures are present - just delete the old one
0819: lOldKeyStructure.refDelete();
0820: } else {
0821: // Old structure is present - new one is not - rename
0822: lOldKeyStructure.setName(lNewKeyStructureName);
0823: }
0824: }
0825: // Call the ensure present bit
0826: ensurePresent(pServicemodule, pEntity, pNewEntityName);
0827: }
0828:
0829: // This helper makes sure that the key and details structures exist and uptodate
0830: void ensurePresent(Servicemodule pServicemodule, Entity pEntity,
0831: String pEntityName) {
0832: // Work on the Key structure
0833: String lKeyStructureName = StylesheetImpl
0834: .getEntityKeyStructureName(pEntityName);
0835: String lKeyStructureDescription = StylesheetImpl
0836: .getEntityKeyStructureDescription(pEntityName);
0837: Structure lKeyStructure = pServicemodule
0838: .findStructure(lKeyStructureName);
0839: if (lKeyStructure == null) {
0840: lKeyStructure = mModelAssistantImpl.mStructureClass
0841: .createStructure();
0842: lKeyStructure.setName(lKeyStructureName);
0843: lKeyStructure.setServicemodule(pServicemodule);
0844:
0845: }
0846: lKeyStructure.setDescription(lKeyStructureDescription);
0847: // Work on the fields
0848: if (pEntity != null) {
0849: // Copy aside the collection of the fields, so we can delete the unused ones
0850: Collection lUnclaimedFields = new ArrayList();
0851: lUnclaimedFields.addAll(lKeyStructure.getFields());
0852:
0853: // Work on Instance Id field
0854: {
0855: String lInstanceIdFieldName = StylesheetImpl
0856: .getEntityInstanceIdStructureFieldName(
0857: pEntityName,
0858: pEntity
0859: .getInstanceIdAttributeNameOverride());
0860: StructureField lInstanceIdStructureField = lKeyStructure
0861: .findField(lInstanceIdFieldName);
0862: if (lInstanceIdStructureField == null) {
0863: lInstanceIdStructureField = mModelAssistantImpl.mStructureFieldClass
0864: .createStructureField();
0865: lInstanceIdStructureField
0866: .setName(lInstanceIdFieldName);
0867: lInstanceIdStructureField
0868: .setOwnerStructure(lKeyStructure);
0869: } else {
0870: // Claim the field
0871: lUnclaimedFields.remove(lInstanceIdStructureField);
0872: }
0873: lInstanceIdStructureField
0874: .setDescription(StylesheetImpl
0875: .getEntityInstanceIdStructureFieldDescription(pEntityName));
0876: lInstanceIdStructureField.setArray(false);
0877: lInstanceIdStructureField.setStructureType(null);
0878: lInstanceIdStructureField.setDataType(pEntity
0879: .getInstanceIdDataType());
0880: }
0881:
0882: // Work on primary key fields
0883: for (Iterator lPrimaryKeyElementsIterator = pEntity
0884: .getPrimaryKeyElements().iterator(); lPrimaryKeyElementsIterator
0885: .hasNext();) {
0886: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
0887: .next();
0888: if (lPrimaryKeyElement instanceof Attribute) {
0889: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
0890: String lAttributeFieldName = StylesheetImpl
0891: .getEntityAttributeStructureFieldName(lAttribute
0892: .getName());
0893: StructureField lAttributeStructureField = lKeyStructure
0894: .findField(lAttributeFieldName);
0895: if (lAttributeStructureField == null) {
0896: lAttributeStructureField = mModelAssistantImpl.mStructureFieldClass
0897: .createStructureField();
0898: lAttributeStructureField
0899: .setName(lAttributeFieldName);
0900: lAttributeStructureField
0901: .setOwnerStructure(lKeyStructure);
0902: } else {
0903: // Claim the field
0904: lUnclaimedFields
0905: .remove(lAttributeStructureField);
0906: }
0907: lAttributeStructureField
0908: .setDescription(StylesheetImpl
0909: .getEntityAttributeStructureFieldDescription(
0910: lAttribute.getName(),
0911: lAttribute.getDescription()));
0912: lAttributeStructureField.setArray(false);
0913: lAttributeStructureField.setDataType(lAttribute
0914: .getDataType());
0915: lAttributeStructureField.setStructureType(null);
0916: } else if (lPrimaryKeyElement instanceof AssociationRole) {
0917: AssociationRole lReference = (AssociationRole) lPrimaryKeyElement;
0918: Entity lReferencedEntity = lReference.getEntity();
0919: String lReferenceFieldName = StylesheetImpl
0920: .getEntityReferenceStructureFieldName(lReference
0921: .getName());
0922: StructureField lReferenceStructureField = lKeyStructure
0923: .findField(lReferenceFieldName);
0924: if (lReferenceStructureField == null) {
0925: lReferenceStructureField = mModelAssistantImpl.mStructureFieldClass
0926: .createStructureField();
0927: lReferenceStructureField
0928: .setName(lReferenceFieldName);
0929: lReferenceStructureField
0930: .setOwnerStructure(lKeyStructure);
0931: } else {
0932: // Claim the field
0933: lUnclaimedFields
0934: .remove(lReferenceStructureField);
0935: }
0936: lReferenceStructureField
0937: .setDescription(StylesheetImpl
0938: .getEntityReferenceStructureFieldDescription(
0939: lReference.getName(),
0940: lReference.getDescription()));
0941: lReferenceStructureField.setArray(false);
0942: if (lReferencedEntity != null
0943: && lReferencedEntity.getName() != null)
0944: lReferenceStructureField
0945: .setStructureType(pServicemodule
0946: .findStructure(StylesheetImpl
0947: .getEntityKeyStructureName(lReferencedEntity
0948: .getName())));
0949: else
0950: lReferenceStructureField.setStructureType(null);
0951: lReferenceStructureField.setDataType(null);
0952: }
0953: }
0954: // Remove unclaimed fields
0955: for (Iterator lUnclaimedFieldsIterator = lUnclaimedFields
0956: .iterator(); lUnclaimedFieldsIterator.hasNext();) {
0957: StructureField lUnclaimedField = (StructureField) lUnclaimedFieldsIterator
0958: .next();
0959: lUnclaimedField.refDelete();
0960: }
0961:
0962: // Work on constraints
0963: // Copy aside the collection of the constraints, so we can delete the unused ones
0964: Collection lUnclaimedConstraints = new ArrayList();
0965: lUnclaimedConstraints
0966: .addAll(lKeyStructure.getConstraints());
0967: {
0968: // Work on the validation constraint. Either InstanceId or all of the primary key elements must be present
0969: String lConstraintName = StylesheetImpl
0970: .getEntityKeyStructureValidationConstraintName();
0971: ModelElementConstraint lModelElementConstraint = lKeyStructure
0972: .findConstraint(lConstraintName);
0973: if (lModelElementConstraint == null) {
0974: lModelElementConstraint = mModelAssistantImpl.mModelElementConstraintClass
0975: .createModelElementConstraint();
0976: lModelElementConstraint.setName(lConstraintName);
0977: lKeyStructure.getConstraints().add(
0978: lModelElementConstraint);
0979: } else {
0980: // Claim the constraint
0981: lUnclaimedConstraints
0982: .remove(lModelElementConstraint);
0983: }
0984: lModelElementConstraint
0985: .setDescription(StylesheetImpl
0986: .getEntityKeyStructureValidationConstraintDescription(pEntityName));
0987: // Build OCL expression and the error message
0988: String lInstanceIdFieldName = StylesheetImpl
0989: .getEntityInstanceIdStructureFieldName(
0990: pEntityName,
0991: pEntity
0992: .getInstanceIdAttributeNameOverride());
0993: // Ensure that the first character is lower case
0994: String lInstanceIdOCLFieldName = lInstanceIdFieldName
0995: .substring(0, 1).toLowerCase()
0996: + lInstanceIdFieldName.substring(1);
0997: Collection lPrimaryKeyElements = pEntity
0998: .getPrimaryKeyElements();
0999: if (lPrimaryKeyElements.isEmpty()) {
1000: // Set default error text
1001: lModelElementConstraint
1002: .setDefaultErrorText("Key structure does not contain enough information to identify the instance of the '"
1003: + pEntityName
1004: + "' entity. '"
1005: + lInstanceIdFieldName
1006: + "' field must contain entity instance identifier.");
1007:
1008: // Build and set the OCL expression
1009: StringBuffer lOCLExpression = new StringBuffer();
1010: lOCLExpression.append("not ");
1011: lOCLExpression.append(lInstanceIdOCLFieldName);
1012: lOCLExpression.append(".oclIsUndefined()");
1013: lModelElementConstraint
1014: .setOclExpression(lOCLExpression.toString());
1015: } else {
1016: // Set default error text
1017: lModelElementConstraint
1018: .setDefaultErrorText("Key structure does not contain enough information to identify the instance of the '"
1019: + pEntityName
1020: + "' entity. Either '"
1021: + lInstanceIdFieldName
1022: + "' field must contain entity instance identifier or all other fields (i.e. fields which are part of the natural primary key) must be populated.");
1023:
1024: // Build and set the OCL expression
1025: StringBuffer lOCLExpression = new StringBuffer();
1026: lOCLExpression.append("(not ");
1027: lOCLExpression.append(lInstanceIdOCLFieldName);
1028: lOCLExpression.append(".oclIsUndefined()) or ");
1029: if (lPrimaryKeyElements.size() > 1)
1030: lOCLExpression.append("(");
1031: for (Iterator lPrimaryKeyElementsIterator = pEntity
1032: .getPrimaryKeyElements().iterator();;) {
1033: PrimaryKeyElement lPrimaryKeyElement = (PrimaryKeyElement) lPrimaryKeyElementsIterator
1034: .next();
1035: String lFieldName = null;
1036: if (lPrimaryKeyElement instanceof Attribute) {
1037: Attribute lAttribute = (Attribute) lPrimaryKeyElement;
1038: lFieldName = StylesheetImpl
1039: .getEntityAttributeStructureFieldName(lAttribute
1040: .getName());
1041: } else if (lPrimaryKeyElement instanceof AssociationRole) {
1042: AssociationRole lReference = (AssociationRole) lPrimaryKeyElement;
1043: lFieldName = StylesheetImpl
1044: .getEntityReferenceStructureFieldName(lReference
1045: .getName());
1046: }
1047: // Ensure that the first character is lower case
1048: String lOCLFieldName = lFieldName.substring(0,
1049: 1).toLowerCase()
1050: + lFieldName.substring(1);
1051: lOCLExpression.append("(not ");
1052: lOCLExpression.append(lOCLFieldName);
1053: lOCLExpression.append(".oclIsUndefined())");
1054:
1055: if (lPrimaryKeyElementsIterator.hasNext())
1056: lOCLExpression.append(" and ");
1057: else
1058: break;
1059: }
1060: if (lPrimaryKeyElements.size() > 1)
1061: lOCLExpression.append(")");
1062: lModelElementConstraint
1063: .setOclExpression(lOCLExpression.toString());
1064: }
1065: }
1066: // Remove unclaimed constraints
1067: for (Iterator lUnclaimedConstraintsIterator = lUnclaimedConstraints
1068: .iterator(); lUnclaimedConstraintsIterator
1069: .hasNext();) {
1070: ModelElementConstraint lUnclaimedConstraint = (ModelElementConstraint) lUnclaimedConstraintsIterator
1071: .next();
1072: lUnclaimedConstraint.refDelete();
1073: }
1074: }
1075: }
1076:
1077: // This helper makes sure that the Details and details structures are absent
1078: void ensureAbsent(Servicemodule pServicemodule, String pEntityName) {
1079: // Work on the key structure
1080: Structure lKeyStructure = pServicemodule
1081: .findStructure(StylesheetImpl
1082: .getEntityKeyStructureName(pEntityName));
1083: if (lKeyStructure != null)
1084: lKeyStructure.refDelete();
1085: }
1086:
1087: // This helper renames the attribute
1088: void primaryKeyAttribute_EnsureRenamedPresent(
1089: Servicemodule pServicemodule, Entity pEntity,
1090: String pOldAttributeName, String pNewAttributeName,
1091: String pAttributeDescription, DataType pAttributeDataType) {
1092: Structure lKeyStructure = pServicemodule
1093: .findStructure(StylesheetImpl
1094: .getEntityKeyStructureName(pEntity.getName()));
1095: if (lKeyStructure == null)
1096: return; // No structure yet
1097: // Note that this method only deals with renaming and than calls the ensure present method
1098: String lOldAttributeName = StylesheetImpl
1099: .getEntityAttributeStructureFieldName(pOldAttributeName);
1100: StructureField lOldAttributeStructureField = lKeyStructure
1101: .findField(lOldAttributeName);
1102: String lNewAttributeName = StylesheetImpl
1103: .getEntityAttributeStructureFieldName(pNewAttributeName);
1104: StructureField lNewAttributeStructureField = lKeyStructure
1105: .findField(lNewAttributeName);
1106: // Be relaxed here - allow for all sorts of mishaps
1107: if (lOldAttributeStructureField != null) {
1108: if (lNewAttributeStructureField != null) {
1109: // New and old structures are present - just delete the old one
1110: lOldAttributeStructureField.refDelete();
1111: } else {
1112: // Old field is present - new one is not - rename
1113: lOldAttributeStructureField.setName(lNewAttributeName);
1114: }
1115: }
1116: // Call the ensure present bit
1117: primaryKeyAttribute_EnsurePresent(pServicemodule, pEntity,
1118: pNewAttributeName, pAttributeDescription,
1119: pAttributeDataType);
1120: }
1121:
1122: // This helper makes sure that the version id attribute is present in the details structure
1123: void primaryKeyAttribute_EnsurePresent(
1124: Servicemodule pServicemodule, Entity pEntity,
1125: String pAttributeName, String pAttributeDescription,
1126: DataType pAttributeDataType) {
1127: Structure lKeyStructure = pServicemodule
1128: .findStructure(StylesheetImpl
1129: .getEntityKeyStructureName(pEntity.getName()));
1130: if (lKeyStructure == null)
1131: return; // No structure yet
1132: String lAttributeFieldName = StylesheetImpl
1133: .getEntityAttributeStructureFieldName(pAttributeName);
1134: StructureField lAttributeStructureField = lKeyStructure
1135: .findField(lAttributeFieldName);
1136: if (lAttributeStructureField == null) {
1137: lAttributeStructureField = mModelAssistantImpl.mStructureFieldClass
1138: .createStructureField();
1139: lAttributeStructureField.setName(lAttributeFieldName);
1140: lAttributeStructureField.setOwnerStructure(lKeyStructure);
1141: }
1142: lAttributeStructureField.setDescription(StylesheetImpl
1143: .getEntityAttributeStructureFieldDescription(
1144: pAttributeName, pAttributeDescription));
1145: lAttributeStructureField.setArray(false);
1146: lAttributeStructureField.setDataType(pAttributeDataType);
1147: lAttributeStructureField.setStructureType(null);
1148: }
1149:
1150: // This helper makes sure that the version id attribute is absent in the details structure
1151: void primaryKeyAttribute_EnsureAbsent(Servicemodule pServicemodule,
1152: Entity pEntity, String pAttributeName) {
1153: Structure lKeyStructure = pServicemodule
1154: .findStructure(StylesheetImpl
1155: .getEntityKeyStructureName(pEntity.getName()));
1156: if (lKeyStructure == null)
1157: return; // No structure yet
1158: String lAttributeFieldName = StylesheetImpl
1159: .getEntityAttributeStructureFieldName(pAttributeName);
1160: StructureField lAttributeStructureField = lKeyStructure
1161: .findField(lAttributeFieldName);
1162: if (lAttributeStructureField != null)
1163: lAttributeStructureField.refDelete();
1164: }
1165:
1166: // This helper makes sure that the structure field data type is empty
1167: void primaryKeyAttributeDataType_EnsureAbsent(
1168: Servicemodule pServicemodule, Entity pEntity,
1169: String pAttributeName) {
1170: Structure lKeyStructure = pServicemodule
1171: .findStructure(StylesheetImpl
1172: .getEntityKeyStructureName(pEntity.getName()));
1173: if (lKeyStructure == null)
1174: return; // No structure yet
1175: String lAttributeFieldName = StylesheetImpl
1176: .getEntityAttributeStructureFieldName(pAttributeName);
1177: StructureField lAttributeStructureField = lKeyStructure
1178: .findField(lAttributeFieldName);
1179: if (lAttributeStructureField != null)
1180: lAttributeStructureField.setDataType(null);
1181: }
1182:
1183: // This helper renames the attribute
1184: void primaryKeyReference_EnsureRenamedPresent(
1185: Servicemodule pServicemodule, Entity pEntity,
1186: String pOldReferenceName, String pNewReferenceName,
1187: String pReferenceDescription, Entity pReferencedEntity) {
1188: Structure lKeyStructure = pServicemodule
1189: .findStructure(StylesheetImpl
1190: .getEntityKeyStructureName(pEntity.getName()));
1191: if (lKeyStructure == null)
1192: return; // No structure yet
1193: // Note that this method only deals with renaming and than calls the ensure present method
1194: String lOldFieldName = StylesheetImpl
1195: .getEntityReferenceStructureFieldName(pOldReferenceName);
1196: StructureField lOldStructureField = lKeyStructure
1197: .findField(lOldFieldName);
1198: String lNewFieldName = StylesheetImpl
1199: .getEntityReferenceStructureFieldName(pNewReferenceName);
1200: StructureField lNewStructureField = lKeyStructure
1201: .findField(lNewFieldName);
1202: // Be relaxed here - allow for all sorts of mishaps
1203: if (lOldStructureField != null) {
1204: if (lNewStructureField != null) {
1205: // New and old structures are present - just delete the old one
1206: lOldStructureField.refDelete();
1207: } else {
1208: // Old field is present - new one is not - rename
1209: lOldStructureField.setName(lNewFieldName);
1210: }
1211: }
1212: // Call the ensure present bit
1213: primaryKeyReference_EnsurePresent(pServicemodule, pEntity,
1214: pNewReferenceName, pReferenceDescription,
1215: pReferencedEntity);
1216: }
1217:
1218: // This helper makes sure that the version id attribute is present in the details structure
1219: void primaryKeyReference_EnsurePresent(
1220: Servicemodule pServicemodule, Entity pEntity,
1221: String pReferenceName, String pReferenceDescription,
1222: Entity pReferencedEntity) {
1223: Structure lKeyStructure = pServicemodule
1224: .findStructure(StylesheetImpl
1225: .getEntityKeyStructureName(pEntity.getName()));
1226: if (lKeyStructure == null)
1227: return; // No structure yet
1228: String lReferenceFieldName = StylesheetImpl
1229: .getEntityReferenceStructureFieldName(pReferenceName);
1230: StructureField lStructureField = lKeyStructure
1231: .findField(lReferenceFieldName);
1232: if (lStructureField == null) {
1233: lStructureField = mModelAssistantImpl.mStructureFieldClass
1234: .createStructureField();
1235: lStructureField.setName(lReferenceFieldName);
1236: lStructureField.setOwnerStructure(lKeyStructure);
1237: }
1238: lStructureField.setDescription(StylesheetImpl
1239: .getEntityReferenceStructureFieldDescription(
1240: pReferenceName, pReferenceDescription));
1241: lStructureField.setArray(false);
1242: if (pReferencedEntity != null
1243: && pReferencedEntity.getName() != null)
1244: lStructureField
1245: .setStructureType(pServicemodule
1246: .findStructure(StylesheetImpl
1247: .getEntityKeyStructureName(pReferencedEntity
1248: .getName())));
1249: else
1250: lStructureField.setStructureType(null);
1251: lStructureField.setDataType(null);
1252: }
1253:
1254: // This helper makes sure that the version id attribute is absent in the details structure
1255: void primaryKeyReference_EnsureAbsent(Servicemodule pServicemodule,
1256: Entity pEntity, String pReferenceName) {
1257: Structure lKeyStructure = pServicemodule
1258: .findStructure(StylesheetImpl
1259: .getEntityKeyStructureName(pEntity.getName()));
1260: if (lKeyStructure == null)
1261: return; // No structure yet
1262: String lReferenceFieldName = StylesheetImpl
1263: .getEntityReferenceStructureFieldName(pReferenceName);
1264: StructureField lStructureField = lKeyStructure
1265: .findField(lReferenceFieldName);
1266: if (lStructureField != null)
1267: lStructureField.refDelete();
1268: }
1269: }
|