01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.servicemix.components.util;
18:
19: import javax.jbi.JBIException;
20: import javax.jbi.component.ComponentContext;
21: import javax.jbi.component.ComponentLifeCycle;
22: import javax.management.ObjectName;
23: import javax.xml.namespace.QName;
24:
25: import org.springframework.beans.factory.DisposableBean;
26:
27: /**
28: * Adapts a POJO to a {@link ComponentLifeCycle} without performing any activation
29: *
30: * @version $Revision: 564374 $
31: */
32: public class PojoLifecycleAdaptor implements ComponentLifeCycle {
33:
34: private Object pojo;
35: private QName service;
36: private String endpoint;
37: private ComponentContext context;
38: private ObjectName extensionMBeanName;
39:
40: public PojoLifecycleAdaptor(Object pojo, QName service,
41: String endpoint) {
42: this .pojo = pojo;
43: this .service = service;
44: this .endpoint = endpoint;
45: }
46:
47: public ObjectName getExtensionMBeanName() {
48: return extensionMBeanName;
49: }
50:
51: public void init(ComponentContext ctx) throws JBIException {
52: this .context = ctx;
53: if (service != null && endpoint != null) {
54: ctx.activateEndpoint(service, endpoint);
55: }
56: }
57:
58: public void shutDown() throws JBIException {
59: if (pojo instanceof DisposableBean) {
60: DisposableBean disposableBean = (DisposableBean) pojo;
61: try {
62: disposableBean.destroy();
63: } catch (Exception e) {
64: throw new JBIException(e);
65: }
66: }
67: }
68:
69: public void start() throws JBIException {
70: }
71:
72: public void stop() throws JBIException {
73: }
74:
75: // Properties
76: //-------------------------------------------------------------------------
77: public Object getPojo() {
78: return pojo;
79: }
80:
81: public void setExtensionMBeanName(ObjectName extensionMBeanName) {
82: this .extensionMBeanName = extensionMBeanName;
83: }
84:
85: public ComponentContext getContext() {
86: return context;
87: }
88: }
|