01: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
02: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
03: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
04: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
05: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
06: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
07: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
08: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
09: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
10: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
11: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
12: // POSSIBILITY OF SUCH DAMAGE.
13: //
14: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
15: package com.metaboss.sdlctools.models.modelassistant.metabossmodel.modelintegrity;
16:
17: import java.util.Collection;
18:
19: import javax.jmi.reflect.ConstraintViolationException;
20: import javax.jmi.reflect.RefObject;
21:
22: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.systemusagemodel.UsageSpecification;
23:
24: /** This class containse helper methods dealing with the Usage Specification attached to every system */
25: class TargetSystemUsageSpecificationHelper {
26: private ModelAssistantImpl mModelAssistantImpl;
27:
28: TargetSystemUsageSpecificationHelper(
29: ModelAssistantImpl pModelAssistantImpl) {
30: mModelAssistantImpl = pModelAssistantImpl;
31:
32: // Add domain lifecycle listener
33: mModelAssistantImpl
34: .addLifecycleListener(
35: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System.class,
36: new ModelAssistantImpl.ModelElementLifecycleListener() {
37: public void onElementJustCreated(
38: RefObject pModelElementJustCreated) {
39: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System lSystem = (com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System) pModelElementJustCreated;
40: ensurePresent(lSystem);
41: }
42:
43: public void onElementBeingDeleted(
44: RefObject pModelElementBeingDeleted) {
45: // The Usage Specification is owned by the System and will be deleted automatically
46: }
47: });
48: }
49:
50: // This helper verifies constraints which are dealing with entity structures
51: void verifyConstraints(
52: Collection pViolations,
53: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem) {
54: UsageSpecification lUsageSpecification = pSystem
55: .getUsageSpecification();
56: if (lUsageSpecification == null)
57: pViolations.add(new ConstraintViolationException(pSystem,
58: pSystem.refMetaObject(),
59: "A System must have UsageSpecification."));
60: }
61:
62: // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
63: void rectifyModel(
64: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem) {
65: // Just call ensurePresent
66: ensurePresent(pSystem);
67: }
68:
69: // This helper makes sure that the version id attribute is present in the details structure
70: void ensurePresent(
71: com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.System pSystem) {
72: UsageSpecification lUsageSpecification = pSystem
73: .getUsageSpecification();
74: if (lUsageSpecification == null) {
75: lUsageSpecification = mModelAssistantImpl.mUsageSpecificationClass
76: .createUsageSpecification();
77: lUsageSpecification.setSystem(pSystem);
78: }
79: lUsageSpecification.setName("Default");
80: lUsageSpecification
81: .setDescription("Describes the ways the '"
82: + pSystem.getName()
83: + "' system is intended to be used");
84: }
85: }
|