001    /*
002     * Licensed to the Apache Software Foundation (ASF) under one
003     * or more contributor license agreements.  See the NOTICE file
004     * distributed with this work for additional information
005     * regarding copyright ownership.  The ASF licenses this file
006     * to you under the Apache License, Version 2.0 (the
007     * "License"); you may not use this file except in compliance
008     * with the License.  You may obtain a copy of the License at
009     *
010     *  http://www.apache.org/licenses/LICENSE-2.0
011     *
012     * Unless required by applicable law or agreed to in writing,
013     * software distributed under the License is distributed on an
014     * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     * KIND, either express or implied.  See the License for the
016     * specific language governing permissions and limitations
017     * under the License.
018     */
019    
020    package org.apache.xbean.osgi.bundle.util;
021    
022    import java.io.File;
023    import java.io.InputStream;
024    import java.util.Dictionary;
025    import java.util.Collection;
026    
027    import org.osgi.framework.Bundle;
028    import org.osgi.framework.BundleContext;
029    import org.osgi.framework.BundleException;
030    import org.osgi.framework.BundleListener;
031    import org.osgi.framework.Filter;
032    import org.osgi.framework.FrameworkListener;
033    import org.osgi.framework.InvalidSyntaxException;
034    import org.osgi.framework.ServiceListener;
035    import org.osgi.framework.ServiceReference;
036    import org.osgi.framework.ServiceRegistration;
037    
038    /**
039     * BundleContext for DelegatingBundle. 
040     * 
041     * @version $Rev: 937957 $ $Date: 2010-04-26 10:00:08 +0200 (lun. 26 avril 2010) $
042     */
043    public class DelegatingBundleContext implements BundleContext {
044    
045        private DelegatingBundle bundle;
046        private BundleContext bundleContext;
047        
048        public DelegatingBundleContext(DelegatingBundle bundle, BundleContext bundleContext) {
049            this.bundle = bundle;
050            this.bundleContext = bundleContext;
051        }
052        
053        public Bundle getBundle() {
054            return bundle;
055        }
056            
057        public void addBundleListener(BundleListener arg0) {
058            bundleContext.addBundleListener(arg0);
059        }
060    
061        public void addFrameworkListener(FrameworkListener arg0) {
062            bundleContext.addFrameworkListener(arg0);
063        }
064    
065        public void addServiceListener(ServiceListener arg0, String arg1) throws InvalidSyntaxException {
066            bundleContext.addServiceListener(arg0, arg1);
067        }
068    
069        public void addServiceListener(ServiceListener arg0) {
070            bundleContext.addServiceListener(arg0);
071        }
072    
073        public Filter createFilter(String arg0) throws InvalidSyntaxException {
074            return bundleContext.createFilter(arg0);
075        }
076    
077        public ServiceReference[] getAllServiceReferences(String arg0, String arg1)
078                throws InvalidSyntaxException {
079            return bundleContext.getAllServiceReferences(arg0, arg1);
080        }
081    
082        public Bundle getBundle(long arg0) {
083            return bundleContext.getBundle(arg0);
084        }
085    
086        public Bundle[] getBundles() {
087            return bundleContext.getBundles();
088        }
089    
090        public File getDataFile(String arg0) {
091            return bundleContext.getDataFile(arg0);
092        }
093    
094        public String getProperty(String arg0) {
095            return bundleContext.getProperty(arg0);
096        }
097    
098        public Object getService(ServiceReference arg0) {
099            return bundleContext.getService(arg0);
100        }
101    
102        public ServiceReference getServiceReference(String arg0) {
103            return bundleContext.getServiceReference(arg0);
104        }
105    
106        public ServiceReference[] getServiceReferences(String arg0, String arg1)
107                throws InvalidSyntaxException {
108            return bundleContext.getServiceReferences(arg0, arg1);
109        }
110    
111        public Bundle installBundle(String arg0, InputStream arg1) throws BundleException {
112            return bundleContext.installBundle(arg0, arg1);
113        }
114    
115        public Bundle installBundle(String arg0) throws BundleException {
116            return bundleContext.installBundle(arg0);
117        }
118    
119        public ServiceRegistration registerService(String arg0, Object arg1, Dictionary arg2) {
120            return bundleContext.registerService(arg0, arg1, arg2);
121        }
122    
123        public ServiceRegistration registerService(String[] arg0, Object arg1, Dictionary arg2) {
124            return bundleContext.registerService(arg0, arg1, arg2);
125        }
126    
127        public void removeBundleListener(BundleListener arg0) {
128            bundleContext.removeBundleListener(arg0);
129        }
130    
131        public void removeFrameworkListener(FrameworkListener arg0) {
132            bundleContext.removeFrameworkListener(arg0);
133        }
134    
135        public void removeServiceListener(ServiceListener arg0) {
136            bundleContext.removeServiceListener(arg0);
137        }
138    
139        public boolean ungetService(ServiceReference arg0) {
140            return bundleContext.ungetService(arg0);
141        }
142        
143        // OSGI 4.3
144        public <S> ServiceRegistration<S> registerService(Class<S> clazz,
145                                               S service,
146                                               Dictionary<String,?> properties) {
147            return bundleContext.registerService(clazz, service, properties);
148        }
149        
150        // OSGI 4.3
151        public <S> ServiceReference<S> getServiceReference(Class<S> clazz) {
152            return bundleContext.getServiceReference(clazz);
153        }
154        
155        // OSGI 4.3
156        public <S> Collection<ServiceReference<S>> getServiceReferences(Class<S> clazz,
157                                                                       String filter)
158                                                                   throws InvalidSyntaxException {
159            return bundleContext.getServiceReferences(clazz, filter);
160        }
161        
162        // OSGI 4.3
163        public Bundle getBundle(String location) {
164            return bundleContext.getBundle(location);
165        }
166    
167    }