camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [2/3] camel git commit: Fixed the eip model a bit around choice eip and rest-dsl
Date Thu, 08 Oct 2015 07:03:58 GMT
Fixed the eip model a bit around choice eip and rest-dsl


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

Branch: refs/heads/camel-2.16.x
Commit: b6a3dfd7daefefa37e2166dde8fb8df724bedb05
Parents: f6eddd7
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Tue Oct 6 16:11:51 2015 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Thu Oct 8 09:05:13 2015 +0200

----------------------------------------------------------------------
 .../camel/tools/apt/EipAnnotationProcessor.java | 71 +++++++++++++++++---
 1 file changed, 63 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b6a3dfd7/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java
----------------------------------------------------------------------
diff --git a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java
b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java
index c02c7c5..8a7d01f 100644
--- a/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java
+++ b/tooling/apt/src/main/java/org/apache/camel/tools/apt/EipAnnotationProcessor.java
@@ -18,6 +18,7 @@ package org.apache.camel.tools.apt;
 
 import java.io.PrintWriter;
 import java.util.Comparator;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Set;
@@ -75,6 +76,10 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
         "org.apache.camel.model.InterceptDefinition",
         "org.apache.camel.model.WhenDefinition",
     };
+    // special for verbs (these classes have sub classes, so we use this to find all classes)
+    private static final String[] ONE_OF_VERBS = new String[]{
+            "org.apache.camel.model.rest.VerbDefinition"
+    };
 
     private boolean skipUnwanted = true;
 
@@ -274,17 +279,21 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
                     // special for routes
                     processRoutes(roundEnv, originalClassType, elementRef, fieldElement,
fieldName, eipOptions, prefix);
 
-                    // special for rests
-                    processRests(roundEnv, originalClassType, elementRef, fieldElement, fieldName,
eipOptions, prefix);
-
                     // special for outputs
                     processOutputs(roundEnv, originalClassType, elementRef, fieldElement,
fieldName, eipOptions, prefix);
 
+                    // special for when clauses (choice eip)
+                    processRefWhenClauses(roundEnv, originalClassType, elementRef, fieldElement,
fieldName, eipOptions, prefix);
+
+                    // special for rests (rest-dsl)
+                    processRests(roundEnv, originalClassType, elementRef, fieldElement, fieldName,
eipOptions, prefix);
+
+                    // special for verbs (rest-dsl)
+                    processVerbs(roundEnv, originalClassType, elementRef, fieldElement, fieldName,
eipOptions, prefix);
+
                     // special for expression
                     processRefExpression(roundEnv, originalClassType, classElement, elementRef,
fieldElement, fieldName, eipOptions, prefix);
 
-                    // special for when clauses
-                    processRefWhenClauses(roundEnv, originalClassType, elementRef, fieldElement,
fieldName, eipOptions, prefix);
                 }
             }
 
@@ -446,6 +455,11 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
                     }
                 }
             }
+            // special for otherwise as we want to indicate that the element is
+            if ("otherwise".equals(name)) {
+                isOneOf = true;
+                oneOfTypes.add("otherwise");
+            }
 
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
@@ -694,6 +708,43 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
     }
 
     /**
+     * Special for processing an @XmlElementRef verbs field (rest-dsl)
+     */
+    private void processVerbs(RoundEnvironment roundEnv, TypeElement originalClassType, XmlElementRef
elementRef,
+                              VariableElement fieldElement, String fieldName, Set<EipOption>
eipOptions, String prefix) {
+        if ("verbs".equals(fieldName) && supportOutputs(originalClassType)) {
+            String kind = "element";
+            String name = elementRef.name();
+            if (isNullOrEmpty(name) || "##default".equals(name)) {
+                name = fieldName;
+            }
+            name = prefix + name;
+            TypeMirror fieldType = fieldElement.asType();
+            String fieldTypeName = fieldType.toString();
+
+            // gather oneOf which extends any of the output base classes
+            Set<String> oneOfTypes = new TreeSet<String>();
+            // find all classes that has that superClassName
+            Set<TypeElement> children = new LinkedHashSet<TypeElement>();
+            for (String superclass : ONE_OF_VERBS) {
+                findTypeElementChildren(roundEnv, children, superclass);
+            }
+            for (TypeElement child : children) {
+                XmlRootElement rootElement = child.getAnnotation(XmlRootElement.class);
+                if (rootElement != null) {
+                    String childName = rootElement.name();
+                    if (childName != null) {
+                        oneOfTypes.add(childName);
+                    }
+                }
+            }
+
+            EipOption ep = new EipOption(name, kind, fieldTypeName, true, "", "", false,
false, null, true, oneOfTypes);
+            eipOptions.add(ep);
+        }
+    }
+
+    /**
      * Special for processing an @XmlElementRef expression field
      */
     private void processRefExpression(RoundEnvironment roundEnv, TypeElement originalClassType,
TypeElement classElement,
@@ -759,7 +810,11 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
             String docComment = findJavaDoc(elementUtils, fieldElement, fieldName, name,
originalClassType, true);
             boolean deprecated = fieldElement.getAnnotation(Deprecated.class) != null;
 
-            EipOption ep = new EipOption(name, kind, fieldTypeName, false, "", docComment,
deprecated, false, null, false, null);
+            // indicate that this element is one of when
+            Set<String> oneOfTypes = new HashSet<String>();
+            oneOfTypes.add("when");
+
+            EipOption ep = new EipOption(name, kind, fieldTypeName, false, "", docComment,
deprecated, false, null, true, oneOfTypes);
             eipOptions.add(ep);
         }
     }
@@ -835,8 +890,8 @@ public class EipAnnotationProcessor extends AbstractAnnotationProcessor
{
     }
 
     private boolean hasOutput(EipModel model, Set<EipOption> options) {
-        // if we are from/rest then we accept output
-        if ("from".equals(model.getName()) || "rest".equals(model.getName())) {
+        // if we are route/rest then we accept output
+        if ("route".equals(model.getName()) || "rest".equals(model.getName())) {
             return true;
         }
 


Mime
View raw message