001 /*
002 * Licensed to the Apache Software Foundation (ASF) under one or more
003 * contributor license agreements. See the NOTICE file distributed with
004 * this work for additional information regarding copyright ownership.
005 * The ASF licenses this file to You under the Apache License, Version 2.0
006 * (the "License"); you may not use this file except in compliance with
007 * the License. You may obtain a copy of the License at
008 *
009 * http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017 package org.apache.camel.component.jbi;
018
019 import javax.jbi.component.ComponentContext;
020 import javax.jbi.messaging.MessageExchange.Role;
021 import javax.xml.namespace.QName;
022 import org.apache.servicemix.common.ExchangeProcessor;
023 import org.apache.servicemix.jbi.container.JBIContainer;
024 import org.apache.servicemix.jbi.framework.ComponentContextImpl;
025
026 /**
027 * The endpoint in the service engine
028 * @version $Revision: 426415 $
029 */
030 public class CamelServiceEngineEndpoint extends org.apache.servicemix.common.Endpoint {
031
032 private static final QName SERVICE_NAME = new QName("http://camel.servicemix.org", "CamelEndpointComponent");
033
034 private CamelEndpointComponent camelEndpointComponent;
035
036 public CamelServiceEngineEndpoint(JbiEndpoint jbiEndpoint) {
037 this.camelEndpointComponent = new CamelEndpointComponent(jbiEndpoint);
038 this.service = SERVICE_NAME;
039 this.endpoint=jbiEndpoint.getEndpointUri();
040 }
041
042 public Role getRole() {
043 throw new UnsupportedOperationException();
044 }
045
046 public void activate() throws Exception {
047 getContainer().activateComponent(camelEndpointComponent,camelEndpointComponent.getName());
048 }
049
050 public void deactivate() throws Exception {
051 getContainer().deactivateComponent(camelEndpointComponent.getName());
052 }
053
054 public ExchangeProcessor getProcessor() {
055 throw new UnsupportedOperationException();
056 }
057
058 public JBIContainer getContainer() {
059 ComponentContext context = getServiceUnit().getComponent().getComponentContext();
060 if( context instanceof ComponentContextImpl ) {
061 return ((ComponentContextImpl) context).getContainer();
062 }
063 throw new IllegalStateException("LwContainer component can only be deployed in ServiceMix");
064 }
065
066 }