KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > lwcontainer > LwContainerEndpoint


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.lwcontainer;
18
19 import javax.jbi.component.ComponentContext;
20 import javax.jbi.messaging.MessageExchange.Role;
21 import javax.xml.namespace.QName JavaDoc;
22
23 import org.apache.activemq.util.IdGenerator;
24 import org.apache.servicemix.common.Endpoint;
25 import org.apache.servicemix.common.ExchangeProcessor;
26 import org.apache.servicemix.jbi.container.ActivationSpec;
27 import org.apache.servicemix.jbi.container.JBIContainer;
28 import org.apache.servicemix.jbi.framework.ComponentContextImpl;
29
30 public class LwContainerEndpoint extends Endpoint {
31
32     private static final QName JavaDoc SERVICE_NAME = new QName JavaDoc("http://lwcontainer.servicemix.org", "LwContainerComponent");
33     
34     private ActivationSpec activationSpec;
35     
36     public LwContainerEndpoint(ActivationSpec activationSpec) {
37         this.activationSpec = activationSpec;
38         this.service = SERVICE_NAME;
39         if (activationSpec.getId() != null) {
40             this.endpoint = activationSpec.getId();
41         } else if (activationSpec.getComponentName() != null) {
42             this.endpoint = activationSpec.getComponentName();
43         } else {
44             this.endpoint = new IdGenerator().generateId();
45         }
46     }
47     
48     public Role getRole() {
49         throw new UnsupportedOperationException JavaDoc();
50     }
51
52     public void activate() throws Exception JavaDoc {
53         getContainer().activateComponent(activationSpec);
54         
55     }
56
57     public void deactivate() throws Exception JavaDoc {
58         getContainer().deactivateComponent(activationSpec.getId());
59     }
60
61     public ExchangeProcessor getProcessor() {
62         throw new UnsupportedOperationException JavaDoc();
63     }
64
65     public JBIContainer getContainer() {
66         ComponentContext context = getServiceUnit().getComponent().getComponentContext();
67         if( context instanceof ComponentContextImpl ) {
68             return ((ComponentContextImpl) context).getContainer();
69         }
70         throw new IllegalStateException JavaDoc("LwContainer component can only be deployed in ServiceMix");
71     }
72
73 }
74
Popular Tags