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.servicemix.common;
018    
019    import java.util.MissingResourceException;
020    import java.util.logging.Logger;
021    
022    import javax.jbi.JBIException;
023    import javax.jbi.component.ComponentContext;
024    import javax.jbi.management.MBeanNames;
025    import javax.jbi.messaging.DeliveryChannel;
026    import javax.jbi.messaging.MessagingException;
027    import javax.jbi.servicedesc.ServiceEndpoint;
028    import javax.management.MBeanServer;
029    import javax.naming.InitialContext;
030    import javax.xml.namespace.QName;
031    
032    import org.w3c.dom.Document;
033    import org.w3c.dom.DocumentFragment;
034    
035    public class EndpointComponentContext implements ComponentContext {
036    
037        private Endpoint endpoint;
038        private ComponentContext context;
039        private DeliveryChannel channel;
040        
041        public EndpointComponentContext(Endpoint endpoint) {
042            this.endpoint = endpoint;
043            this.context = endpoint.getServiceUnit().getComponent().getComponentContext();
044        }
045    
046        public EndpointComponentContext(ComponentContext context) {
047            this.context = context;
048        }
049    
050        public Endpoint getEndpoint() {
051            return endpoint;
052        }
053        
054        public ComponentContext getComponentContext() {
055            return context;
056        }
057    
058        public ServiceEndpoint activateEndpoint(QName serviceName, String endpointName) throws JBIException {
059            throw new UnsupportedOperationException();
060        }
061    
062        public void deactivateEndpoint(ServiceEndpoint endpoint) throws JBIException {
063            throw new UnsupportedOperationException();
064        }
065    
066        public void deregisterExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
067            throw new UnsupportedOperationException();
068        }
069    
070        public String getComponentName() {
071            return context.getComponentName();
072        }
073    
074        public DeliveryChannel getDeliveryChannel() throws MessagingException {
075            if (this.channel == null) {
076                if (endpoint != null) {
077                    this.channel = new EndpointDeliveryChannel(endpoint);
078                } else {
079                    this.channel = new EndpointDeliveryChannel(context);
080                }
081            }
082            return this.channel;
083        }
084    
085        public ServiceEndpoint getEndpoint(QName service, String name) {
086            return context.getEndpoint(service, name);
087        }
088    
089        public Document getEndpointDescriptor(ServiceEndpoint endpoint) throws JBIException {
090            return context.getEndpointDescriptor(endpoint);
091        }
092    
093        public ServiceEndpoint[] getEndpoints(QName interfaceName) {
094            return context.getEndpoints(interfaceName);
095        }
096    
097        public ServiceEndpoint[] getEndpointsForService(QName serviceName) {
098            return context.getEndpointsForService(serviceName);
099        }
100    
101        public ServiceEndpoint[] getExternalEndpoints(QName interfaceName) {
102            return context.getExternalEndpoints(interfaceName);
103        }
104    
105        public ServiceEndpoint[] getExternalEndpointsForService(QName serviceName) {
106            return context.getExternalEndpointsForService(serviceName);
107        }
108    
109        public String getInstallRoot() {
110            return context.getInstallRoot();
111        }
112    
113        public Logger getLogger(String suffix, String resourceBundleName) throws MissingResourceException, JBIException {
114            return context.getLogger(suffix, resourceBundleName);
115        }
116    
117        public MBeanNames getMBeanNames() {
118            return context.getMBeanNames();
119        }
120    
121        public MBeanServer getMBeanServer() {
122            return context.getMBeanServer();
123        }
124    
125        public InitialContext getNamingContext() {
126            return context.getNamingContext();
127        }
128    
129        public Object getTransactionManager() {
130            return context.getTransactionManager();
131        }
132    
133        public String getWorkspaceRoot() {
134            return context.getWorkspaceRoot();
135        }
136    
137        public void registerExternalEndpoint(ServiceEndpoint externalEndpoint) throws JBIException {
138            throw new UnsupportedOperationException();
139        }
140    
141        public ServiceEndpoint resolveEndpointReference(DocumentFragment epr) {
142            return context.resolveEndpointReference(epr);
143        }
144        
145    }