camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: CAMEL-7999: Use FactoryFinder to find component documentation location instead of having to maintain special naming code in camel-core.
Date Tue, 06 Jan 2015 17:11:45 GMT
Repository: camel
Updated Branches:
  refs/heads/master 5a276c3c9 -> 565764851


CAMEL-7999: Use FactoryFinder to find component documentation location instead of having to
maintain special naming code in camel-core.


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/95a24dfc
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/95a24dfc
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/95a24dfc

Branch: refs/heads/master
Commit: 95a24dfcc75257441be697bc1a12d957d4fb8df0
Parents: 5a276c3
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Jan 6 16:16:49 2015 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Tue Jan 6 16:16:49 2015 +0100

----------------------------------------------------------------------
 .../apache/camel/impl/DefaultCamelContext.java  | 107 +++++++++----------
 1 file changed, 52 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/95a24dfc/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 fb42e4e..c492fcf 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
@@ -1138,35 +1138,65 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
     }
 
     public String getComponentDocumentation(String componentName) throws IOException {
-        String packageName = sanitizeComponentName(componentName);
-        String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + packageName + "/"
+ componentName + ".html";
-        ClassResolver resolver = getClassResolver();
-        InputStream inputStream = resolver.loadResourceAsStream(path);
-        log.debug("Loading component documentation for: {} using class resolver: {} ->
{}", new Object[]{componentName, resolver, inputStream});
-        if (inputStream != null) {
-            try {
-                return IOHelper.loadText(inputStream);
-            } finally {
-                IOHelper.close(inputStream);
+        // use the component factory finder to find the package name of the component class,
which is the location
+        // where the documentation exists as well
+        FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
+        try {
+            Class<?> clazz = finder.findClass(componentName);
+            if (clazz == null) {
+                return null;
+            }
+
+            String packageName = clazz.getPackage().getName();
+            packageName = packageName.replace('.', '/');
+            String path = packageName + "/" + componentName + ".html";
+
+            ClassResolver resolver = getClassResolver();
+            InputStream inputStream = resolver.loadResourceAsStream(path);
+            log.debug("Loading component documentation for: {} using class resolver: {} ->
{}", new Object[]{componentName, resolver, inputStream});
+            if (inputStream != null) {
+                try {
+                    return IOHelper.loadText(inputStream);
+                } finally {
+                    IOHelper.close(inputStream);
+                }
             }
+            return null;
+
+        } catch (ClassNotFoundException e) {
+            return null;
         }
-        return null;
     }
 
     public String getComponentParameterJsonSchema(String componentName) throws IOException
{
-        String packageName = sanitizeComponentName(componentName);
-        String path = CamelContextHelper.COMPONENT_DOCUMENTATION_PREFIX + packageName + "/"
+ componentName + ".json";
-        ClassResolver resolver = getClassResolver();
-        InputStream inputStream = resolver.loadResourceAsStream(path);
-        log.debug("Loading component JSON Schema for: {} using class resolver: {} -> {}",
new Object[]{componentName, resolver, inputStream});
-        if (inputStream != null) {
-            try {
-                return IOHelper.loadText(inputStream);
-            } finally {
-                IOHelper.close(inputStream);
+        // use the component factory finder to find the package name of the component class,
which is the location
+        // where the documentation exists as well
+        FactoryFinder finder = getFactoryFinder(DefaultComponentResolver.RESOURCE_PATH);
+        try {
+            Class<?> clazz = finder.findClass(componentName);
+            if (clazz == null) {
+                return null;
+            }
+
+            String packageName = clazz.getPackage().getName();
+            packageName = packageName.replace('.', '/');
+            String path = packageName + "/" + componentName + ".json";
+
+            ClassResolver resolver = getClassResolver();
+            InputStream inputStream = resolver.loadResourceAsStream(path);
+            log.debug("Loading component JSON Schema for: {} using class resolver: {} ->
{}", new Object[]{componentName, resolver, inputStream});
+            if (inputStream != null) {
+                try {
+                    return IOHelper.loadText(inputStream);
+                } finally {
+                    IOHelper.close(inputStream);
+                }
             }
+            return null;
+
+        } catch (ClassNotFoundException e) {
+            return null;
         }
-        return null;
     }
 
     public String getEipParameterJsonSchema(String eipName) throws IOException {
@@ -1325,39 +1355,6 @@ public class DefaultCamelContext extends ServiceSupport implements
ModelCamelCon
         }
     }
 
-    /**
-     * Sanitizes the component name by removing dash (-) in the name, when using the component
name to load
-     * resources from the classpath.
-     */
-    private static String sanitizeComponentName(String componentName) {
-        // the ftp components are in a special package
-        if ("ftp".equals(componentName) || "ftps".equals(componentName) || "sftp".equals(componentName))
{
-            return "file/remote";
-        } else if ("cxfrs".equals(componentName)) {
-            return "cxf/jaxrs";
-        } else if ("gauth".equals(componentName) || "ghttp".equals(componentName) || "glogin".equals(componentName)
-                || "gmail".equals(componentName) || "gtask".equals(componentName)) {
-            return "gae/" + componentName.substring(1);
-        } else if ("guava-eventbus".equals(componentName)) {
-            return "guava/eventbus";
-        } else if ("atmosphere-websocket".equals(componentName)) {
-            return "atmosphere/websocket";
-        } else if ("netty-http".equals(componentName)) {
-            return "netty/http";
-        } else if ("netty4-http".equals(componentName)) {
-            return "netty4/http";
-        } else if ("spring-event".equals(componentName)) {
-            return "event";
-        } else if ("class".equals(componentName)) {
-            return "beanclass";
-        } else if ("smtp".equals(componentName) || "smtps".equals(componentName)
-                || "imap".equals(componentName) || "imaps".equals(componentName)
-                || "pop3".equals(componentName) || "pop3s".equals(componentName)) {
-            return "mail";
-        }
-        return componentName.replaceAll("-", "");
-    }
-
     public String explainEndpointJson(String uri, boolean includeAllOptions) {
         try {
             URI u = new URI(uri);


Mime
View raw message