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.implicitselectors;
016:
017: import java.util.ArrayList;
018: import java.util.Collection;
019: import java.util.Collections;
020: import java.util.Iterator;
021: import java.util.List;
022:
023: import javax.jmi.reflect.ConstraintViolationException;
024: import javax.naming.Context;
025: import javax.naming.InitialContext;
026: import javax.naming.NamingException;
027:
028: import com.metaboss.sdlctools.models.ModelRepository;
029: import com.metaboss.sdlctools.models.ModelRepositoryException;
030: import com.metaboss.sdlctools.models.ModelRepositoryInternalException;
031: import com.metaboss.sdlctools.models.metabossmodel.MetaBossModelPackage;
032: import com.metaboss.sdlctools.models.metabossmodel.ModelElementClass;
033: import com.metaboss.sdlctools.models.metabossmodel.datadictionarymodel.DataDictionaryModelPackage;
034: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Entity;
035: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.EntityClass;
036: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.Selector;
037: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorClass;
038: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SelectorInputFieldClass;
039: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemimplementationmodel.SystemImplementationModelPackage;
040: import com.metaboss.sdlctools.models.modelassistant.metabossmodel.SingleModelAssistantImplBase;
041:
042: /** Implementation of the assistant to MetaBoss models.
043: * Looks after some implicit data types in the systems.
044: * This implementation is always only serving one model. This is guaranteed
045: * by special factory implementation */
046: public class ModelAssistantImpl extends SingleModelAssistantImplBase {
047: /** String constant which is used to identify this assistant as an owner of certain model elements */
048: public static final String ASSISTANT_IDENTIFIER = ModelAssistantImpl.class
049: .getPackage().getName();
050:
051: // Variables below are cached for whole session with the model regardless of the kind of model it is
052: ModelRepository mModelRepository = null;
053: MetaBossModelPackage mRootPackage = null;
054: ModelElementClass mModelElementClass = null;
055: SystemImplementationModelPackage mSystemImplementationModelPackage = null;
056: EntityClass mEntityClass = null;
057: SelectorClass mSelectorClass = null;
058: SelectorInputFieldClass mSelectorInputFieldClass = null;
059: DataDictionaryModelPackage mDataDictionaryModel = null;
060:
061: TargetEntityStateSelectorHelper mTargetEntityStateSelectorHelper = null;
062: TargetEnumerableAttributeSelectorHelper mTargetEnumerableAttributeSelectorHelper = null;
063:
064: public ModelAssistantImpl() {
065: mTargetEntityStateSelectorHelper = new TargetEntityStateSelectorHelper(
066: this );
067: mTargetEnumerableAttributeSelectorHelper = new TargetEnumerableAttributeSelectorHelper(
068: this );
069: }
070:
071: // As per interface
072: public void assignToModel(String pModelName)
073: throws ModelRepositoryException {
074: super .assignToModel(pModelName);
075: try {
076: Context lContext = new InitialContext();
077: mModelRepository = (ModelRepository) lContext
078: .lookup(ModelRepository.COMPONENT_URL);
079: mRootPackage = (MetaBossModelPackage) mModelRepository
080: .getModelExtent(pModelName);
081: mModelElementClass = mRootPackage.getModelElement();
082: mSystemImplementationModelPackage = mRootPackage
083: .getEnterpriseModel()
084: .getSystemImplementationModel();
085: mEntityClass = mSystemImplementationModelPackage
086: .getEntity();
087: mSelectorClass = mSystemImplementationModelPackage
088: .getSelector();
089: mSelectorInputFieldClass = mSystemImplementationModelPackage
090: .getSelectorInputField();
091: mDataDictionaryModel = mRootPackage
092: .getDataDictionaryModel();
093:
094: } catch (NamingException e) {
095: throw new ModelRepositoryInternalException(
096: "Unable to lookup repository", e);
097: }
098: }
099:
100: // As per interface
101: public void dismissFromModel(String pModelName) {
102: mRootPackage = null;
103: mModelRepository = null;
104: mModelElementClass = null;
105: mSystemImplementationModelPackage = null;
106: mEntityClass = null;
107: mSelectorClass = null;
108: mSelectorInputFieldClass = null;
109: mDataDictionaryModel = null;
110: super .dismissFromModel(pModelName);
111: }
112:
113: // As per interface
114: public void rectifyModel(String pModelName)
115: throws ModelRepositoryException {
116: // Ensure that every entity has all necessary selectors
117: for (Iterator lEntitiesIterator = mEntityClass.refAllOfType()
118: .iterator(); lEntitiesIterator.hasNext();) {
119: Entity lEntity = (Entity) lEntitiesIterator.next();
120: HelperContext lHelperContext = new HelperContext(lEntity);
121: // Collect all selectors with the view of deleting the ones we do not need
122: List lUnclaimedSelectors = new ArrayList(lEntity
123: .getSelectors());
124: mTargetEntityStateSelectorHelper.rectifyModel(lEntity,
125: lUnclaimedSelectors);
126: mTargetEnumerableAttributeSelectorHelper.rectifyModel(
127: lEntity, lUnclaimedSelectors);
128: for (Iterator lUnclaimedSelectorsIterator = lUnclaimedSelectors
129: .iterator(); lUnclaimedSelectorsIterator.hasNext();) {
130: Selector lSelector = (Selector) lUnclaimedSelectorsIterator
131: .next();
132: if (lSelector.isDerived()
133: && lSelector.getOwnerIdentifier().equals(
134: ASSISTANT_IDENTIFIER))
135: lSelector.refDelete();
136: }
137: }
138: }
139:
140: // As per interface
141: public Collection verifyConstraints(String pModelName) {
142: List lViolations = new ArrayList();
143: // Ensure that every entity has all necessary selectors
144: for (Iterator lEntitiesIterator = mEntityClass.refAllOfType()
145: .iterator(); lEntitiesIterator.hasNext();) {
146: Entity lEntity = (Entity) lEntitiesIterator.next();
147: HelperContext lHelperContext = new HelperContext(lEntity);
148: // Collect all selectors with the view of deleting the ones we do not need
149: List lUnclaimedSelectors = new ArrayList(lEntity
150: .getSelectors());
151: // Verify integrity
152: mTargetEntityStateSelectorHelper.verifyConstraints(
153: lViolations, lEntity, lUnclaimedSelectors);
154: mTargetEnumerableAttributeSelectorHelper.verifyConstraints(
155: lViolations, lEntity, lUnclaimedSelectors);
156: // Report unprocessed selectors
157: for (Iterator lUnclaimedSelectorsIterator = lUnclaimedSelectors
158: .iterator(); lUnclaimedSelectorsIterator.hasNext();) {
159: Selector lSelector = (Selector) lUnclaimedSelectorsIterator
160: .next();
161: if (lSelector.isDerived()
162: && lSelector.getOwnerIdentifier().equals(
163: ASSISTANT_IDENTIFIER))
164: lViolations
165: .add(new ConstraintViolationException(
166: lSelector,
167: lSelector.refMetaObject(),
168: "Implicit selector must be associated with Entity State or Enumerable Attribute. Selector '"
169: + lSelector.getName()
170: + "' appears to have no reason to exist."));
171: }
172: }
173: // Return what we have
174: return Collections.unmodifiableCollection(lViolations);
175: }
176: }
|