001: package org.drools.event;
002:
003: /*
004: * Copyright 2005 JBoss Inc
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: */
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.Collections;
022: import java.util.List;
023:
024: import org.drools.WorkingMemory;
025: import org.drools.common.InternalWorkingMemory;
026: import org.drools.ruleflow.instance.RuleFlowProcessInstance;
027: import org.drools.spi.RuleFlowGroup;
028:
029: /**
030: * @author <a href="mailto:kris_verlaenen@hotmail.com">Kris Verlaenen</a>
031: */
032: public class RuleFlowEventSupport implements Serializable {
033:
034: private static final long serialVersionUID = 400L;
035: private final List listeners = Collections
036: .synchronizedList(new ArrayList());
037:
038: public RuleFlowEventSupport() {
039: }
040:
041: public void addEventListener(final RuleFlowEventListener listener) {
042: if (!this .listeners.contains(listener)) {
043: this .listeners.add(listener);
044: }
045: }
046:
047: public void removeEventListener(final RuleFlowEventListener listener) {
048: this .listeners.remove(listener);
049: }
050:
051: public List getEventListeners() {
052: return Collections.unmodifiableList(this .listeners);
053: }
054:
055: public int size() {
056: return this .listeners.size();
057: }
058:
059: public boolean isEmpty() {
060: return this .listeners.isEmpty();
061: }
062:
063: public void fireRuleFlowProcessStarted(
064: final RuleFlowProcessInstance instance,
065: final InternalWorkingMemory workingMemory) {
066: if (this .listeners.isEmpty()) {
067: return;
068: }
069:
070: final RuleFlowStartedEvent event = new RuleFlowStartedEvent(
071: instance);
072:
073: for (int i = 0, size = this .listeners.size(); i < size; i++) {
074: ((RuleFlowEventListener) this .listeners.get(i))
075: .ruleFlowStarted(event, workingMemory);
076: }
077: }
078:
079: public void fireRuleFlowProcessCompleted(
080: final RuleFlowProcessInstance instance,
081: final InternalWorkingMemory workingMemory) {
082: if (this .listeners.isEmpty()) {
083: return;
084: }
085:
086: final RuleFlowCompletedEvent event = new RuleFlowCompletedEvent(
087: instance);
088:
089: for (int i = 0, size = this .listeners.size(); i < size; i++) {
090: ((RuleFlowEventListener) this .listeners.get(i))
091: .ruleFlowCompleted(event, workingMemory);
092: }
093: }
094:
095: public void fireRuleFlowGroupActivated(
096: final RuleFlowGroup ruleFlowGroup,
097: final InternalWorkingMemory workingMemory) {
098: if (this .listeners.isEmpty()) {
099: return;
100: }
101:
102: final RuleFlowGroupActivatedEvent event = new RuleFlowGroupActivatedEvent(
103: ruleFlowGroup);
104:
105: for (int i = 0, size = this .listeners.size(); i < size; i++) {
106: ((RuleFlowEventListener) this .listeners.get(i))
107: .ruleFlowGroupActivated(event, workingMemory);
108: }
109: }
110:
111: public void fireRuleFlowGroupDeactivated(
112: final RuleFlowGroup ruleFlowGroup,
113: final InternalWorkingMemory workingMemory) {
114: if (this .listeners.isEmpty()) {
115: return;
116: }
117:
118: final RuleFlowGroupDeactivatedEvent event = new RuleFlowGroupDeactivatedEvent(
119: ruleFlowGroup);
120:
121: for (int i = 0, size = this .listeners.size(); i < size; i++) {
122: ((RuleFlowEventListener) this.listeners.get(i))
123: .ruleFlowGroupDeactivated(event, workingMemory);
124: }
125: }
126:
127: }
|