Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 21043 invoked from network); 2 Jan 2009 14:05:44 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 2 Jan 2009 14:05:44 -0000 Received: (qmail 8283 invoked by uid 500); 2 Jan 2009 14:05:43 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 8269 invoked by uid 500); 2 Jan 2009 14:05:43 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 8251 invoked by uid 99); 2 Jan 2009 14:05:43 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2009 06:05:43 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 02 Jan 2009 14:05:32 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id AEDF12388995; Fri, 2 Jan 2009 06:05:10 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r730721 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/impl/converter/ components/camel-osgi/ components/camel-osgi/src/main/java/org/apache/camel/osgi/ Date: Fri, 02 Jan 2009 14:05:09 -0000 To: camel-commits@activemq.apache.org From: ningjiang@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090102140510.AEDF12388995@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: ningjiang Date: Fri Jan 2 06:05:09 2009 New Revision: 730721 URL: http://svn.apache.org/viewvc?rev=730721&view=rev Log: CAMEL-1043 Using OSGI bundle activator to search the component and type converter Added: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java (with props) activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java (with props) activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java (with props) Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java activemq/camel/trunk/components/camel-osgi/pom.xml activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiComponentResolver.java Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java?rev=730721&r1=730720&r2=730721&view=diff ============================================================================== --- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java (original) +++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/impl/converter/AnnotationTypeConverterLoader.java Fri Jan 2 06:05:09 2009 @@ -50,7 +50,7 @@ public class AnnotationTypeConverterLoader implements TypeConverterLoader { public static final String META_INF_SERVICES = "META-INF/services/org/apache/camel/TypeConverter"; private static final transient Log LOG = LogFactory.getLog(AnnotationTypeConverterLoader.class); - private ResolverUtil resolver = new ResolverUtil(); + private ResolverUtil resolver; private Set visitedClasses = new HashSet(); public AnnotationTypeConverterLoader() { @@ -58,8 +58,14 @@ if (WebSphereResolverUtil.isWebSphereClassLoader(this.getClass().getClassLoader())) { LOG.info("Using WebSphere specific ResolverUtil"); resolver = new WebSphereResolverUtil(META_INF_SERVICES); + } else { + resolver = new ResolverUtil(); } } + + public AnnotationTypeConverterLoader(ResolverUtil resolverUtil) { + this.resolver = resolverUtil; + } public void load(TypeConverterRegistry registry) throws Exception { String[] packageNames = findPackageNames(); Modified: activemq/camel/trunk/components/camel-osgi/pom.xml URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/pom.xml?rev=730721&r1=730720&r2=730721&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-osgi/pom.xml (original) +++ activemq/camel/trunk/components/camel-osgi/pom.xml Fri Jan 2 06:05:09 2009 @@ -127,6 +127,21 @@ + + org.apache.felix + maven-bundle-plugin + + + ${pom.artifactId} + ${camel.osgi.export.pkg} + * + org.apache.camel.osgi.Activator + Apache Camel + ${project.version} + + true + + org.codehaus.mojo Added: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java?rev=730721&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java (added) +++ activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java Fri Jan 2 06:05:09 2009 @@ -0,0 +1,263 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.osgi; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Properties; +import java.util.Set; +import java.util.StringTokenizer; + +import org.apache.camel.util.ObjectHelper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleActivator; +import org.osgi.framework.BundleContext; +import org.osgi.framework.BundleEvent; +import org.osgi.framework.SynchronousBundleListener; +import org.springframework.osgi.util.BundleDelegatingClassLoader; + +public class Activator implements BundleActivator, SynchronousBundleListener { + public static final String META_INF_TYPE_CONVERTER = "META-INF/services/org/apache/camel/TypeConverter"; + public static final String META_INF_COMPONENT = "/META-INF/services/org/apache/camel/component/"; + private static final transient Log LOG = LogFactory.getLog(Activator.class); + private static final Map COMPONENTS = new HashMap(); + private static final Map TYPE_CONVERTERS = new HashMap(); + private static Bundle bundle; + + private class ComponentEntry { + Bundle bundle; + String path; + String name; + Class type; + } + + private class TypeConverterEntry { + Bundle bundle; + URL resource; + Set converterPackages; + } + + public void bundleChanged(BundleEvent event) { + try { + Bundle bundle = event.getBundle(); + if (event.getType() == BundleEvent.RESOLVED) { + if (LOG.isDebugEnabled()) { + LOG.debug("Bundle resolved: " + bundle.getSymbolicName()); + } + mayBeAddComponentFor(bundle); + mayBeAddTypeConverterFor(bundle); + } else if (event.getType() == BundleEvent.UNRESOLVED) { + if (LOG.isDebugEnabled()) { + LOG.debug("Bundle unresolved: " + bundle.getSymbolicName()); + } + mayBeRemoveComponentFor(bundle); + mayBeRemoveTypeConverterFor(bundle); + } + } catch (Throwable e) { + LOG.fatal("Exception handing bundle changed event", e); + } + + } + + protected synchronized void mayBeAddComponentFor(Bundle bundle) { + Enumeration e = bundle.getEntryPaths(META_INF_COMPONENT); + if (e != null) { + while (e.hasMoreElements()) { + String path = (String)e.nextElement(); + if (LOG.isDebugEnabled()) { + LOG.debug("Found entry: " + path + " in bundle " + bundle.getSymbolicName()); + } + ComponentEntry entry = new ComponentEntry(); + entry.bundle = bundle; + entry.path = path; + entry.name = path.substring(path.lastIndexOf("/") + 1); + COMPONENTS.put(entry.name, entry); + } + } + } + + protected synchronized void mayBeAddTypeConverterFor(Bundle bundle) { + try { + Enumeration e = bundle.getResources(META_INF_TYPE_CONVERTER); + if (e != null) { + while (e.hasMoreElements()) { + URL resource = (URL)e.nextElement(); + if (LOG.isDebugEnabled()) { + LOG.debug("Found entry: " + resource + " in bundle " + bundle.getSymbolicName()); + } + TypeConverterEntry entry = new TypeConverterEntry(); + entry.bundle = bundle; + entry.resource = resource; + entry.converterPackages = getConverterPackages(resource); + TYPE_CONVERTERS.put(bundle, entry); + } + } + } catch (IOException ignore) { + // can't find the resource + } + } + + protected synchronized void mayBeRemoveComponentFor(Bundle bundle) { + ComponentEntry[] entriesArray = COMPONENTS.values().toArray(new ComponentEntry[0]); + for (ComponentEntry entry : entriesArray) { + if (entry.bundle == bundle) { + if (LOG.isDebugEnabled()) { + LOG.debug("Removing entry: " + entry.path + " in bundle " + bundle.getSymbolicName()); + } + COMPONENTS.remove(entry.name); + } + } + } + + protected synchronized void mayBeRemoveTypeConverterFor(Bundle bundle) { + TypeConverterEntry[] entriesArray = TYPE_CONVERTERS.values().toArray(new TypeConverterEntry[0]); + for (TypeConverterEntry entry : entriesArray) { + if (entry.bundle == bundle) { + if (LOG.isDebugEnabled()) { + LOG.debug("Removing entry: " + entry.resource + " in bundle " + bundle.getSymbolicName()); + } + COMPONENTS.remove(bundle); + } + } + } + + public void start(BundleContext context) throws Exception { + bundle = context.getBundle(); + context.addBundleListener(this); + if (LOG.isDebugEnabled()) { + LOG.debug("checking existing bundles"); + } + for (Bundle bundle : context.getBundles()) { + if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING + || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { + mayBeAddComponentFor(bundle); + mayBeAddTypeConverterFor(bundle); + } + } + if (LOG.isDebugEnabled()) { + LOG.debug("actived"); + } + + } + + public void stop(BundleContext context) throws Exception { + if (LOG.isDebugEnabled()) { + LOG.debug("removing the components of existing bundles"); + } + for (Bundle bundle : context.getBundles()) { + if (bundle.getState() == Bundle.RESOLVED || bundle.getState() == Bundle.STARTING + || bundle.getState() == Bundle.ACTIVE || bundle.getState() == Bundle.STOPPING) { + mayBeRemoveComponentFor(bundle); + mayBeRemoveTypeConverterFor(bundle); + } + } + if (LOG.isDebugEnabled()) { + LOG.debug("stopped"); + } + } + + protected Set getConverterPackages(URL resource) { + Set packages = new HashSet(); + if (resource != null) { + BufferedReader reader = null; + try { + reader = new BufferedReader(new InputStreamReader(resource.openStream())); + while (true) { + String line = reader.readLine(); + if (line == null) { + break; + } + line = line.trim(); + if (line.startsWith("#") || line.length() == 0) { + continue; + } + tokenize(packages, line); + } + } catch (Exception ignore) { + // Do nothing here + } finally { + if (reader != null) { + ObjectHelper.close(reader, null, LOG); + } + } + } + return packages; + } + + protected void tokenize(Set packages, String line) { + StringTokenizer iter = new StringTokenizer(line, ","); + while (iter.hasMoreTokens()) { + String name = iter.nextToken().trim(); + if (name.length() > 0) { + packages.add(name); + } + } + } + + protected static Bundle getBundle() { + return bundle; + } + + protected static synchronized String[] findTypeConverterPackageNames() { + Set packages = new HashSet(); + for (TypeConverterEntry entry : TYPE_CONVERTERS.values()) { + for (String packageName : entry.converterPackages) { + packages.add(packageName); + } + } + return packages.toArray(new String[packages.size()]); + } + + protected static synchronized Class getComponent(String name) throws Exception { + ComponentEntry entry = COMPONENTS.get(name); + if (entry == null) { + return null; + } + if (entry.type == null) { + URL url = entry.bundle.getEntry(entry.path); + // lets load the file + Properties properties = new Properties(); + BufferedInputStream reader = null; + try { + reader = new BufferedInputStream(url.openStream()); + properties.load(reader); + } finally { + try { + reader.close(); + } catch (Exception ignore) { + } + } + String classname = (String)properties.get("class"); + ClassLoader loader = BundleDelegatingClassLoader.createBundleClassLoaderFor(entry.bundle); + entry.type = loader.loadClass(classname); + } + if (LOG.isDebugEnabled()) { + LOG.debug("Found component: " + name + " via type: " + entry.type.getName()); + } + return entry.type; + } + +} Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/Activator.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java?rev=730721&r1=730720&r2=730721&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java (original) +++ activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/CamelContextFactoryBean.java Fri Jan 2 06:05:09 2009 @@ -16,11 +16,16 @@ */ package org.apache.camel.osgi; +import java.util.List; + import javax.xml.bind.annotation.XmlAccessType; import javax.xml.bind.annotation.XmlAccessorType; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlTransient; +import org.apache.camel.impl.converter.AnnotationTypeConverterLoader; +import org.apache.camel.impl.converter.DefaultTypeConverter; +import org.apache.camel.impl.converter.TypeConverterLoader; import org.apache.camel.spring.SpringCamelContext; import org.osgi.framework.BundleContext; import org.springframework.osgi.context.BundleContextAware; @@ -44,9 +49,28 @@ protected SpringCamelContext createContext() { SpringCamelContext context = super.createContext(); if (bundleContext != null) { - context.setComponentResolver(new OsgiComponentResolver(bundleContext)); + context.setComponentResolver(new OsgiComponentResolver()); + addOsgiAnnotationTypeConverterLoader(context, bundleContext); } + return context; } + + protected void addOsgiAnnotationTypeConverterLoader(SpringCamelContext context, BundleContext bundleContext) { + DefaultTypeConverter typeConverter = (DefaultTypeConverter) context.getTypeConverter(); + List typeConverterLoaders = typeConverter.getTypeConverterLoaders(); + // Remove the AnnotationTypeConverterLoader + TypeConverterLoader atLoader = null; + for (TypeConverterLoader loader : typeConverterLoaders) { + if (loader instanceof AnnotationTypeConverterLoader) { + atLoader = loader; + break; + } + } + if (atLoader != null) { + typeConverterLoaders.remove(atLoader); + } + typeConverterLoaders.add(new OsgiAnnotationTypeConverterLoader(bundleContext)); + } } Added: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java?rev=730721&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java (added) +++ activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java Fri Jan 2 06:05:09 2009 @@ -0,0 +1,37 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.osgi; + +import org.apache.camel.impl.converter.AnnotationTypeConverterLoader; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; + +public class OsgiAnnotationTypeConverterLoader extends AnnotationTypeConverterLoader { + private static final transient Log LOG = LogFactory.getLog(OsgiAnnotationTypeConverterLoader.class); + + public OsgiAnnotationTypeConverterLoader(BundleContext context) { + super(new OsgiResolverUtil(context)); + } + + protected String[] findPackageNames() { + return Activator.findTypeConverterPackageNames(); + } + + + +} Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiAnnotationTypeConverterLoader.java ------------------------------------------------------------------------------ svn:keywords = Rev Date Modified: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiComponentResolver.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiComponentResolver.java?rev=730721&r1=730720&r2=730721&view=diff ============================================================================== --- activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiComponentResolver.java (original) +++ activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiComponentResolver.java Fri Jan 2 06:05:09 2009 @@ -35,121 +35,11 @@ import org.springframework.osgi.util.BundleDelegatingClassLoader; public class OsgiComponentResolver implements ComponentResolver { - + private static final transient Log LOG = LogFactory.getLog(OsgiComponentResolver.class); - private BundleContext bundleContext; - private Map components; - - private class BundleListener implements SynchronousBundleListener { - public void bundleChanged(BundleEvent event) { - try { - Bundle bundle = event.getBundle(); - if (event.getType() == BundleEvent.RESOLVED) { - if (LOG.isDebugEnabled()) { - LOG.debug("Bundle resolved: " + bundle.getSymbolicName()); - } - mayBeAddComponentFor(bundle); - } else if (event.getType() == BundleEvent.UNRESOLVED) { - if (LOG.isDebugEnabled()) { - LOG.debug("Bundle unresolved: " + bundle.getSymbolicName()); - } - mayBeRemoveComponentFor(bundle); - } - } catch (Throwable e) { - LOG.fatal("Exception handing bundle changed event", e); - } - } - } - - private class ComponentEntry { - Bundle bundle; - String path; - String name; - Class type; - } - - public OsgiComponentResolver(BundleContext bundleContext) { - this.bundleContext = bundleContext; - } - - protected void init() { - if (components != null) { - return; - } - LOG.debug("Initializing OsgiComponentResolver"); - components = new HashMap(); - bundleContext.addBundleListener(new BundleListener()); - Bundle[] previousBundles = bundleContext.getBundles(); - for (int i = 0; i < previousBundles.length; i++) { - int state = previousBundles[i].getState(); - if (state == Bundle.RESOLVED || state == Bundle.ACTIVE) { - try { - mayBeAddComponentFor(previousBundles[i]); - } catch (Exception e) { - LOG.error("Component " + previousBundles[i] + " not added due to " + e.toString(), e); - } - } - } - } - - protected synchronized void mayBeAddComponentFor(Bundle bundle) { - Enumeration e = bundle.getEntryPaths("/META-INF/services/org/apache/camel/component/"); - if (e != null) { - while (e.hasMoreElements()) { - String path = (String)e.nextElement(); - if (LOG.isDebugEnabled()) { - LOG.debug("Found entry: " + path + " in bundle " + bundle.getSymbolicName()); - } - ComponentEntry entry = new ComponentEntry(); - entry.bundle = bundle; - entry.path = path; - entry.name = path.substring(path.lastIndexOf("/") + 1); - components.put(entry.name, entry); - } - } - } - - protected synchronized void mayBeRemoveComponentFor(Bundle bundle) { - // To avoid the CurrentModificationException, do not use components.values directly - ComponentEntry[] entriesArray = components.values().toArray(new ComponentEntry[0]); - for (ComponentEntry entry : entriesArray) { - if (entry.bundle == bundle) { - if (LOG.isDebugEnabled()) { - LOG.debug("Removing entry: " + entry.path + " in bundle " + bundle.getSymbolicName()); - } - components.remove(entry.name); - } - } - } - protected synchronized Class getComponent(String name) throws Exception { - ComponentEntry entry = components.get(name); - if (entry == null) { - return null; - } - if (entry.type == null) { - URL url = entry.bundle.getEntry(entry.path); - // lets load the file - Properties properties = new Properties(); - BufferedInputStream reader = null; - try { - reader = new BufferedInputStream(url.openStream()); - properties.load(reader); - } finally { - try { - reader.close(); - } catch (Exception ignore) { - } - } - String classname = (String)properties.get("class"); - ClassLoader loader = BundleDelegatingClassLoader.createBundleClassLoaderFor(entry.bundle); - entry.type = loader.loadClass(classname); - } - if (LOG.isDebugEnabled()) { - LOG.debug("Found component: " + name + " via type: " + entry.type.getName()); - } - return entry.type; + return Activator.getComponent(name); } public Component resolveComponent(String name, CamelContext context) throws Exception { @@ -168,8 +58,7 @@ } // we do not throw the exception here and try to auto create a component } - // Check in OSGi bundles - init(); + // Check in OSGi bundles Class type = null; try { type = getComponent(name); Added: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java URL: http://svn.apache.org/viewvc/activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java?rev=730721&view=auto ============================================================================== --- activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java (added) +++ activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java Fri Jan 2 06:05:09 2009 @@ -0,0 +1,47 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.osgi; + +import java.util.Set; + +import org.apache.camel.util.ResolverUtil; +import org.osgi.framework.Bundle; +import org.osgi.framework.BundleContext; +import org.springframework.osgi.util.BundleDelegatingClassLoader; + +public class OsgiResolverUtil extends ResolverUtil { + private Bundle bundle; + + public OsgiResolverUtil(BundleContext context) { + bundle = context.getBundle(); + } + + /** + * Returns the classloaders that will be used for scanning for classes. + * Here we just add BundleDelegatingClassLoader here + * + * @return the ClassLoader instances that will be used to scan for classes + */ + public Set getClassLoaders() { + Set classLoaders = super.getClassLoaders(); + // Using the Activator's bundle to make up a class loader + ClassLoader osgiLoader = BundleDelegatingClassLoader.createBundleClassLoaderFor(bundle); + classLoaders.add(osgiLoader); + return classLoaders; + } + +} Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java ------------------------------------------------------------------------------ svn:eol-style = native Propchange: activemq/camel/trunk/components/camel-osgi/src/main/java/org/apache/camel/osgi/OsgiResolverUtil.java ------------------------------------------------------------------------------ svn:keywords = Rev Date