You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dh...@apache.org on 2014/06/10 21:51:49 UTC

[21/35] git commit: Fixed method alias handling, changed component config file name pattern

Fixed method alias handling, changed component config file name pattern


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

Branch: refs/heads/master
Commit: 96c8ec0f4da3df0f6bbe0374a625dddaa2d7524d
Parents: 5bf87ed
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Wed Jun 4 13:47:58 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 10 12:48:33 2014 -0700

----------------------------------------------------------------------
 .../camel/util/component/ApiMethodHelper.java   | 21 +++++++++++++-----
 .../component/ApiMethodPropertiesHelper.java    | 14 ++++++------
 .../ApiMethodPropertiesHelperTest.java          |  4 ++--
 .../src/main/resources/api-collection.vm        |  2 +-
 .../src/main/resources/api-endpoint-config.vm   |  2 +-
 .../src/main/resources/api-name-enum.vm         |  2 +-
 .../apache/camel/component/test/TestConfig.java | 23 --------------------
 .../camel/component/test/TestConfiguration.java | 23 ++++++++++++++++++++
 8 files changed, 51 insertions(+), 40 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
index dbbc332..a698c1e 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodHelper.java
@@ -50,7 +50,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
     private final Map<String, Class<?>> VALID_ARGUMENTS = new HashMap<String, Class<?>>();
 
     // maps aliases to actual method names
-    private final HashMap<String, String> ALIASES = new HashMap<String, String>();
+    private final HashMap<String, Set<String>> ALIASES = new HashMap<String, Set<String>>();
 
     /**
      * Create a helper to work with a {@link ApiMethod}, using optional method aliases.
@@ -94,7 +94,12 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
                         builder.append(Character.toLowerCase(firstChar)).append(alias.substring(1));
                         alias = builder.toString();
                     }
-                    ALIASES.put(alias, name);
+                    Set<String> names = ALIASES.get(alias);
+                    if (names == null) {
+                        names = new HashSet<String>();
+                        ALIASES.put(alias, names);
+                    }
+                    names.add(name);
                 }
             }
 
@@ -144,7 +149,7 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
     /**
      * Gets methods that match the given name and arguments.<p/>
      * Note that the args list is a required subset of arguments for returned methods.
-     * @param name case sensitive full method name to lookup
+     * @param name case sensitive method name or alias to lookup
      * @param argNames unordered required argument names
      * @return non-null unmodifiable list of methods that take all of the given arguments, empty if there is no match
      */
