Author: davsclaus Date: Thu Nov 1 15:50:35 2012 New Revision: 1404651 URL: http://svn.apache.org/viewvc?rev=1404651&view=rev Log: Fixed CS
Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java?rev=1404651&r1=1404650&r2=1404651&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/component/bean/BeanInfo.java Thu Nov 1 15:50:35 2012 @@ -514,7 +514,7 @@ public class BeanInfo { } private MethodInfo chooseMethodWithMatchingParameters(Exchange exchange, String parameters, Collection<MethodInfo> operationList) - throws AmbiguousMethodCallException { + throws AmbiguousMethodCallException { // we have hardcoded parameters so need to match that with the given operations Iterator<?> it = ObjectHelper.createIterator(parameters); int count = 0; Modified: camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java URL: http://svn.apache.org/viewvc/camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java?rev=1404651&r1=1404650&r2=1404651&view=diff ============================================================================== --- camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java (original) +++ camel/trunk/camel-core/src/main/java/org/apache/camel/language/simple/ast/SimpleFunctionExpression.java Thu Nov 1 15:50:35 2012 @@ -62,42 +62,14 @@ public class SimpleFunctionExpression ex return answer; } - // bodyAs - String remainder = ifStartsWithReturnRemainder("bodyAs", function); - if (remainder != null) { - String type = ObjectHelper.between(remainder, "(", ")"); - if (type == null) { - throw new SimpleParserException("Valid syntax: ${bodyAs(type)} was: " + function, token.getIndex()); - } - type = StringHelper.removeQuotes(type); - return ExpressionBuilder.bodyExpression(type); - } - // mandatoryBodyAs - remainder = ifStartsWithReturnRemainder("mandatoryBodyAs", function); - if (remainder != null) { - String type = ObjectHelper.between(remainder, "(", ")"); - if (type == null) { - throw new SimpleParserException("Valid syntax: ${mandatoryBodyAs(type)} was: " + function, token.getIndex()); - } - type = StringHelper.removeQuotes(type); - return ExpressionBuilder.mandatoryBodyExpression(type); - } - - // body OGNL - remainder = ifStartsWithReturnRemainder("body", function); - if (remainder == null) { - remainder = ifStartsWithReturnRemainder("in.body", function); - } - if (remainder != null) { - boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); - if (invalid) { - throw new SimpleParserException("Valid syntax: ${body.OGNL} was: " + function, token.getIndex()); - } - return ExpressionBuilder.bodyOgnlExpression(remainder); + // body and headers first + answer = createSimpleExpressionBodyOrHeader(function, strict); + if (answer != null) { + return answer; } // camelContext OGNL - remainder = ifStartsWithReturnRemainder("camelContext", function); + String remainder = ifStartsWithReturnRemainder("camelContext", function); if (remainder != null) { boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); if (invalid) { @@ -116,74 +88,6 @@ public class SimpleFunctionExpression ex return ExpressionBuilder.exchangeExceptionOgnlExpression(remainder); } - // headerAs - remainder = ifStartsWithReturnRemainder("headerAs", function); - if (remainder != null) { - String keyAndType = ObjectHelper.between(remainder, "(", ")"); - if (keyAndType == null) { - throw new SimpleParserException("Valid syntax: ${headerAs(key, type)} was: " + function, token.getIndex()); - } - - String key = ObjectHelper.before(keyAndType, ","); - String type = ObjectHelper.after(keyAndType, ","); - if (ObjectHelper.isEmpty(key) || ObjectHelper.isEmpty(type)) { - throw new SimpleParserException("Valid syntax: ${headerAs(key, type)} was: " + function, token.getIndex()); - } - key = StringHelper.removeQuotes(key); - type = StringHelper.removeQuotes(type); - return ExpressionBuilder.headerExpression(key, type); - } - - // headers function - if ("in.headers".equals(function) || "headers".equals(function)) { - return ExpressionBuilder.headersExpression(); - } - - // in header function - remainder = ifStartsWithReturnRemainder("in.headers", function); - if (remainder == null) { - remainder = ifStartsWithReturnRemainder("in.header", function); - } - if (remainder == null) { - remainder = ifStartsWithReturnRemainder("headers", function); - } - if (remainder == null) { - remainder = ifStartsWithReturnRemainder("header", function); - } - if (remainder != null) { - // remove leading character (dot or ?) - if (remainder.startsWith(".") || remainder.startsWith("?")) { - remainder = remainder.substring(1); - } - // remove starting and ending brackets - if (remainder.startsWith("[") && remainder.endsWith("]")) { - remainder = remainder.substring(1, remainder.length() - 1); - } - - // validate syntax - boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); - if (invalid) { - throw new SimpleParserException("Valid syntax: ${header.name[key]} was: " + function, token.getIndex()); - } - - if (OgnlHelper.isValidOgnlExpression(remainder)) { - // ognl based header - return ExpressionBuilder.headersOgnlExpression(remainder); - } else { - // regular header - return ExpressionBuilder.headerExpression(remainder); - } - } - - // out header function - remainder = ifStartsWithReturnRemainder("out.header.", function); - if (remainder == null) { - remainder = ifStartsWithReturnRemainder("out.headers.", function); - } - if (remainder != null) { - return ExpressionBuilder.outHeaderExpression(remainder); - } - // property remainder = ifStartsWithReturnRemainder("property", function); if (remainder != null) { @@ -216,8 +120,6 @@ public class SimpleFunctionExpression ex if (remainder != null) { return ExpressionBuilder.systemPropertyExpression(remainder); } - - // system property remainder = ifStartsWithReturnRemainder("sysenv.", function); if (remainder != null) { return ExpressionBuilder.systemEnvironmentExpression(remainder); @@ -280,6 +182,112 @@ public class SimpleFunctionExpression ex } } + private Expression createSimpleExpressionBodyOrHeader(String function, boolean strict) { + // bodyAs + String remainder = ifStartsWithReturnRemainder("bodyAs", function); + if (remainder != null) { + String type = ObjectHelper.between(remainder, "(", ")"); + if (type == null) { + throw new SimpleParserException("Valid syntax: ${bodyAs(type)} was: " + function, token.getIndex()); + } + type = StringHelper.removeQuotes(type); + return ExpressionBuilder.bodyExpression(type); + } + // mandatoryBodyAs + remainder = ifStartsWithReturnRemainder("mandatoryBodyAs", function); + if (remainder != null) { + String type = ObjectHelper.between(remainder, "(", ")"); + if (type == null) { + throw new SimpleParserException("Valid syntax: ${mandatoryBodyAs(type)} was: " + function, token.getIndex()); + } + type = StringHelper.removeQuotes(type); + return ExpressionBuilder.mandatoryBodyExpression(type); + } + + // body OGNL + remainder = ifStartsWithReturnRemainder("body", function); + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("in.body", function); + } + if (remainder != null) { + boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); + if (invalid) { + throw new SimpleParserException("Valid syntax: ${body.OGNL} was: " + function, token.getIndex()); + } + return ExpressionBuilder.bodyOgnlExpression(remainder); + } + + // headerAs + remainder = ifStartsWithReturnRemainder("headerAs", function); + if (remainder != null) { + String keyAndType = ObjectHelper.between(remainder, "(", ")"); + if (keyAndType == null) { + throw new SimpleParserException("Valid syntax: ${headerAs(key, type)} was: " + function, token.getIndex()); + } + + String key = ObjectHelper.before(keyAndType, ","); + String type = ObjectHelper.after(keyAndType, ","); + if (ObjectHelper.isEmpty(key) || ObjectHelper.isEmpty(type)) { + throw new SimpleParserException("Valid syntax: ${headerAs(key, type)} was: " + function, token.getIndex()); + } + key = StringHelper.removeQuotes(key); + type = StringHelper.removeQuotes(type); + return ExpressionBuilder.headerExpression(key, type); + } + + // headers function + if ("in.headers".equals(function) || "headers".equals(function)) { + return ExpressionBuilder.headersExpression(); + } + + // in header function + remainder = ifStartsWithReturnRemainder("in.headers", function); + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("in.header", function); + } + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("headers", function); + } + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("header", function); + } + if (remainder != null) { + // remove leading character (dot or ?) + if (remainder.startsWith(".") || remainder.startsWith("?")) { + remainder = remainder.substring(1); + } + // remove starting and ending brackets + if (remainder.startsWith("[") && remainder.endsWith("]")) { + remainder = remainder.substring(1, remainder.length() - 1); + } + + // validate syntax + boolean invalid = OgnlHelper.isInvalidValidOgnlExpression(remainder); + if (invalid) { + throw new SimpleParserException("Valid syntax: ${header.name[key]} was: " + function, token.getIndex()); + } + + if (OgnlHelper.isValidOgnlExpression(remainder)) { + // ognl based header + return ExpressionBuilder.headersOgnlExpression(remainder); + } else { + // regular header + return ExpressionBuilder.headerExpression(remainder); + } + } + + // out header function + remainder = ifStartsWithReturnRemainder("out.header.", function); + if (remainder == null) { + remainder = ifStartsWithReturnRemainder("out.headers.", function); + } + if (remainder != null) { + return ExpressionBuilder.outHeaderExpression(remainder); + } + + return null; + } + private Expression createSimpleExpressionDirectly(String expression) { if (ObjectHelper.isEqualToAny(expression, "body", "in.body")) { return ExpressionBuilder.bodyExpression();