KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > components > util > PojoLifecycleAdaptor


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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 org.springframework.beans.factory.DisposableBean;
20
21 import javax.jbi.JBIException;
22 import javax.jbi.component.ComponentContext;
23 import javax.jbi.component.ComponentLifeCycle;
24 import javax.management.ObjectName JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
26
27 /**
28  * Adapts a POJO to a {@link ComponentLifeCycle} without performing any activation
29  *
30  * @version $Revision: 426415 $
31  */

32 public class PojoLifecycleAdaptor implements ComponentLifeCycle {
33
34     private Object JavaDoc pojo;
35     private QName JavaDoc service;
36     private String JavaDoc endpoint;
37     private ComponentContext context;
38     private ObjectName JavaDoc extensionMBeanName;
39
40     public PojoLifecycleAdaptor(Object JavaDoc pojo, QName JavaDoc service, String JavaDoc endpoint) {
41         this.pojo = pojo;
42         this.service = service;
43         this.endpoint = endpoint;
44     }
45
46     public ObjectName JavaDoc getExtensionMBeanName() {
47         return extensionMBeanName;
48     }
49
50     public void init(ComponentContext context) throws JBIException {
51         this.context = context;
52         if (service != null && endpoint != null) {
53             context.activateEndpoint(service, endpoint);
54         }
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             }
64             catch (Exception JavaDoc e) {
65                 throw new JBIException(e);
66             }
67         }
68     }
69
70     public void start() throws JBIException {
71     }
72
73     public void stop() throws JBIException {
74     }
75
76     // Properties
77
//-------------------------------------------------------------------------
78
public Object JavaDoc getPojo() {
79         return pojo;
80     }
81
82     public void setExtensionMBeanName(ObjectName JavaDoc extensionMBeanName) {
83         this.extensionMBeanName = extensionMBeanName;
84     }
85
86     public ComponentContext getContext() {
87         return context;
88     }
89 }
90
Popular Tags