@@ -152,7 +157,10 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
         List<T> methods = METHOD_MAP.get(name);
         if (methods == null) {
             if (ALIASES.containsKey(name)) {
-                methods = METHOD_MAP.get(ALIASES.get(name));
+                methods = new ArrayList<T>();
+                for (String method : ALIASES.get(name)) {
+                    methods.addAll(METHOD_MAP.get(method));
+                }
             }
         }
         if (methods == null) {
@@ -232,7 +240,10 @@ public final class ApiMethodHelper<T extends Enum<T> & ApiMethod> {
         List<Object> arguments = ARGUMENTS_MAP.get(name);
         if (arguments == null) {
             if (ALIASES.containsKey(name)) {
-                arguments = ARGUMENTS_MAP.get(ALIASES.get(name));
+                arguments = new ArrayList<Object>();
+                for (String method : ALIASES.get(name)) {
+                    arguments.addAll(ARGUMENTS_MAP.get(method));
+                }
             }
         }
         if (arguments == null) {

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodPropertiesHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodPropertiesHelper.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodPropertiesHelper.java
index ea0f442..4cd692c 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodPropertiesHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodPropertiesHelper.java
@@ -29,19 +29,19 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 /**
- * Helper class to work with ApiMethod arguments.
+ * Helper class to work with ApiMethod arguments to be extended by components.
  */
-public final class ApiMethodPropertiesHelper<C> {
+public abstract class ApiMethodPropertiesHelper<C> {
 
-    private final Logger LOG = LoggerFactory.getLogger(ApiMethodPropertiesHelper.class);
+    protected Logger LOG = LoggerFactory.getLogger(ApiMethodPropertiesHelper.class);
 
     // set of field names which are specific to the api, to be excluded from method argument considerations
-    private final Set<String> COMPONENT_CONFIG_FIELDS = new HashSet<String>();
+    protected final Set<String> COMPONENT_CONFIG_FIELDS = new HashSet<String>();
 
-    private final Class<?> componentConfigClass;
-    private final String propertyPrefix;
+    protected final Class<?> componentConfigClass;
+    protected final String propertyPrefix;
 
-    public ApiMethodPropertiesHelper(Class<C> componentConfiguration, String propertyPrefix) {
+    protected ApiMethodPropertiesHelper(Class<C> componentConfiguration, String propertyPrefix) {
 
         this.componentConfigClass = componentConfiguration;
         this.propertyPrefix = propertyPrefix;

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
----------------------------------------------------------------------
diff --git a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
index c711c5f..cfc29d1 100644
--- a/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
+++ b/camel-core/src/test/java/org/apache/camel/util/component/ApiMethodPropertiesHelperTest.java
@@ -25,7 +25,7 @@ import static org.junit.Assert.assertEquals;
 
 public class ApiMethodPropertiesHelperTest {
 
-    private static final String TEST_PREFIX = "TestComponent.";
+    private static final String TEST_PREFIX = "CamelTest.";
 
     private static final String PROPERTY_1 = TEST_PREFIX + "property1";
     private static final String PROPERTY_2 = TEST_PREFIX + "property2";
@@ -38,7 +38,7 @@ public class ApiMethodPropertiesHelperTest {
     private static final String VALUE_4 = "true";
 
     private static ApiMethodPropertiesHelper propertiesHelper =
-            new ApiMethodPropertiesHelper(TestComponentConfiguration.class, TEST_PREFIX);
+            new ApiMethodPropertiesHelper(TestComponentConfiguration.class, TEST_PREFIX){};
 
     @Test
     public void testGetExchangeProperties() throws Exception {

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
index 6596d16..e2c7eb4 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-collection.vm
@@ -24,7 +24,7 @@ package $packageName;
 import java.util.Map;
 import java.util.HashMap;
 
-#set( $componentConfig = "${componentName}Config" )
+#set( $componentConfig = "${componentName}Configuration" )
 import ${componentPackage}.${componentConfig};
 #foreach ( $api in $apis )
 import ${componentPackage}.${helper.getEndpointConfig($api.ProxyClass)};

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-endpoint-config.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-endpoint-config.vm b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-endpoint-config.vm
index 03ddd4b..f01d29e 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-endpoint-config.vm
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-endpoint-config.vm
@@ -25,7 +25,7 @@ package ${componentPackage};
  * Camel EndpointConfiguration for $proxyType.Name
  */
 @SuppressWarnings("unused")
-public final class $configName extends ${componentName}Config {
+public final class $configName extends ${componentName}Configuration {
 
 #foreach( $parameter in $parameters.entrySet() )
     private $helper.getCanonicalName($parameter.Value) $parameter.Key;

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-name-enum.vm
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-name-enum.vm b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-name-enum.vm
index f4fa253..e0d558d 100644
--- a/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-name-enum.vm
+++ b/tooling/maven/camel-component-util-maven-plugin/src/main/resources/api-name-enum.vm
@@ -45,7 +45,7 @@ public enum $apiNameEnum implements ApiName {
         return name;
     }
 
-    public static $apiNameEnum fromValue(String value) {
+    public static $apiNameEnum fromValue(String value) throws IllegalArgumentException {
         for ($apiNameEnum api : ${apiNameEnum}.values()) {
             if (api.name.equals(value)) {
                 return api;

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfig.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfig.java b/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfig.java
deleted file mode 100644
index 429280e..0000000
--- a/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfig.java
+++ /dev/null
@@ -1,23 +0,0 @@
-/**
- * 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.component.test;
-
-/**
- * Dummy component config.
- */
-public class TestConfig {
-}

http://git-wip-us.apache.org/repos/asf/camel/blob/96c8ec0f/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java b/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
new file mode 100644
index 0000000..de22f82
--- /dev/null
+++ b/tooling/maven/camel-component-util-maven-plugin/src/test/java/org/apache/camel/component/test/TestConfiguration.java
@@ -0,0 +1,23 @@
+/**
+ * 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.component.test;
+
+/**
+ * Dummy component configuration.
+ */
+public class TestConfiguration {
+}