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