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.impl.metabossmodel.enterprisemodel;
16:
17: import java.util.Collection;
18: import java.util.HashSet;
19: import java.util.Iterator;
20: import java.util.Set;
21:
22: import org.netbeans.mdr.storagemodel.StorableObject;
23:
24: import com.metaboss.sdlctools.models.impl.metabossmodel.ModelElementImpl;
25: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.Event;
26: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscription;
27: import com.metaboss.sdlctools.models.metabossmodel.enterprisemodel.EventSubscriptionOperation;
28:
29: public abstract class EventSubscriptionImpl extends ModelElementImpl
30: implements EventSubscription {
31: // Required constructor
32: protected EventSubscriptionImpl(StorableObject storable) {
33: super (storable);
34: }
35:
36: /**
37: * @param pEventName
38: * @return requested Event or throws exception if none found
39: */
40: public Event getEvent(String pEventName) {
41: Event lFoundEvent = findEvent(pEventName);
42: // Throw exception if nothing found
43: if (lFoundEvent == null)
44: throw new IllegalArgumentException(
45: "Unable to locate Event named '"
46: + pEventName
47: + "' in EventSusbscription. EventSusbscriptionRef: "
48: + getRef());
49: return lFoundEvent;
50: }
51:
52: /**
53: * @param pEventName
54: * @return requested Event or null if none found
55: */
56: public Event findEvent(String pEventName) {
57: Collection lEvents = getEvents();
58: if (!lEvents.isEmpty()) {
59: for (Iterator lEventsIterator = lEvents.iterator(); lEventsIterator
60: .hasNext();) {
61: Event lEvent = (Event) lEventsIterator.next();
62: if (lEvent.getName().equals(pEventName))
63: return lEvent;
64: }
65: }
66: return null;
67: }
68:
69: /** @return All combined structures and types used in this structure */
70: public Collection getCombinedTypes() {
71: Set lCombinedTypes = new HashSet();
72: EventSubscriptionOperation lSubscriptionOperation = getSubscriptionOperation();
73: // First work on subsription operation
74: if (lSubscriptionOperation != null)
75: lCombinedTypes.addAll(lSubscriptionOperation
76: .getCombinedTypes());
77: // Now work on events
78: Collection lEvents = getEvents();
79: if (!lEvents.isEmpty()) {
80: for (Iterator lEventsIterator = lEvents.iterator(); lEventsIterator
81: .hasNext();) {
82: Event lEvent = (Event) lEventsIterator.next();
83: lCombinedTypes.addAll(lEvent.getCombinedTypes());
84: }
85: }
86: return java.util.Collections
87: .unmodifiableCollection(lCombinedTypes);
88: }
89: }
|