001: /*
002: * Copyright 2004-2006 the original author or authors.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.compass.core.engine.event;
018:
019: import java.util.ArrayList;
020:
021: import org.compass.core.engine.SearchEngineException;
022:
023: /**
024: * @author kimchy
025: */
026: public class SearchEngineEventManager implements
027: SearchEngineLifecycleEventListener {
028:
029: private ArrayList<SearchEngineLifecycleEventListener> lifecycleListeners;
030:
031: public void registerLifecycleListener(
032: SearchEngineLifecycleEventListener lifecycleEventListener) {
033: if (lifecycleListeners == null) {
034: lifecycleListeners = new ArrayList<SearchEngineLifecycleEventListener>();
035: }
036: lifecycleListeners.add(lifecycleEventListener);
037: }
038:
039: public void removeLifecycleListener(
040: SearchEngineLifecycleEventListener lifecycleEventListener) {
041: if (lifecycleListeners == null) {
042: return;
043: }
044: lifecycleListeners.remove(lifecycleEventListener);
045: }
046:
047: public void beforeBeginTransaction() throws SearchEngineException {
048: if (lifecycleListeners == null) {
049: return;
050: }
051: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
052: lifecycleListener.beforeBeginTransaction();
053: }
054: }
055:
056: public void afterBeginTransaction() throws SearchEngineException {
057: if (lifecycleListeners == null) {
058: return;
059: }
060: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
061: lifecycleListener.afterBeginTransaction();
062: }
063: }
064:
065: public void afterPrepare() throws SearchEngineException {
066: if (lifecycleListeners == null) {
067: return;
068: }
069: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
070: lifecycleListener.afterPrepare();
071: }
072: }
073:
074: public void afterCommit(boolean onePhase)
075: throws SearchEngineException {
076: if (lifecycleListeners == null) {
077: return;
078: }
079: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
080: lifecycleListener.afterCommit(onePhase);
081: }
082: }
083:
084: public void afterRollback() throws SearchEngineException {
085: if (lifecycleListeners == null) {
086: return;
087: }
088: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
089: lifecycleListener.afterRollback();
090: }
091: }
092:
093: public void close() throws SearchEngineException {
094: if (lifecycleListeners == null) {
095: return;
096: }
097: for (SearchEngineLifecycleEventListener lifecycleListener : lifecycleListeners) {
098: lifecycleListener.close();
099: }
100: }
101: }
|