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.HashSet;
018: import java.util.Iterator;
019: import java.util.Set;
020:
021: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Servicemodule;
022: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Attribute;
023: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Domain;
024: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
025:
026: /** This class is looking after actions on attributes */
027: class SourceAttributeHelper {
028: private ModelAssistantImpl mModelAssistantImpl;
029:
030: SourceAttributeHelper(ModelAssistantImpl pModelAssistantImpl) {
031: mModelAssistantImpl = pModelAssistantImpl;
032: }
033:
034: // Handle the creation
035: void onJustCreated(Attribute pAttribute) {
036: String lAttributeName = pAttribute.getName();
037: if (lAttributeName == null || lAttributeName.length() == 0)
038: return; // Attribute does not have a name
039: Entity lEntity = pAttribute.getEntity();
040: if (lEntity == null)
041: return; // Attribute is not associated with entity
042: Domain lDomain = lEntity.getDomain();
043: if (lDomain == null)
044: return; // Entity is not associated with domain
045: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
046: .getSystem();
047: if (lSystem == null)
048: return; // Domain is not associated with system
049: String lDomainName = lDomain.getName();
050: if (lDomainName == null || lDomainName.length() == 0)
051: return; // Domain does not have a name
052: String lServicemoduleName = StylesheetImpl
053: .getDomainSupportServicemoduleName(lDomainName);
054: Servicemodule lServicemodule = lSystem
055: .findServicemodule(lServicemoduleName);
056: if (lServicemodule == null)
057: return; // There is no support servicemodule yet
058: // We will have to work on the entity and all subtypes
059: Set lAllEntitiesToConsider = new HashSet();
060: lAllEntitiesToConsider.add(lEntity);
061: lAllEntitiesToConsider.addAll(lEntity.getCombinedSubtypes());
062: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
063: .iterator(); lEntityElementsIterator.hasNext();) {
064: Entity lEntityElement = (Entity) lEntityElementsIterator
065: .next();
066: String lEntityName = lEntityElement.getName();
067: if (lEntityName == null || lEntityName.length() == 0)
068: continue; // Entity does not have a name
069: // Attribute may need to be put to the key structure immediately
070: if (lEntityElement.getPrimaryKeyElements().contains(
071: pAttribute)) {
072: mModelAssistantImpl.mTargetEntityKeyStructureHelper
073: .primaryKeyAttribute_EnsurePresent(
074: lServicemodule, lEntityElement,
075: lAttributeName, pAttribute
076: .getDescription(), pAttribute
077: .getDataType());
078: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
079: .primaryKeyAttribute_EnsurePresent(
080: lServicemodule, lEntityElement,
081: lAttributeName, pAttribute
082: .getDataType());
083: } else {
084: mModelAssistantImpl.mTargetEntityKeyStructureHelper
085: .primaryKeyAttribute_EnsureAbsent(
086: lServicemodule, lEntityElement,
087: lAttributeName);
088: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
089: .primaryKeyAttribute_EnsureAbsent(
090: lServicemodule, lEntityElement,
091: lAttributeName);
092: }
093: }
094: }
095:
096: // Handle the deletion
097: void onDeleting(Attribute pAttribute) {
098: String lAttributeName = pAttribute.getName();
099: if (lAttributeName == null || lAttributeName.length() == 0)
100: return; // Attribute does not have a name
101: Entity lEntity = pAttribute.getEntity();
102: if (lEntity == null)
103: return; // Attribute is not associated with entity
104: Domain lDomain = lEntity.getDomain();
105: if (lDomain == null)
106: return; // Entity is not associated with domain
107: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = lDomain
108: .getSystem();
109: if (lSystem == null)
110: return; // Domain is not associated with system
111: String lDomainName = lDomain.getName();
112: if (lDomainName == null || lDomainName.length() == 0)
113: return; // Domain does not have a name yet
114: String lServicemoduleName = StylesheetImpl
115: .getDomainSupportServicemoduleName(lDomainName);
116: Servicemodule lServicemodule = lSystem
117: .findServicemodule(lServicemoduleName);
118: if (lServicemodule == null)
119: return; // There is no support servicemodule yet
120: // We will have to work on the entity and all subtypes
121: Set lAllEntitiesToConsider = new HashSet();
122: lAllEntitiesToConsider.add(lEntity);
123: lAllEntitiesToConsider.addAll(lEntity.getCombinedSubtypes());
124: for (Iterator lEntityElementsIterator = lAllEntitiesToConsider
125: .iterator(); lEntityElementsIterator.hasNext();) {
126: Entity lEntityElement = (Entity) lEntityElementsIterator
127: .next();
128: String lEntityName = lEntityElement.getName();
129: if (lEntityName == null || lEntityName.length() == 0)
130: continue; // Entity does not have a name
131: // Attribute is being deleted. Make sure it is not present in the key and details structures
132: mModelAssistantImpl.mTargetEntityKeyStructureHelper
133: .primaryKeyAttribute_EnsureAbsent(lServicemodule,
134: lEntityElement, lAttributeName);
135: mModelAssistantImpl.mTargetDuplicateCreateFailedMessageHelper
136: .primaryKeyAttribute_EnsureAbsent(lServicemodule,
137: lEntityElement, lAttributeName);
138: }
139: }
140: }
|