apex-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Chinmay Kolhatkar (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (APEXMALHAR-1972) Create Expression Evaluator Support quasi-Java Expression Language
Date Wed, 13 Jan 2016 10:38:39 GMT

    [ https://issues.apache.org/jira/browse/APEXMALHAR-1972?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15095984#comment-15095984
] 

Chinmay Kolhatkar commented on APEXMALHAR-1972:
-----------------------------------------------

h2. Examples
This shows various ways in which ExpressionEvaluator can be used.
h3. Accessing multiple fields from single POJO using operand : ${object.fieldName}
	+*Parameter to expression:*+
	*Code:*
{code:java}
POJO1 pojo = new POJO1();
pojo.setA(12);
pojo.setB(13);
pojo.setD(new Date(1988 - 1900, 2, 11));
pojo.name1 = "Apex";
pojo.name2 = "DataTorrent";
		{code}

*Explanation:*
		pojo object of class POJO1 on which expression will be operated.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inp"}, new Class[]{POJO1.class});

{code}

*Explanation:*
This tells expression evaluator that when inp is seen in string expression, that corresponds
to type POJO1.class.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "${inp.a} * ${inp.b}";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Long.class);

{code}

*Explanation:*
This compiles expression provides and tells that the return type is Long.class.

	+*Using evaluated expression:*+
	*Code:*
{code:java}
Long mult = expression.execute(pojo);
	{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 
h3. Accessing multiple fields from single POJO using operand: ${fieldName}
	+*Parameter to expression:*+
	*Code:*
{code:java}
POJO1 pojo = new POJO1();
pojo.setA(12);
pojo.setB(13);
pojo.setD(new Date(1988 - 1900, 2, 11));
pojo.name1 = "Apex";
pojo.name2 = "DataTorrent";
		{code}

*Explanation:*
		pojo object of class POJO1 on which expression will be operated.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inp"}, new Class[]{POJO1.class});

{code}

*Explanation:*
This tells expression evaluator that when inp is seen in string expression, that corresponds
to type POJO1.class.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "${a} * ${b}";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Long.class);
{code}

*Explanation:*
This compiles expression provides and tells that the return type is Long.class.
As seen the expression references field a & field 3 by Type3 of operand. THe effect 
is same as operand of Type1.

	+*Using evaluated expression:*+
	*Code:*
{code:java}
Long mult = expression.execute(pojo);
	{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 
h3. Accessing multiple fields from multiple POJO of same type
	+*Parameter to expression:*+
	*Code:*
{code:java}
POJO1 pojoA = new POJO1();
pojoA.setA(12);
pojoA.setB(13);
pojoA.setD(new Date(1988 - 1900, 2, 11));
pojoA.name1 = "Apex";
pojoA.name2 = "DataTorrent";

POJO1 pojoB = new POJO1();
pojoB.setA(14);
pojoB.setB(15);
pojoB.setD(new Date(1988 - 1900, 2, 11));
pojoB.name1 = "apex";
pojoB.name2 = "DataTorrent";
		{code}

*Explanation:*
		Both pojoA & pojoB object of class POJO1 on which expression will be operated.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inpA", “inpB”}, new Class[]{POJO1.class,
POJO1.class});
{code}

*Explanation:*
This tells expression evaluator that when inpA & inpB is seen in string expression, that
corresponds to type POJO1.class. This also tells expression evaluator the order in which the
parameters and types will b eexpected.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "equalsIgnoreCase(${inpA.name1}, ${inpB.name1}) ? ${inpA.a} : ${inpB.a}";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Long.class);
{code}

*Explanation:*
This compiles expression provides and tells that the return type is Long.class.
	+*Using evaluated expression:*+
	*Code:*
{code:java}
Long mult = expression.execute(pojoA, pojoB);
{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 
h3. Accessing multiple fields from multiple POJO of different type
	+*Parameter to expression:*+
	*Code:*
{code:java}
POJO1 pojoA = new POJO1();
pojoA.setA(12);
pojoA.setB(13);
pojoA.setD(new Date(1988 - 1900, 2, 11));
pojoA.name1 = "Apex";
pojoA.name2 = "DataTorrent";

POJO2 pojoB = new POJO2();
pojoB.name1 = "apex";
pojoB.value = 15;
{code}

*Explanation:*
Both pojoA of class POJO1 & pojoB object of class POJO2 on which expression will be operated.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inpA", “inpB”}, new Class[]{POJO1.class,
POJO2.class});
{code}

*Explanation:*
This tells expression evaluator that when inpA is seen in string expression that corresponds
to type POJO1.class and when inpB  is seen in expression that corresponds to type POJ).class.

