001: package org.mvel.tests.perftests;
002:
003: import ognl.Ognl;
004: import org.apache.commons.el.ExpressionEvaluatorImpl;
005: import org.mvel.MVEL;
006:
007: import javax.servlet.jsp.el.Expression;
008:
009: /**
010: * @author Christopher Brock
011: */
012: public class PerfTest {
013: private String name;
014: private String expression;
015: private int runFlags;
016:
017: private Object ognlCompiled;
018: private Object mvelCompiled;
019: private Object groovyCompiled;
020:
021: private Expression elCompiled;
022: private NativeTest javaNative;
023:
024: public String getName() {
025: return name;
026: }
027:
028: public void setName(String name) {
029: this .name = name;
030: }
031:
032: public String getExpression() {
033: return expression;
034: }
035:
036: public void setExpression(String expression) {
037: this .expression = expression;
038: }
039:
040: public int getRunFlags() {
041: return runFlags;
042: }
043:
044: public void setRunFlags(int runFlags) {
045: this .runFlags = runFlags;
046: }
047:
048: public Object getOgnlCompiled() {
049: return ognlCompiled;
050: }
051:
052: public void setOgnlCompiled(Object ognlCompiled) {
053: this .ognlCompiled = ognlCompiled;
054: }
055:
056: public Object getMvelCompiled() {
057: return mvelCompiled;
058: }
059:
060: public void setMvelCompiled(Object mvelCompiled) {
061: this .mvelCompiled = mvelCompiled;
062: }
063:
064: public NativeTest getJavaNative() {
065: return javaNative;
066: }
067:
068: public void setJavaNative(NativeTest javaNative) {
069: this .javaNative = javaNative;
070: }
071:
072: public Expression getElCompiled() {
073: return elCompiled;
074: }
075:
076: public void setElCompiled(Expression elCompiled) {
077: this .elCompiled = elCompiled;
078: }
079:
080: public Object getGroovyCompiled() {
081: return groovyCompiled;
082: }
083:
084: public void setGroovyCompiled(Object groovyCompiled) {
085: this .groovyCompiled = groovyCompiled;
086: }
087:
088: public PerfTest(String name, String expression, int runFlags,
089: NativeTest javaNative) {
090: this .name = name;
091: this .expression = expression;
092: this .runFlags = runFlags;
093: this .javaNative = javaNative;
094:
095: if ((runFlags & ELComparisons.RUN_MVEL) != 0)
096: this .mvelCompiled = MVEL.compileExpression(expression);
097:
098: try {
099: if ((runFlags & ELComparisons.RUN_OGNL) != 0)
100: this .ognlCompiled = Ognl.parseExpression(expression);
101: } catch (Exception e) {
102: throw new RuntimeException(e);
103: }
104:
105: try {
106: // if ((runFlags & ELComparisons.RUN_GROOVY) != 0) {
107: // Binding binding = new Binding();
108: // GroovyShell sh = new GroovyShell(binding);
109: // this.groovyCompiled = sh.parse(expression);
110: // }
111:
112: this .ognlCompiled = Ognl.parseExpression(expression);
113: } catch (Exception e) {
114: throw new RuntimeException(e);
115: }
116:
117: ExpressionEvaluatorImpl factory = new ExpressionEvaluatorImpl();
118:
119: try {
120: if ((runFlags & ELComparisons.RUN_COMMONS_EL) != 0)
121: this .elCompiled = factory.parseExpression("${"
122: + expression + "}", Object.class, null);
123: } catch (Exception e) {
124: throw new RuntimeException(e);
125: }
126:
127: }
128:
129: }
|