01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */package org.apache.cxf.buslifecycle;
19:
20: import java.util.ArrayList;
21: import java.util.List;
22:
23: import javax.annotation.PostConstruct;
24: import javax.annotation.Resource;
25:
26: import org.apache.cxf.Bus;
27:
28: public class CXFBusLifeCycleManager implements BusLifeCycleManager {
29:
30: private final List<BusLifeCycleListener> listeners;
31: private Bus bus;
32:
33: public CXFBusLifeCycleManager() {
34: listeners = new ArrayList<BusLifeCycleListener>();
35: }
36:
37: @Resource
38: public void setBus(Bus b) {
39: bus = b;
40: }
41:
42: @PostConstruct
43: public void register() {
44: if (null != bus) {
45: bus.setExtension(this , BusLifeCycleManager.class);
46: }
47: }
48:
49: /* (non-Javadoc)
50: * @see org.apache.cxf.buslifecycle.BusLifeCycleManager#registerLifeCycleListener(
51: * org.apache.cxf.buslifecycle.BusLifeCycleListener)
52: */
53: public void registerLifeCycleListener(BusLifeCycleListener listener) {
54: listeners.add(listener);
55:
56: }
57:
58: /* (non-Javadoc)
59: * @see org.apache.cxf.buslifecycle.BusLifeCycleManager#unregisterLifeCycleListener(
60: * org.apache.cxf.buslifecycle.BusLifeCycleListener)
61: */
62: public void unregisterLifeCycleListener(
63: BusLifeCycleListener listener) {
64: listeners.remove(listener);
65: }
66:
67: public void initComplete() {
68: for (BusLifeCycleListener listener : listeners) {
69: listener.initComplete();
70: }
71: }
72:
73: public void preShutdown() {
74: // TODO inverse order of registration?
75: for (BusLifeCycleListener listener : listeners) {
76: listener.preShutdown();
77: }
78: }
79:
80: public void postShutdown() {
81: // TODO inverse order of registration?
82: for (BusLifeCycleListener listener : listeners) {
83: listener.postShutdown();
84: }
85: }
86:
87: }
|