This also tells expression evaluator the order in which the parameters and types will be expected.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "equalsIgnoreCase(${inpA.name1}, ${inpB.name1}) ? ${inpA.a} : ${inpB.value}";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Long.class);
{code}

*Explanation:*
This compiles expression provides and tells that the return type is Long.class.
	+*Using evaluated expression:*+
	*Code:*
{code:java}
Long mult = expression.execute(pojoA, pojoB);
{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 

h3. Accessing fields from nested POJO operand: ${object.fieldName.innerFieldName}
	+*Parameter to expression:*+
	*Code:*
{code:java}
POJO4 pojoInternal = new POJO4();
pojoInternal.setValue(12345);
POJO3 pojo = new POJO3();
pojo.pojoInternal = pojoInternal;
pojo.name1 = “12345”
pojo.name2 = “67890”;
{code}

*Explanation:*
pojo of type POJO3.class has an internal variable of class type POJO4.class. pojo (POJO3)
will be the parameter to expression for evaluation.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inpX"}, new Class[]{POJO3.class});
{code}

*Explanation:*
This tells expression evaluator that when inpX is seen in string expression, that corresponds
to type POJO3.class. This also tells expression evaluator the order in which the parameters
and types will be expected.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "strlen(${inpX.name1}) == strlen(${inpX.name2}) ? ${inpX.pojoInternal.value}
: -1 * ${inpX.pojoInternal.value}";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Integer.class);
{code}

*Explanation:*
This compiles expression provides and tells that the return type is Integer.class.
	+*Using evaluated expression:*+
	*Code:*
{code:java}
Integer mult = expression.execute(pojo);
{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 
h3. Accessing operand directly using operand: ${object}
+*Parameter to expression:*+
	*Code:*
{code:java}
POJO5 pojo = new POJO5();
pojo.pojoInternal = pojoInternal;
pojo.name1 = “12345”
pojo.name2 = “67890”;

public String processData()
{
   return this.name1 + this.name2;
}
{code}

*Explanation:*
pojo of type POJO5.class has an internal method called processData which has public access.
pojo (POJO5) will be the parameter to expression for evaluation.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inpX"}, new Class[]{POJO5.class});
{code}

*Explanation:*
This tells expression evaluator that when inpX is seen in string expression, that corresponds
to type POJO5.class. This also tells expression evaluator the order in which the parameters
and types will be expected.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "${inpX}.processData";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
String.class);
{code}

*Explanation:*
This compiles expression provides and tells that the return type is String.class.
	+*Using evaluated expression:*+
	*Code:*
{code:java}
String result = expression.execute(pojo);
	{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 
h3. Using function evaluator of Expression Evaluator
		+*Parameter to expression:*+
	*Code:*
{code:java}
POJO6 pojo = new POJO6();
pojo.value1 = 4
pojo.value2 = 12;
{code}

*Explanation:*
pojo of type POJO6.class has an internal method called processData which has public access.
pojo (POJO6) will be the parameter to expression for evaluation.

+*ExpressionEvaluator configuration:*+
*Code:*
{code:java}
ExpressionEvaluator ee = new ExpressionEvaluator();
// Let expression evaluator know what are the object mappings present in expressions //and
their class types.
ee.setInputObjectPlaceholders(new String[] {"inpF"}, new Class[]{POJO6.class});
{code}

*Explanation:*
This tells expression evaluator that when inpF is seen in string expression, that corresponds
to type POJO5.class. This also tells expression evaluator the order in which the parameters
and types will be expected.
 
+*Compiling the expression:*+
*Code:*
{code:java}
String expression = "long retVal=1; for (int i=0; ${inpF.value1}; i++) {retVal = retVal *
${inpF.value1}; } return retVal;";
ExpressionEvaluator.Expression<Long> expression =  ee.createExecutableExpression(expression,
Long.class);
{code}

*Explanation:*
This compiles given function code provides and tells that the return type is String.class.
	+*Using evaluated expression:*+
	*Code:*
{code:java}
Long result = expression.execute(pojo);
{code}

*Explanation:*
This executes the compiled expression against pojo parameter passed and return the result
of expression. 


> Create Expression Evaluator Support quasi-Java Expression Language
> ------------------------------------------------------------------
>
>                 Key: APEXMALHAR-1972
>                 URL: https://issues.apache.org/jira/browse/APEXMALHAR-1972
>             Project: Apache Apex Malhar
>          Issue Type: New Feature
>          Components: utilities
>            Reporter: Chinmay Kolhatkar
>            Assignee: Chinmay Kolhatkar
>
> Create Expression Evaluator utility which will have support for quasi-Java expression
language.
> Usecases, Design, etc need to be added as a comment.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Mime
View raw message