Updated Branches: refs/heads/master 2fe5d2aca -> 5e1a3a3ea
add an OSGi specific implementation of the findComponents() helper method on the MBean and on the CamelContext API so that implementations can behave differently (e.g. inside OSGi and outside) Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/5e1a3a3e Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/5e1a3a3e Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/5e1a3a3e Branch: refs/heads/master Commit: 5e1a3a3ea80d0b455eb445ede1e7fa6c96d4538f Parents: 2fe5d2a Author: James Strachan <james.strac...@gmail.com> Authored: Sat Jun 8 07:51:45 2013 +0200 Committer: James Strachan <james.strac...@gmail.com> Committed: Sat Jun 8 07:51:45 2013 +0200 ---------------------------------------------------------------------- .../main/java/org/apache/camel/CamelContext.java | 15 ++++++++++++--- .../org/apache/camel/impl/DefaultCamelContext.java | 6 ++++++ .../management/mbean/ManagedCamelContext.java | 2 +- .../org/apache/camel/util/CamelContextHelper.java | 12 +++++++++--- .../camel/core/osgi/OsgiDefaultCamelContext.java | 15 +++++++++++++++ 5 files changed, 43 insertions(+), 7 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5e1a3a3e/camel-core/src/main/java/org/apache/camel/CamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/CamelContext.java b/camel-core/src/main/java/org/apache/camel/CamelContext.java index 5a87ea0..5b2b4f6 100644 --- a/camel-core/src/main/java/org/apache/camel/CamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/CamelContext.java @@ -16,10 +16,10 @@ */ package org.apache.camel; +import java.io.IOException; import java.io.InputStream; -import java.util.Collection; -import java.util.List; -import java.util.Map; +import java.util.*; +import java.util.Properties; import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.TimeUnit; @@ -53,6 +53,7 @@ import org.apache.camel.spi.ServicePool; import org.apache.camel.spi.ShutdownStrategy; import org.apache.camel.spi.TypeConverterRegistry; import org.apache.camel.spi.UuidGenerator; +import org.apache.camel.util.LoadPropertiesException; /** * Interface used to represent the context used to configure routes and the @@ -1196,4 +1197,12 @@ public interface CamelContext extends SuspendableService, RuntimeConfiguration { * @param useBreadcrumb <tt>true</tt> to enable breadcrumb, <tt>false</tt> to disable */ void setUseBreadcrumb(Boolean useBreadcrumb); + + /** + * Find information about all the Camel components available in the classpath and {@link org.apache.camel.spi.Registry}. + * + * @return a map with the component name, and value with component details. + * @throws Exception is thrown if error occurred + */ + Map<String,Properties> findComponents() throws LoadPropertiesException, IOException; } http://git-wip-us.apache.org/repos/asf/camel/blob/5e1a3a3e/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java index 56a5504..c61c79f 100644 --- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java @@ -29,6 +29,7 @@ import java.util.LinkedHashMap; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; import java.util.TreeMap; import java.util.concurrent.ScheduledExecutorService; @@ -125,6 +126,7 @@ import org.apache.camel.util.CamelContextHelper; import org.apache.camel.util.EndpointHelper; import org.apache.camel.util.EventHelper; import org.apache.camel.util.IntrospectionSupport; +import org.apache.camel.util.LoadPropertiesException; import org.apache.camel.util.ObjectHelper; import org.apache.camel.util.ServiceHelper; import org.apache.camel.util.StopWatch; @@ -1005,6 +1007,10 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon } } + public Map<String, Properties> findComponents() throws LoadPropertiesException, IOException { + return CamelContextHelper.findComponents(this); + } + // Helper methods // ----------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/5e1a3a3e/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java index 2f5a76e..d01d3d0 100644 --- a/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java +++ b/camel-core/src/main/java/org/apache/camel/management/mbean/ManagedCamelContext.java @@ -342,7 +342,7 @@ public class ManagedCamelContext extends ManagedPerformanceCounter implements Ti } public Map<String, Properties> findComponents() throws Exception { - return CamelContextHelper.findComponents(context); + return context.findComponents(); } public List<String> findComponentNames() throws Exception { http://git-wip-us.apache.org/repos/asf/camel/blob/5e1a3a3e/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java ---------------------------------------------------------------------- diff --git a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java index 03b5422..40d7a1c 100644 --- a/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java +++ b/camel-core/src/main/java/org/apache/camel/util/CamelContextHelper.java @@ -354,10 +354,16 @@ public final class CamelContextHelper { * Finds all possible Components on the classpath and Registry */ public static SortedMap<String, Properties> findComponents(CamelContext camelContext) throws LoadPropertiesException { - SortedMap<String, Properties> map = new TreeMap<String, Properties>(); Enumeration<URL> iter = camelContext.getClassResolver().loadResourcesAsURL(COMPONENT_DESCRIPTOR); - while (iter != null && iter.hasMoreElements()) { - URL url = iter.nextElement(); + return findComponents(camelContext, iter); + } + + public static SortedMap<String, Properties> findComponents(CamelContext camelContext, + Enumeration<URL> componentDescriptionIter) + throws LoadPropertiesException { + SortedMap<String, Properties> map = new TreeMap<String, Properties>(); + while (componentDescriptionIter != null && componentDescriptionIter.hasMoreElements()) { + URL url = componentDescriptionIter.nextElement(); try { Properties properties = new Properties(); properties.load(url.openStream()); http://git-wip-us.apache.org/repos/asf/camel/blob/5e1a3a3e/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java ---------------------------------------------------------------------- diff --git a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java index 80002c1..9f7b0b2 100644 --- a/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java +++ b/components/camel-core-osgi/src/main/java/org/apache/camel/core/osgi/OsgiDefaultCamelContext.java @@ -16,11 +16,20 @@ */ package org.apache.camel.core.osgi; +import java.io.IOException; +import java.net.URL; +import java.util.Enumeration; +import java.util.Map; +import java.util.Properties; + import org.apache.camel.TypeConverter; import org.apache.camel.core.osgi.utils.BundleContextUtils; import org.apache.camel.impl.DefaultCamelContext; import org.apache.camel.spi.FactoryFinder; import org.apache.camel.spi.Registry; +import org.apache.camel.util.CamelContextHelper; +import org.apache.camel.util.LoadPropertiesException; +import org.osgi.framework.Bundle; import org.osgi.framework.BundleContext; public class OsgiDefaultCamelContext extends DefaultCamelContext { @@ -38,6 +47,12 @@ public class OsgiDefaultCamelContext extends DefaultCamelContext { OsgiCamelContextHelper.osgiUpdate(this, bundleContext); } + public Map<String, Properties> findComponents() throws LoadPropertiesException, IOException { + Bundle bundle = bundleContext.getBundle(); + Enumeration<URL> iter = bundle.getResources(CamelContextHelper.COMPONENT_DESCRIPTOR); + return CamelContextHelper.findComponents(this, iter); + } + @Override protected Registry createRegistry() { if (registry != null) {