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.EventSubscription;
23: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
24:
25: /** This class containse helper methods dealing with the Event Subsription Operation attached to every Event Subscription */
26: class TargetEventSubscriptionOperationHelper {
27: private ModelAssistantImpl mModelAssistantImpl;
28:
29: TargetEventSubscriptionOperationHelper(
30: ModelAssistantImpl pModelAssistantImpl) {
31: mModelAssistantImpl = pModelAssistantImpl;
32:
33: // Add domain lifecycle listener
34: mModelAssistantImpl.addLifecycleListener(
35: EventSubscription.class,
36: new ModelAssistantImpl.ModelElementLifecycleListener() {
37: public void onElementJustCreated(
38: RefObject pModelElementJustCreated) {
39: EventSubscription lEventSubscription = (EventSubscription) pModelElementJustCreated;
40: ensurePresent(lEventSubscription);
41: }
42:
43: public void onElementBeingDeleted(
44: RefObject pModelElementBeingDeleted) {
45: // The Event Subsription Operation is owned by the Event Subsription and will be deleted automatically
46: }
47: });
48: }
49:
50: // This helper verifies constraints which are dealing with entity structures
51: void verifyConstraints(Collection pViolations,
52: EventSubscription pEventSubscription) {
53: EventSubscriptionOperation lEventSubscriptionOperation = pEventSubscription
54: .getSubscriptionOperation();
55: if (lEventSubscriptionOperation == null)
56: pViolations
57: .add(new ConstraintViolationException(
58: pEventSubscription, pEventSubscription
59: .refMetaObject(),
60: "An EventSubscription must have EventSubscriptionOperation defined."));
61: }
62:
63: // This helper is doing everything necessary to rectify errors reported in verifyConstraints()
64: void rectifyModel(EventSubscription pEventSubscription) {
65: // Just call ensurePresent
66: ensurePresent(pEventSubscription);
67: }
68:
69: // This helper makes sure that the version id attribute is present in the details structure
70: void ensurePresent(EventSubscription pEventSubscription) {
71: EventSubscriptionOperation lEventSubscriptionOperation = pEventSubscription
72: .getSubscriptionOperation();
73: if (lEventSubscriptionOperation == null) {
74: lEventSubscriptionOperation = mModelAssistantImpl.mEventSubscriptionOperationClass
75: .createEventSubscriptionOperation();
76: lEventSubscriptionOperation
77: .setSubscription(pEventSubscription);
78: }
79: lEventSubscriptionOperation.setName("Default");
80: lEventSubscriptionOperation
81: .setDescription("Activates the '"
82: + pEventSubscription.getName()
83: + "' event subscription");
84: }
85: }
|