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:44 UTC
[16/35] git commit: Updated ApiCollection to use type ApiName,
fixed method name constant to be locale independent
Updated ApiCollection to use type ApiName, fixed method name constant to be locale independent
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a38476c2
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a38476c2
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a38476c2
Branch: refs/heads/master
Commit: a38476c24af048437a8fb4ddb35b73ad5dbeb4ea
Parents: fad4865
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Mon Jun 2 15:45:47 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Jun 10 12:48:32 2014 -0700
----------------------------------------------------------------------
.../camel/util/component/ApiCollection.java | 14 +++++++---
.../camel/util/component/ApiMethodParser.java | 11 ++++++--
.../apache/camel/util/component/ApiName.java | 29 ++++++++++++++++++++
3 files changed, 48 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/a38476c2/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
index 6520d1c..1183591 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiCollection.java
@@ -18,21 +18,27 @@ package org.apache.camel.util.component;
import java.util.Collections;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Map;
import java.util.Set;
/**
* Base class for a collection of ApiMethods. Meant to be extended by Components to create the api name map.
*/
-public abstract class ApiCollection {
+@SuppressWarnings("unused")
+public abstract class ApiCollection<T extends Enum & ApiName> {
- protected final Map<String, ApiMethodHelper> apis = new HashMap<String, ApiMethodHelper>();
+ protected final Map<T, ApiMethodHelper> apis = new HashMap<T, ApiMethodHelper>();
- public final ApiMethodHelper getHelper(String apiName) {
+ public final ApiMethodHelper getHelper(T apiName) {
return apis.get(apiName);
}
public final Set<String> getApiNames() {
- return Collections.unmodifiableSet(apis.keySet());
+ final Set<String> result = new HashSet<String>();
+ for (T api : apis.keySet()) {
+ result.add(api.getName());
+ }
+ return Collections.unmodifiableSet(result);
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/a38476c2/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
index b7e6ef7..1003df4 100644
--- a/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiMethodParser.java
@@ -178,8 +178,15 @@ public abstract class ApiMethodParser<T> {
// assign unique names to every method model
final Map<String, Integer> dups = new HashMap<String, Integer>();
for (ApiMethodModel model : result) {
- // TODO watch out, this uses default locale to convert to upper case
- String uniqueName = model.name.toUpperCase();
+ // locale independent upper case conversion
+ final String name = model.getName();
+ final char[] upperCase = new char[name.length()];
+ final char[] lowerCase = name.toCharArray();
+ for (int i = 0; i < upperCase.length; i++) {
+ upperCase[i] = Character.toUpperCase(lowerCase[i]);
+ }
+ String uniqueName = new String(upperCase);
+
Integer suffix = dups.get(uniqueName);
if (suffix == null) {
dups.put(uniqueName, 1);
http://git-wip-us.apache.org/repos/asf/camel/blob/a38476c2/camel-core/src/main/java/org/apache/camel/util/component/ApiName.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/component/ApiName.java b/camel-core/src/main/java/org/apache/camel/util/component/ApiName.java
new file mode 100644
index 0000000..9c863fd
--- /dev/null
+++ b/camel-core/src/main/java/org/apache/camel/util/component/ApiName.java
@@ -0,0 +1,29 @@
+/**
+ * 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.util.component;
+
+/**
+ * Marker interface for ApiName enumerations.
+ */
+public interface ApiName {
+
+ /**
+ * Returns API name prefix path element for endpoint uri.
+ * @return unique API name prefix
+ */
+ String getName();
+}