KickJava   Java API By Example, From Geeks To Geeks.

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


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.w3c.dom.Document JavaDoc;
20 import org.w3c.dom.DocumentFragment JavaDoc;
21
22 import javax.jbi.JBIException;
23 import javax.jbi.component.Component;
24 import javax.jbi.component.ComponentContext;
25 import javax.jbi.component.ComponentLifeCycle;
26 import javax.jbi.component.ServiceUnitManager;
27 import javax.jbi.messaging.MessageExchange;
28 import javax.jbi.servicedesc.ServiceEndpoint;
29 import javax.xml.namespace.QName JavaDoc;
30
31 /**
32  * A simple adaptor which can be used to turn any instance of
33  * a {@link ComponentLifeCycle} into a fully fledged JBI {@link Component}
34  *
35  * @version $Revision: 426415 $
36  */

37 public class ComponentAdaptor implements Component {
38
39     private ComponentLifeCycle lifeCycle;
40     private QName JavaDoc service;
41     private String JavaDoc endpoint;
42     private ComponentContext context;
43     private ServiceUnitManager serviceManager;
44
45
46     public ComponentAdaptor(ComponentLifeCycle lifeCycle) {
47         this.lifeCycle = lifeCycle;
48     }
49
50     public ComponentAdaptor(ComponentLifeCycle lifeCycle, QName JavaDoc service, String JavaDoc endpoint) {
51         this.lifeCycle = lifeCycle;
52         this.service = service;
53         this.endpoint = endpoint;
54     }
55
56     /**
57      * Called when the Component is initialized
58      *
59      * @param context
60      * @throws javax.jbi.JBIException
61      */

62     public void init(ComponentContext context) throws JBIException {
63         this.context = context;
64         if (service != null && endpoint != null) {
65             context.activateEndpoint(service, endpoint);
66         }
67     }
68
69     /**
70      * @return the lifecycel control implementation
71      */

72     public ComponentLifeCycle getLifeCycle() {
73         return lifeCycle;
74     }
75
76     public ServiceUnitManager getServiceUnitManager() {
77         initializeServiceUnitManager();
78         return serviceManager;
79     }
80
81     public void setServiceManager(ServiceUnitManager serviceManager) {
82         this.serviceManager = serviceManager;
83     }
84
85
86     public ComponentContext getContext() {
87         return context;
88     }
89
90     public String JavaDoc toString() {
91         return getClass().getName() + " for " + lifeCycle;
92     }
93
94     protected synchronized void initializeServiceUnitManager() {
95         if (this.serviceManager == null) {
96             this.serviceManager = createServiceUnitManager();
97         }
98     }
99
100     protected ServiceUnitManager createServiceUnitManager() {
101         return new ServiceUnitManagerSupport();
102     }
103
104
105     public Document JavaDoc getServiceDescription(ServiceEndpoint endpoint) {
106         // TODO Auto-generated method stub
107
return null;
108     }
109
110
111     public boolean isExchangeWithConsumerOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
112         // TODO Auto-generated method stub
113
return true;
114     }
115
116
117     public boolean isExchangeWithProviderOkay(ServiceEndpoint endpoint, MessageExchange exchange) {
118         // TODO Auto-generated method stub
119
return true;
120     }
121
122
123     public ServiceEndpoint resolveEndpointReference(DocumentFragment JavaDoc epr) {
124         // TODO Auto-generated method stub
125
return null;
126     }
127
128 }
129
Popular Tags