├── .classpath ├── .gitignore ├── .project ├── ASM-LICENSE.txt ├── LICENSE.txt ├── build.properties ├── lib ├── asm.jar ├── commons-el-1.0.jar ├── js.jar ├── jsp-api-2.1.jar ├── junit-3.8.2.jar ├── ognl-2.6.7.jar ├── script-api.jar ├── script-js.jar ├── servlet-api-2.5.jar ├── xpp3_min-1.1.4c.jar └── xstream-1.3.1.jar ├── pom.xml ├── samples └── scripts │ ├── fquicksort.mvel │ ├── functions1.mvel │ ├── multibyte.mvel │ ├── multilinestring.mvel │ ├── quicksort.mvel │ ├── quicksort2.mvel │ ├── quicksort3.mvel │ └── randomguess.mvel └── src ├── main └── java │ └── org │ └── mvel2 │ ├── CompileException.java │ ├── ConversionException.java │ ├── ConversionHandler.java │ ├── DataConversion.java │ ├── DataTypes.java │ ├── ErrorDetail.java │ ├── ImmutableElementException.java │ ├── MVEL.java │ ├── MVELInterpretedRuntime.java │ ├── MVELRuntime.java │ ├── Macro.java │ ├── MacroProcessor.java │ ├── Operator.java │ ├── OptimizationFailure.java │ ├── ParserConfiguration.java │ ├── ParserContext.java │ ├── PreProcessor.java │ ├── PropertyAccessException.java │ ├── PropertyAccessor.java │ ├── ScriptRuntimeException.java │ ├── Unit.java │ ├── UnresolveablePropertyException.java │ ├── asm │ ├── AnnotationVisitor.java │ ├── AnnotationWriter.java │ ├── Attribute.java │ ├── ByteVector.java │ ├── ClassAdapter.java │ ├── ClassReader.java │ ├── ClassVisitor.java │ ├── ClassWriter.java │ ├── Edge.java │ ├── FieldVisitor.java │ ├── FieldWriter.java │ ├── Frame.java │ ├── Handler.java │ ├── Item.java │ ├── Label.java │ ├── MethodAdapter.java │ ├── MethodVisitor.java │ ├── MethodWriter.java │ ├── Opcodes.java │ ├── Type.java │ ├── package.html │ ├── signature │ │ ├── SignatureReader.java │ │ ├── SignatureVisitor.java │ │ ├── SignatureWriter.java │ │ └── package.html │ └── util │ │ ├── AbstractVisitor.java │ │ ├── TraceAbstractVisitor.java │ │ ├── TraceAnnotationVisitor.java │ │ ├── TraceClassVisitor.java │ │ ├── TraceFieldVisitor.java │ │ ├── TraceMethodVisitor.java │ │ ├── TraceSignatureVisitor.java │ │ └── Traceable.java │ ├── ast │ ├── ASTNode.java │ ├── And.java │ ├── ArraySize.java │ ├── AssertNode.java │ ├── Assignment.java │ ├── AssignmentNode.java │ ├── BinaryOperation.java │ ├── BlockNode.java │ ├── BooleanNode.java │ ├── Contains.java │ ├── Convertable.java │ ├── DeclProtoVarNode.java │ ├── DeclTypedVarNode.java │ ├── DeepAssignmentNode.java │ ├── DoNode.java │ ├── DoUntilNode.java │ ├── EndOfStatement.java │ ├── Fold.java │ ├── ForEachNode.java │ ├── ForNode.java │ ├── Function.java │ ├── IfNode.java │ ├── ImportNode.java │ ├── IndexedAssignmentNode.java │ ├── IndexedDeclTypedVarNode.java │ ├── IndexedOperativeAssign.java │ ├── IndexedPostFixDecNode.java │ ├── IndexedPostFixIncNode.java │ ├── IndexedPreFixDecNode.java │ ├── IndexedPreFixIncNode.java │ ├── InlineCollectionNode.java │ ├── Instance.java │ ├── IntAdd.java │ ├── IntDiv.java │ ├── IntMult.java │ ├── IntOptimized.java │ ├── IntSub.java │ ├── InterceptorWrapper.java │ ├── Invert.java │ ├── IsDef.java │ ├── LineLabel.java │ ├── LiteralDeepPropertyNode.java │ ├── LiteralNode.java │ ├── Negation.java │ ├── NestedStatement.java │ ├── NewObjectNode.java │ ├── NewPrototypeNode.java │ ├── OperativeAssign.java │ ├── OperatorNode.java │ ├── Or.java │ ├── PostFixDecNode.java │ ├── PostFixIncNode.java │ ├── PreFixDecNode.java │ ├── PreFixIncNode.java │ ├── Proto.java │ ├── ProtoVarNode.java │ ├── ReduceableCodeException.java │ ├── RedundantCodeException.java │ ├── RegExMatch.java │ ├── RegExMatchNode.java │ ├── ReturnNode.java │ ├── Safe.java │ ├── Sign.java │ ├── Soundslike.java │ ├── StaticImportNode.java │ ├── Strsim.java │ ├── Substatement.java │ ├── ThisWithNode.java │ ├── TypeCast.java │ ├── TypeDescriptor.java │ ├── TypedVarNode.java │ ├── Union.java │ ├── UntilNode.java │ ├── WhileNode.java │ └── WithNode.java │ ├── compiler │ ├── AbstractParser.java │ ├── Accessor.java │ ├── AccessorNode.java │ ├── BlankLiteral.java │ ├── CompiledAccExpression.java │ ├── CompiledExpression.java │ ├── EndWithValue.java │ ├── ExecutableAccessor.java │ ├── ExecutableAccessorSafe.java │ ├── ExecutableLiteral.java │ ├── ExecutableStatement.java │ ├── ExpressionCompiler.java │ ├── Parser.java │ └── PropertyVerifier.java │ ├── conversion │ ├── ArrayCH.java │ ├── ArrayHandler.java │ ├── BigDecimalCH.java │ ├── BigIntegerCH.java │ ├── BooleanCH.java │ ├── ByteCH.java │ ├── CharArrayCH.java │ ├── CharCH.java │ ├── Converter.java │ ├── DoubleCH.java │ ├── FloatCH.java │ ├── IntArrayCH.java │ ├── IntegerCH.java │ ├── ListCH.java │ ├── LongCH.java │ ├── ObjectCH.java │ ├── PrimIntArrayCH.java │ ├── SetCH.java │ ├── ShortCH.java │ ├── StringArrayCH.java │ ├── StringCH.java │ └── UnitConversion.java │ ├── debug │ ├── DebugTools.java │ ├── Debugger.java │ ├── DebuggerContext.java │ └── Frame.java │ ├── integration │ ├── GlobalListenerFactory.java │ ├── Interceptor.java │ ├── Listener.java │ ├── PropertyHandler.java │ ├── PropertyHandlerFactory.java │ ├── ResolverTools.java │ ├── VariableResolver.java │ ├── VariableResolverFactory.java │ └── impl │ │ ├── BaseVariableResolverFactory.java │ │ ├── CachedMapVariableResolverFactory.java │ │ ├── CachingMapVariableResolverFactory.java │ │ ├── ClassImportResolver.java │ │ ├── ClassImportResolverFactory.java │ │ ├── DefaultLocalVariableResolverFactory.java │ │ ├── FunctionVariableResolverFactory.java │ │ ├── ImmutableDefaultFactory.java │ │ ├── IndexVariableResolver.java │ │ ├── IndexedVariableResolverFactory.java │ │ ├── ItemResolverFactory.java │ │ ├── LocalVariableResolverFactory.java │ │ ├── MapVariableResolver.java │ │ ├── MapVariableResolverFactory.java │ │ ├── PrecachedMapVariableResolver.java │ │ ├── SimpleSTValueResolver.java │ │ ├── SimpleValueResolver.java │ │ ├── SimpleVariableResolverFactory.java │ │ ├── StaticMethodImportResolver.java │ │ ├── StaticMethodImportResolverFactory.java │ │ ├── TypeInjectionResolverFactory.java │ │ └── TypeInjectionResolverFactoryImpl.java │ ├── math │ └── MathProcessor.java │ ├── optimizers │ ├── AbstractOptimizer.java │ ├── AccessorOptimizer.java │ ├── OptimizationNotSupported.java │ ├── OptimizerFactory.java │ ├── OptimizerHook.java │ ├── dynamic │ │ ├── DynamicAccessor.java │ │ ├── DynamicClassLoader.java │ │ ├── DynamicCollectionAccessor.java │ │ ├── DynamicGetAccessor.java │ │ ├── DynamicOptimizer.java │ │ └── DynamicSetAccessor.java │ └── impl │ │ ├── asm │ │ ├── ASMAccessorOptimizer.java │ │ └── ProducesBytecode.java │ │ └── refl │ │ ├── ReflectiveAccessorOptimizer.java │ │ ├── collection │ │ ├── ArrayCreator.java │ │ ├── ExprValueAccessor.java │ │ ├── ListCreator.java │ │ ├── MDArrayCreator.java │ │ └── MapCreator.java │ │ └── nodes │ │ ├── ArrayAccessor.java │ │ ├── ArrayAccessorNest.java │ │ ├── ArrayLength.java │ │ ├── BaseAccessor.java │ │ ├── ConstructorAccessor.java │ │ ├── DynamicFieldAccessor.java │ │ ├── DynamicFunctionAccessor.java │ │ ├── DynamicSetterAccessor.java │ │ ├── FieldAccessor.java │ │ ├── FieldAccessorNH.java │ │ ├── FunctionAccessor.java │ │ ├── GetterAccessor.java │ │ ├── GetterAccessorNH.java │ │ ├── IndexedCharSeqAccessor.java │ │ ├── IndexedCharSeqAccessorNest.java │ │ ├── IndexedVariableAccessor.java │ │ ├── ListAccessor.java │ │ ├── ListAccessorNest.java │ │ ├── MapAccessor.java │ │ ├── MapAccessorNest.java │ │ ├── MethodAccessor.java │ │ ├── MethodAccessorNH.java │ │ ├── Notify.java │ │ ├── NullSafe.java │ │ ├── PropertyHandlerAccessor.java │ │ ├── SetterAccessor.java │ │ ├── StaticReferenceAccessor.java │ │ ├── StaticVarAccessor.java │ │ ├── StaticVarAccessorNH.java │ │ ├── ThisValueAccessor.java │ │ ├── Union.java │ │ ├── VariableAccessor.java │ │ └── WithAccessor.java │ ├── sh │ ├── Command.java │ ├── CommandException.java │ ├── CommandSet.java │ ├── DefaultEnvironment.java │ ├── Main.java │ ├── ShellSession.java │ ├── command │ │ ├── basic │ │ │ ├── BasicCommandSet.java │ │ │ ├── Exit.java │ │ │ ├── Help.java │ │ │ ├── ObjectInspector.java │ │ │ ├── PushContext.java │ │ │ ├── Set.java │ │ │ └── ShowVars.java │ │ └── file │ │ │ ├── ChangeWorkingDir.java │ │ │ ├── DirList.java │ │ │ ├── FileCommandSet.java │ │ │ └── PrintWorkingDirectory.java │ └── text │ │ └── TextUtil.java │ ├── templates │ ├── CompiledTemplate.java │ ├── SimpleTemplateRegistry.java │ ├── TemplateCompiler.java │ ├── TemplateDebug.java │ ├── TemplateError.java │ ├── TemplateRegistry.java │ ├── TemplateRuntime.java │ ├── TemplateRuntimeError.java │ ├── TemplateSyntaxError.java │ ├── res │ │ ├── CodeNode.java │ │ ├── CommentNode.java │ │ ├── CompiledCodeNode.java │ │ ├── CompiledDeclareNode.java │ │ ├── CompiledEvalNode.java │ │ ├── CompiledExpressionNode.java │ │ ├── CompiledForEachNode.java │ │ ├── CompiledIfNode.java │ │ ├── CompiledIncludeNode.java │ │ ├── CompiledNamedIncludeNode.java │ │ ├── CompiledTerminalExpressionNode.java │ │ ├── DeclareNode.java │ │ ├── EndNode.java │ │ ├── EvalNode.java │ │ ├── ExpressionNode.java │ │ ├── ForEachNode.java │ │ ├── IfNode.java │ │ ├── IncludeNode.java │ │ ├── NamedIncludeNode.java │ │ ├── Node.java │ │ ├── Opcodes.java │ │ ├── TerminalExpressionNode.java │ │ ├── TerminalNode.java │ │ └── TextNode.java │ └── util │ │ ├── ArrayIterator.java │ │ ├── CountIterator.java │ │ ├── TemplateOutputStream.java │ │ ├── TemplateTools.java │ │ └── io │ │ ├── StandardOutputStream.java │ │ ├── StringAppenderStream.java │ │ └── StringBuilderStream.java │ └── util │ ├── ASTIterator.java │ ├── ASTLinkedList.java │ ├── ArrayTools.java │ ├── CallableProxy.java │ ├── CollectionParser.java │ ├── CompilerTools.java │ ├── ErrorUtil.java │ ├── ExecutionStack.java │ ├── FastList.java │ ├── FunctionParser.java │ ├── InternalNumber.java │ ├── JITClassLoader.java │ ├── LineMapper.java │ ├── MVELClassLoader.java │ ├── Make.java │ ├── MethodStub.java │ ├── NullType.java │ ├── ParseTools.java │ ├── PropertyTools.java │ ├── ProtoParser.java │ ├── ReflectionUtil.java │ ├── SharedVariableSpaceModel.java │ ├── SimpleIndexHashMapWrapper.java │ ├── SimpleVariableSpaceModel.java │ ├── Soundex.java │ ├── Stack.java │ ├── StackElement.java │ ├── StringAppender.java │ ├── ThisLiteral.java │ ├── VariableSpaceCompiler.java │ └── VariableSpaceModel.java └── test ├── java └── org │ └── mvel2 │ ├── compiler │ └── GenericsTypeInferenceTest.java │ ├── marshalling │ └── MarshallingTest.java │ ├── tests │ ├── AccessorBMModel.java │ ├── MVEL238.mvel │ ├── core │ │ ├── AbstractTest.java │ │ ├── ArithmeticTests.java │ │ ├── ArraysTests.java │ │ ├── CommentParsingTests.java │ │ ├── ComparisonTests.java │ │ ├── ControlFlowTests.java │ │ ├── CoreConfidenceTests.java │ │ ├── DebuggerTests.java │ │ ├── FailureTests.java │ │ ├── FunctionsTest.java │ │ ├── IndexedVariablesTests.java │ │ ├── InlineCollectionsTests.java │ │ ├── IntegrationTests.java │ │ ├── LiteralParsingTests.java │ │ ├── MVELTest.java │ │ ├── MVELThreadTest.java │ │ ├── MacroProcessorTest.java │ │ ├── MutationsTests.java │ │ ├── ProjectionsTests.java │ │ ├── PropertyAccessTests.java │ │ ├── PropertyAccessUnitTest.java │ │ ├── PropertyHandlerTests.java │ │ ├── ProtoTests.java │ │ ├── RegularExpressionTests.java │ │ ├── SamplesTests.java │ │ ├── ScopeTests.java │ │ ├── TypesAndInferenceTests.java │ │ ├── UnsupportedFeaturesTests.java │ │ ├── UtilsTests.java │ │ ├── WithTests.java │ │ └── res │ │ │ ├── AStatic.java │ │ │ ├── Bar.java │ │ │ ├── Base.java │ │ │ ├── Cake.java │ │ │ ├── Cheese.java │ │ │ ├── Cheesery.java │ │ │ ├── Column.java │ │ │ ├── DefaultKnowledgeHelper.java │ │ │ ├── DerivedClass.java │ │ │ ├── FactHandle.java │ │ │ ├── Foo.java │ │ │ ├── Grid.java │ │ │ ├── KnowledgeHelper.java │ │ │ ├── KnowledgeHelperFixer.java │ │ │ ├── MapObject.java │ │ │ ├── Model.java │ │ │ ├── MyClass.java │ │ │ ├── MyEnum.java │ │ │ ├── MyInterface.java │ │ │ ├── MyInterface2.java │ │ │ ├── MyInterface3.java │ │ │ ├── MySuperInterface.java │ │ │ ├── PDFFieldUtil.java │ │ │ ├── PojoStatic.java │ │ │ ├── PresentationElements.java │ │ │ ├── RuleBase.java │ │ │ ├── RuleBaseImpl.java │ │ │ ├── SampleBean.java │ │ │ ├── SampleBeanAccessor.java │ │ │ ├── Ship.java │ │ │ ├── Status.java │ │ │ ├── Task.java │ │ │ ├── TestClass.java │ │ │ ├── TestInterface.java │ │ │ ├── TestMVEL197.java │ │ │ ├── Thing.java │ │ │ ├── User.java │ │ │ ├── Users.java │ │ │ ├── WorkingMemory.java │ │ │ ├── WorkingMemoryImpl.java │ │ │ └── res2 │ │ │ ├── ClassProvider.java │ │ │ ├── Outer.java │ │ │ ├── PrivateClass.java │ │ │ └── PublicClass.java │ ├── fuzz │ │ ├── Fuzzer.java │ │ └── IdentifierFuzzer.java │ ├── perftests │ │ ├── CompiledPerformanceTests.java │ │ ├── InlineCollectionsPerformance.java │ │ ├── NullOutputStream.java │ │ └── SimpleTests.java │ └── templates │ │ ├── TemplateTests.java │ │ ├── perfTest1.mv │ │ ├── templateDeclareTest.mv │ │ ├── templateError.mv │ │ ├── templateError2.mv │ │ ├── templateIfTest.mv │ │ ├── templateTest.mv │ │ └── tests │ │ └── res │ │ └── TestPluginNode.java │ └── util │ ├── FastListTest.java │ └── QuickSort.java └── resources └── eventing-example.jar /.classpath: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignored files deleted by mvn clean 2 | /target 3 | # Ignored files not deleted by mvn clean 4 | /local 5 | 6 | # Netbeans and IntelliJ files 7 | /.idea 8 | !.gitignore 9 | /nbproject 10 | /*.ipr 11 | /*.iws 12 | /*.iml 13 | 14 | # The META-INF directory is generated by the maven-felix-plugin 15 | /META-INF 16 | -------------------------------------------------------------------------------- /.project: -------------------------------------------------------------------------------- 1 | 2 | 3 | mvel 4 | 5 | 6 | 7 | 8 | 9 | org.eclipse.jdt.core.javabuilder 10 | 11 | 12 | 13 | 14 | org.maven.ide.eclipse.maven2Builder 15 | 16 | 17 | 18 | 19 | 20 | org.maven.ide.eclipse.maven2Nature 21 | org.eclipse.jdt.core.javanature 22 | 23 | 24 | -------------------------------------------------------------------------------- /build.properties: -------------------------------------------------------------------------------- 1 | src.includes = .,\ 2 | build.properties,\ 3 | META-INF/,\ 4 | src/,\ 5 | pom.xml 6 | bin.includes = .,\ 7 | META-INF/,\ 8 | build.properties,\ 9 | source.. = src/main/java/,\ 10 | src/main/resources/ 11 | output.. = target/classes/ 12 | jars.compile.order = . 13 | -------------------------------------------------------------------------------- /lib/asm.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/asm.jar -------------------------------------------------------------------------------- /lib/commons-el-1.0.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/commons-el-1.0.jar -------------------------------------------------------------------------------- /lib/js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/js.jar -------------------------------------------------------------------------------- /lib/jsp-api-2.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/jsp-api-2.1.jar -------------------------------------------------------------------------------- /lib/junit-3.8.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/junit-3.8.2.jar -------------------------------------------------------------------------------- /lib/ognl-2.6.7.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/ognl-2.6.7.jar -------------------------------------------------------------------------------- /lib/script-api.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/script-api.jar -------------------------------------------------------------------------------- /lib/script-js.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/script-js.jar -------------------------------------------------------------------------------- /lib/servlet-api-2.5.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/servlet-api-2.5.jar -------------------------------------------------------------------------------- /lib/xpp3_min-1.1.4c.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/xpp3_min-1.1.4c.jar -------------------------------------------------------------------------------- /lib/xstream-1.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/lib/xstream-1.3.1.jar -------------------------------------------------------------------------------- /samples/scripts/fquicksort.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.1 Script 3 | * "Functional QuickSort" 4 | * by: Mike Brock, Inspired by: Dhanji Prasanna 5 | */ 6 | 7 | def quicksort(list) { 8 | list.size() <= 1 ? list : 9 | (pivot = list[0]; (quicksort(($ in list if $ < pivot)) + pivot) 10 | + quicksort(($ in list if $ > pivot))) 11 | } 12 | 13 | // create a list to sort 14 | list = [5,2,4,1,18,10,15,1,0]; 15 | 16 | // sort it! 17 | quicksort(list); -------------------------------------------------------------------------------- /samples/scripts/functions1.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.0 Script 3 | * "Functions Demonstration" 4 | * by: Christopher Michael Brock 5 | */ 6 | 7 | def isGood(obj) { 8 | return !(obj.toLowerCase() contains "evil"); 9 | } 10 | 11 | def describe(obj) { 12 | System.out.println(obj + " is " + (isGood(obj) ? "Good" : "Evil")); 13 | } 14 | 15 | $test1 = "Mr. Good"; 16 | $test2 = "Mr. Evil"; 17 | 18 | describe($test1); 19 | describe($test2); -------------------------------------------------------------------------------- /samples/scripts/multibyte.mvel: -------------------------------------------------------------------------------- 1 | a = "?????"; -------------------------------------------------------------------------------- /samples/scripts/multilinestring.mvel: -------------------------------------------------------------------------------- 1 | 2 | System.out.println( 3 | "Hello, are you there? 4 | Is it wonderful? 5 | Did you try to escape the population?" 6 | ); 7 | 8 | -------------------------------------------------------------------------------- /samples/scripts/quicksort.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.0 Script 3 | * "QuickSort" 4 | * by: Christopher Michael Brock 5 | */ 6 | 7 | 8 | array = null; 9 | 10 | def swap(i, j) { 11 | temp = array[i]; 12 | array[i] = array[j]; 13 | array[j] = temp; 14 | } 15 | 16 | def partition(low, high) { 17 | pivotPoint = array[low]; 18 | 19 | i = low - 1; 20 | j = high + 1; 21 | 22 | while (i < j) { 23 | i++; while (array[i] < pivotPoint) ++i; 24 | j--; while (array[j] > pivotPoint) --j; 25 | if (i < j) swap(i, j); 26 | } 27 | 28 | j; //return j 29 | } 30 | 31 | def sort(low, high) { 32 | if (low < high) { 33 | var p; 34 | sort(low, p = partition(low, high)); 35 | sort(p + 1, high); 36 | } 37 | } 38 | 39 | def quicksort() { 40 | sort(0, array.length - 1); 41 | } 42 | 43 | array = {99,20,21,209,10,77,8,9,55,73,41,50}; 44 | 45 | quicksort(); 46 | 47 | array; // return array -------------------------------------------------------------------------------- /samples/scripts/quicksort2.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.0 Script 3 | * "QuickSort" 4 | * by: Christopher Michael Brock 5 | */ 6 | 7 | array = null; 8 | 9 | def swap(i, j) { 10 | temp = array[i]; 11 | array[i] = array[j]; 12 | array[j] = temp; 13 | } 14 | 15 | def partition(low, high) { 16 | pivotPoint = array[low]; 17 | 18 | i = low - 1; 19 | j = high + 1; 20 | 21 | while (i < j) { 22 | i += 1; while (array[i] < pivotPoint) i += 1; 23 | j -= 1; while (array[j] > pivotPoint) j -= 1; 24 | if (i < j) swap(i, j); 25 | } 26 | 27 | j; //return j 28 | } 29 | 30 | def sort(low, high) { 31 | if (low < high) { 32 | var p; 33 | sort(low, p = partition(low, high)); 34 | sort(p + 1, high); 35 | } 36 | } 37 | 38 | def quicksort() { 39 | sort(0, array.length - 1); 40 | } 41 | 42 | array = {50,20,21,209,10,77,8,9,55,73,41,99}; 43 | 44 | quicksort(); 45 | 46 | array; // return array -------------------------------------------------------------------------------- /samples/scripts/quicksort3.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.0 Script 3 | * "QuickSort" 4 | * by: Christopher Michael Brock 5 | */ 6 | 7 | array = null; 8 | 9 | 10 | def swap(i, j) { 11 | temp = array[i]; 12 | array[i] = array[j]; 13 | array[j] = temp; 14 | } 15 | 16 | def partition(low, high) { 17 | int pivotPoint = array[low], i = low - 1, j = high + 1; 18 | 19 | while (i < j) { 20 | i += 1; while (array[i] < pivotPoint) i += 1; 21 | j -= 1; while (array[j] > pivotPoint) j -= 1; 22 | if (i < j) swap(i, j); 23 | } 24 | 25 | j; //return j 26 | } 27 | 28 | def sort(low, high) { 29 | if (low < high) { 30 | var p; 31 | sort(low, p = partition(low, high)); 32 | sort(p + 1, high); 33 | } 34 | } 35 | 36 | def quicksort() { 37 | sort(0, array.length - 1); 38 | } 39 | 40 | array = {50,20,21,209,10,77,8,9,55,73,41,99}; 41 | 42 | quicksort(); 43 | 44 | array; // return array -------------------------------------------------------------------------------- /samples/scripts/randomguess.mvel: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample MVEL 2.0 Script 3 | * "Random Guess" 4 | * by: Christopher Michael Brock 5 | */ 6 | 7 | import java.io.*; 8 | 9 | // 10 | // Seed the random number 11 | // 12 | 13 | $num = (int) Math.random() * 100; 14 | $guesses = 0; 15 | $in = -1; 16 | 17 | // 18 | // Setup the STDIN line reader. 19 | // 20 | 21 | $linereader = new BufferedReader(new InputStreamReader(System.in)); 22 | 23 | System.out.print("I'm Thinking of a Number Between 1 and 100... Can you guess what it is? "); 24 | 25 | // 26 | // Main program loop 27 | // 28 | 29 | while ($in != $num) { 30 | if ($in != -1) { 31 | System.out.print("Nope. The number is: " + ($num < $in ? "Lower" : "Higher") + ". What's your next guess? "); 32 | } 33 | if (($in = $linereader.readLine().trim()) == empty) $in = -2; 34 | $guesses++; 35 | } 36 | 37 | System.out.println("You got it! It took you " + $guesses + " tries"); 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ConversionException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | public class ConversionException extends RuntimeException { 22 | 23 | 24 | public ConversionException(String message) { 25 | super(message); //To change body of overridden methods use File | Settings | File Templates. 26 | } 27 | 28 | public ConversionException(String message, Throwable cause) { 29 | super(message, cause); //To change body of overridden methods use File | Settings | File Templates. 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ConversionHandler.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 MVFLEX/Valhalla Project and the Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | /** 22 | * The conversion handler interface defines the basic interface for implementing conversion handlers in MVEL. 23 | * 24 | * @see org.mvel2.DataConversion 25 | */ 26 | public interface ConversionHandler { 27 | /** 28 | * Converts the passed argument to the type represented by the handler. 29 | * 30 | * @param in - the input type 31 | * @return - the converted type 32 | */ 33 | public Object convertFrom(Object in); 34 | 35 | /** 36 | * This method is used to indicate to the runtime whehter or not the handler knows how to convert 37 | * from the specified type. 38 | * 39 | * @param cls - the source type 40 | * @return - true if the converter supports converting from the specified type. 41 | */ 42 | public boolean canConvertFrom(Class cls); 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ImmutableElementException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | package org.mvel2; 21 | 22 | /** 23 | * Exception thrown by internal immutable structures if any modifications are attempted. 24 | */ 25 | public class ImmutableElementException extends RuntimeException { 26 | 27 | public ImmutableElementException() { 28 | super(); 29 | } 30 | 31 | public ImmutableElementException(String s) { 32 | super(s); 33 | } 34 | 35 | public ImmutableElementException(String s, Throwable throwable) { 36 | super(s, throwable); 37 | } 38 | 39 | public ImmutableElementException(Throwable throwable) { 40 | super(throwable); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/Macro.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | /** 22 | * @author Christopher Brock 23 | */ 24 | public interface Macro { 25 | public String doMacro(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/OptimizationFailure.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2; 19 | 20 | public class OptimizationFailure extends RuntimeException { 21 | 22 | public OptimizationFailure() { 23 | super(); 24 | } 25 | 26 | public OptimizationFailure(String message) { 27 | super(message); 28 | } 29 | 30 | public OptimizationFailure(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public OptimizationFailure(Throwable cause) { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/PreProcessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | /** 22 | * A preprocessor used for pre-processing any expressions before being parsed/compiled. 23 | */ 24 | public interface PreProcessor { 25 | public char[] parse(char[] input); 26 | 27 | public String parse(String input); 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/PropertyAccessException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2; 19 | 20 | public class PropertyAccessException extends CompileException { 21 | 22 | // public PropertyAccessException() { 23 | // super(); 24 | // } 25 | // 26 | // public PropertyAccessException(String message) { 27 | // super( message); 28 | // } 29 | // 30 | // public PropertyAccessException(String message, Throwable cause) { 31 | // super( message, cause); 32 | // } 33 | // 34 | // public PropertyAccessException(Throwable cause) { 35 | // super(cause); 36 | // } 37 | 38 | public PropertyAccessException(String message, char[] expr, int cursor, Throwable e) { 39 | super(message, expr, cursor, e); 40 | } 41 | 42 | public PropertyAccessException(String message, char[] expr, int cursor) { 43 | super(message, expr, cursor); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ScriptRuntimeException.java: -------------------------------------------------------------------------------- 1 | package org.mvel2; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public class ScriptRuntimeException extends RuntimeException { 7 | public ScriptRuntimeException() { 8 | } 9 | 10 | public ScriptRuntimeException(String message) { 11 | super(message); 12 | } 13 | 14 | public ScriptRuntimeException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public ScriptRuntimeException(Throwable cause) { 19 | super(cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/Unit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | public interface Unit extends ConversionHandler { 22 | public double getValue(); 23 | 24 | public void setValue(double value); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/UnresolveablePropertyException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2; 20 | 21 | import org.mvel2.ast.ASTNode; 22 | 23 | /** 24 | * @author Christopher Brock 25 | */ 26 | public class UnresolveablePropertyException extends RuntimeException { 27 | 28 | private String name; 29 | 30 | public UnresolveablePropertyException(ASTNode astNode, Throwable throwable) { 31 | super("unable to resolve token: " + astNode.getName(), throwable); 32 | this.name = astNode.getName(); 33 | } 34 | 35 | public UnresolveablePropertyException(ASTNode astNode) { 36 | super("unable to resolve token: " + astNode.getName()); 37 | this.name = astNode.getName(); 38 | } 39 | 40 | public UnresolveablePropertyException(String name) { 41 | super("unable to resolve token: " + name); 42 | this.name = name; 43 | } 44 | 45 | public String getName() { 46 | return name; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/asm/signature/package.html: -------------------------------------------------------------------------------- 1 | 2 | 31 | 32 | Provides support for type signatures. 33 | 34 | @since ASM 2.0 35 | 36 | 37 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/ArraySize.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import java.io.Serializable; 22 | 23 | public class ArraySize implements Serializable { 24 | public ArraySize(char[] value) { 25 | this.value = value; 26 | } 27 | 28 | public char[] value; 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Assignment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.compiler.ExecutableStatement; 22 | 23 | public interface Assignment { 24 | public String getAssignmentVar(); 25 | 26 | public char[] getExpression(); 27 | 28 | public boolean isNewDeclaration(); 29 | 30 | public void setValueStatement(ExecutableStatement stmt); 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/BlockNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.compiler.ExecutableStatement; 22 | 23 | /** 24 | * @author Christopher Brock 25 | */ 26 | public class BlockNode extends ASTNode { 27 | protected int blockStart; 28 | protected int blockOffset; 29 | 30 | protected ExecutableStatement compiledBlock; 31 | 32 | public BlockNode() { 33 | } 34 | 35 | public ExecutableStatement getCompiledBlock() { 36 | return compiledBlock; 37 | } 38 | 39 | public int getBlockStart() { 40 | return blockStart; 41 | } 42 | 43 | public int getBlockOffset() { 44 | return blockOffset; 45 | } 46 | } 47 | 48 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/BooleanNode.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | public abstract class BooleanNode extends ASTNode { 4 | protected ASTNode left; 5 | protected ASTNode right; 6 | 7 | public ASTNode getLeft() { 8 | return this.left; 9 | } 10 | 11 | public ASTNode getRight() { 12 | return this.right; 13 | } 14 | 15 | public void setLeft(ASTNode node) { 16 | this.left = node; 17 | } 18 | 19 | public void setRight(ASTNode node) { 20 | this.right = node; 21 | } 22 | 23 | public abstract void setRightMost(ASTNode right); 24 | 25 | public abstract ASTNode getRightMost(); 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Contains.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | import static org.mvel2.util.ParseTools.containsCheck; 24 | 25 | public class Contains extends ASTNode { 26 | private ASTNode stmt; 27 | private ASTNode stmt2; 28 | 29 | public Contains(ASTNode stmt, ASTNode stmt2) { 30 | this.stmt = stmt; 31 | this.stmt2 = stmt2; 32 | } 33 | 34 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 35 | return containsCheck(stmt.getReducedValueAccelerated(ctx, thisValue, factory), stmt2.getReducedValueAccelerated(ctx, thisValue, factory)); 36 | } 37 | 38 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 39 | throw new RuntimeException("operation not supported"); 40 | } 41 | 42 | public Class getEgressType() { 43 | return Boolean.class; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Convertable.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.DataConversion; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | import org.mvel2.util.CompilerTools; 6 | 7 | public class Convertable extends ASTNode { 8 | private ASTNode stmt; 9 | private ASTNode clsStmt; 10 | 11 | public Convertable(ASTNode stmt, ASTNode clsStmt) { 12 | this.stmt = stmt; 13 | this.clsStmt = clsStmt; 14 | CompilerTools.expectType(clsStmt, Class.class, true); 15 | } 16 | 17 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 18 | Object o = stmt.getReducedValueAccelerated(ctx, thisValue, factory); 19 | return o != null && DataConversion.canConvert( 20 | (Class) clsStmt.getReducedValueAccelerated(ctx, thisValue, factory), o.getClass()); 21 | 22 | } 23 | 24 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 25 | try { 26 | 27 | Object o = stmt.getReducedValue(ctx, thisValue, factory); 28 | if (o == null) return false; 29 | 30 | Class i = (Class) clsStmt.getReducedValue(ctx, thisValue, factory); 31 | if (i == null) throw new ClassCastException(); 32 | 33 | 34 | return DataConversion.canConvert(i, o.getClass()); 35 | } 36 | catch (ClassCastException e) { 37 | throw new RuntimeException("not a class reference: " + clsStmt.getName()); 38 | } 39 | 40 | } 41 | 42 | public Class getEgressType() { 43 | return Boolean.class; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/EndOfStatement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.Operator; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | 24 | /** 25 | * @author Christopher Brock 26 | */ 27 | public class EndOfStatement extends ASTNode { 28 | public EndOfStatement() { 29 | this.literal = getOperator(); 30 | } 31 | 32 | public boolean isOperator() { 33 | return true; 34 | } 35 | 36 | public boolean isOperator(Integer operator) { 37 | return operator == Operator.END_OF_STMT; 38 | } 39 | 40 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 41 | return null; 42 | } 43 | 44 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 45 | return null; 46 | } 47 | 48 | public Integer getOperator() { 49 | return Operator.END_OF_STMT; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IndexedPostFixIncNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.DataTypes; 22 | import org.mvel2.Operator; 23 | import org.mvel2.ParserContext; 24 | import org.mvel2.integration.VariableResolver; 25 | import org.mvel2.integration.VariableResolverFactory; 26 | import org.mvel2.math.MathProcessor; 27 | 28 | /** 29 | * @author Christopher Brock 30 | */ 31 | public class IndexedPostFixIncNode extends ASTNode { 32 | private int register; 33 | 34 | public IndexedPostFixIncNode(int register, ParserContext pCtx) { 35 | this.register = register; 36 | this.egressType = pCtx.getVarOrInputType(pCtx.getIndexedVarNames()[register]); 37 | } 38 | 39 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 40 | VariableResolver vResolver = factory.getIndexedVariableResolver(register); 41 | vResolver.setValue(MathProcessor.doOperations(ctx = vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1)); 42 | return ctx; 43 | } 44 | 45 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 46 | return getReducedValueAccelerated(ctx, thisValue, factory); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IndexedPreFixDecNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.DataTypes; 21 | import org.mvel2.Operator; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolver; 24 | import org.mvel2.integration.VariableResolverFactory; 25 | import org.mvel2.math.MathProcessor; 26 | 27 | /** 28 | * @author Christopher Brock 29 | */ 30 | public class IndexedPreFixDecNode extends ASTNode { 31 | private int register; 32 | 33 | public IndexedPreFixDecNode(int register, ParserContext pCtx) { 34 | this.register = register; 35 | this.egressType = pCtx.getVarOrInputType(pCtx.getIndexedVarNames()[register]); 36 | } 37 | 38 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 39 | VariableResolver vResolver = factory.getIndexedVariableResolver(register); 40 | vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.SUB, DataTypes.INTEGER, 1)); 41 | return ctx; 42 | } 43 | 44 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 45 | return getReducedValueAccelerated(ctx, thisValue, factory); 46 | } 47 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IndexedPreFixIncNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.DataTypes; 22 | import org.mvel2.Operator; 23 | import org.mvel2.ParserContext; 24 | import org.mvel2.integration.VariableResolver; 25 | import org.mvel2.integration.VariableResolverFactory; 26 | import org.mvel2.math.MathProcessor; 27 | 28 | /** 29 | * @author Christopher Brock 30 | */ 31 | public class IndexedPreFixIncNode extends ASTNode { 32 | private int register; 33 | 34 | public IndexedPreFixIncNode(int register, ParserContext pCtx) { 35 | this.register = register; 36 | this.egressType = pCtx.getVarOrInputType(pCtx.getIndexedVarNames()[register]); 37 | } 38 | 39 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 40 | VariableResolver vResolver = factory.getIndexedVariableResolver(register); 41 | vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1)); 42 | return ctx; 43 | } 44 | 45 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 46 | return getReducedValueAccelerated(ctx, thisValue, factory); 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Instance.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.integration.VariableResolverFactory; 4 | import org.mvel2.util.CompilerTools; 5 | 6 | 7 | public class Instance extends ASTNode { 8 | private ASTNode stmt; 9 | private ASTNode clsStmt; 10 | 11 | public Instance(ASTNode stmt, ASTNode clsStmt) { 12 | this.stmt = stmt; 13 | this.clsStmt = clsStmt; 14 | CompilerTools.expectType(clsStmt, Class.class, true); 15 | } 16 | 17 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 18 | return ((Class) clsStmt.getReducedValueAccelerated(ctx, thisValue, factory)).isInstance(stmt.getReducedValueAccelerated(ctx, thisValue, factory)); 19 | } 20 | 21 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 22 | try { 23 | Class i = (Class) clsStmt.getReducedValue(ctx, thisValue, factory); 24 | if (i == null) throw new ClassCastException(); 25 | 26 | return i.isInstance(stmt.getReducedValue(ctx, thisValue, factory)); 27 | } 28 | catch (ClassCastException e) { 29 | throw new RuntimeException("not a class reference: " + clsStmt.getName()); 30 | } 31 | 32 | } 33 | 34 | public Class getEgressType() { 35 | return Boolean.class; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IntAdd.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.Operator; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | 6 | public class IntAdd extends BinaryOperation implements IntOptimized { 7 | public IntAdd(ASTNode left, ASTNode right) { 8 | super(Operator.ADD); 9 | this.left = left; 10 | this.right = right; 11 | } 12 | 13 | @Override 14 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 15 | return ((Integer) left.getReducedValueAccelerated(ctx, thisValue, factory)) 16 | + ((Integer) right.getReducedValueAccelerated(ctx, thisValue, factory)); 17 | } 18 | 19 | @Override 20 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 21 | return ((Integer) left.getReducedValue(ctx, thisValue, factory)) 22 | + ((Integer) right.getReducedValue(ctx, thisValue, factory)); 23 | } 24 | 25 | @Override 26 | public Class getEgressType() { 27 | return Integer.class; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IntDiv.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.Operator; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | 6 | 7 | public class IntDiv extends BinaryOperation implements IntOptimized { 8 | public IntDiv(ASTNode left, ASTNode right) { 9 | super(Operator.MULT); 10 | this.left = left; 11 | this.right = right; 12 | } 13 | 14 | @Override 15 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 16 | return ((Integer) left.getReducedValueAccelerated(ctx, thisValue, factory)) 17 | / ((Integer) right.getReducedValueAccelerated(ctx, thisValue, factory)); 18 | } 19 | 20 | @Override 21 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 22 | return ((Integer) left.getReducedValue(ctx, thisValue, factory)) 23 | / ((Integer) right.getReducedValue(ctx, thisValue, factory)); 24 | } 25 | 26 | @Override 27 | public void setRight(ASTNode node) { 28 | super.setRight(node); 29 | } 30 | 31 | @Override 32 | public Class getEgressType() { 33 | return Integer.class; 34 | } 35 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IntMult.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.Operator; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | 6 | 7 | public class IntMult extends BinaryOperation implements IntOptimized { 8 | public IntMult(ASTNode left, ASTNode right) { 9 | super(Operator.MULT); 10 | this.left = left; 11 | this.right = right; 12 | } 13 | 14 | @Override 15 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 16 | return ((Integer) left.getReducedValueAccelerated(ctx, thisValue, factory)) 17 | * ((Integer) right.getReducedValueAccelerated(ctx, thisValue, factory)); 18 | } 19 | 20 | @Override 21 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 22 | return ((Integer) left.getReducedValue(ctx, thisValue, factory)) 23 | * ((Integer) right.getReducedValue(ctx, thisValue, factory)); 24 | } 25 | 26 | @Override 27 | public Class getEgressType() { 28 | return Integer.class; 29 | } 30 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IntOptimized.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | public interface IntOptimized { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IntSub.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.Operator; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | 6 | 7 | public class IntSub extends BinaryOperation implements IntOptimized { 8 | public IntSub(ASTNode left, ASTNode right) { 9 | super(Operator.SUB); 10 | this.left = left; 11 | this.right = right; 12 | } 13 | 14 | @Override 15 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 16 | return ((Integer) left.getReducedValueAccelerated(ctx, thisValue, factory)) 17 | - ((Integer) right.getReducedValueAccelerated(ctx, thisValue, factory)); 18 | } 19 | 20 | @Override 21 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 22 | return ((Integer) left.getReducedValue(ctx, thisValue, factory)) 23 | - ((Integer) right.getReducedValue(ctx, thisValue, factory)); 24 | } 25 | 26 | 27 | @Override 28 | public Class getEgressType() { 29 | return Integer.class; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/InterceptorWrapper.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.integration.Interceptor; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | 24 | /** 25 | * @author Christopher Brock 26 | */ 27 | public class InterceptorWrapper extends ASTNode { 28 | private Interceptor interceptor; 29 | private ASTNode node; 30 | 31 | public InterceptorWrapper(Interceptor interceptor, ASTNode node) { 32 | this.interceptor = interceptor; 33 | this.node = node; 34 | } 35 | 36 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 37 | interceptor.doBefore(node, factory); 38 | interceptor.doAfter(ctx = node.getReducedValueAccelerated(ctx, thisValue, factory), node, factory); 39 | return ctx; 40 | } 41 | 42 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 43 | interceptor.doBefore(node, factory); 44 | interceptor.doAfter(ctx = node.getReducedValue(ctx, thisValue, factory), node, factory); 45 | return ctx; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/IsDef.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | import static org.mvel2.util.PropertyTools.getFieldOrAccessor; 24 | 25 | public class IsDef extends ASTNode { 26 | public IsDef(char[] expr, int start, int offset) { 27 | this.nameCache = new String(this.expr = expr, this.start = start, this.offset = offset); 28 | } 29 | 30 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 31 | return factory.isResolveable(nameCache) || (thisValue != null && getFieldOrAccessor(thisValue.getClass(), nameCache) != null); 32 | } 33 | 34 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 35 | return factory.isResolveable(nameCache) || (thisValue != null && getFieldOrAccessor(thisValue.getClass(), nameCache) != null); 36 | 37 | } 38 | 39 | public Class getEgressType() { 40 | return Boolean.class; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/NestedStatement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.compiler.ExecutableStatement; 21 | 22 | /** 23 | * @author Christopher Brock 24 | */ 25 | public interface NestedStatement { 26 | public ExecutableStatement getNestedStatement(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/NewPrototypeNode.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.integration.VariableResolverFactory; 4 | 5 | public class NewPrototypeNode extends ASTNode { 6 | private String protoName; 7 | 8 | public NewPrototypeNode(TypeDescriptor t) { 9 | this.protoName = t.getClassName(); 10 | } 11 | 12 | @Override 13 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 14 | return ((Proto) factory.getVariableResolver(protoName).getValue()) 15 | .newInstance(ctx, thisValue, factory); 16 | } 17 | 18 | @Override 19 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 20 | return ((Proto) factory.getVariableResolver(protoName).getValue()) 21 | .newInstance(ctx, thisValue, factory); 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/OperatorNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.CompileException; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | 24 | import static org.mvel2.debug.DebugTools.getOperatorSymbol; 25 | 26 | public class OperatorNode extends ASTNode { 27 | private Integer operator; 28 | 29 | public OperatorNode(Integer operator, char[] expr, int start) { 30 | assert operator != null; 31 | this.expr = expr; 32 | this.literal = this.operator = operator; 33 | this.start = start; 34 | } 35 | 36 | public boolean isOperator() { 37 | return true; 38 | } 39 | 40 | public boolean isOperator(Integer operator) { 41 | return operator.equals(this.operator); 42 | } 43 | 44 | public Integer getOperator() { 45 | return operator; 46 | } 47 | 48 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 49 | throw new CompileException("illegal use of operator: " + getOperatorSymbol(operator), expr, start); 50 | } 51 | 52 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 53 | throw new CompileException("illegal use of operator: " + getOperatorSymbol(operator), expr, start); 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/PostFixDecNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.DataTypes; 21 | import org.mvel2.Operator; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolver; 24 | import org.mvel2.integration.VariableResolverFactory; 25 | import org.mvel2.math.MathProcessor; 26 | 27 | /** 28 | * @author Christopher Brock 29 | */ 30 | public class PostFixDecNode extends ASTNode { 31 | private String name; 32 | 33 | public PostFixDecNode(String name, ParserContext pCtx) { 34 | this.name = name; 35 | if (pCtx != null) { 36 | this.egressType = pCtx.getVarOrInputType(name); 37 | } 38 | } 39 | 40 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 41 | VariableResolver vResolver = factory.getVariableResolver(name); 42 | vResolver.setValue(MathProcessor.doOperations(ctx = vResolver.getValue(), Operator.SUB, DataTypes.INTEGER, 1)); 43 | return ctx; 44 | } 45 | 46 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 47 | return getReducedValueAccelerated(ctx, thisValue, factory); 48 | } 49 | 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/PostFixIncNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.DataTypes; 21 | import org.mvel2.Operator; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolver; 24 | import org.mvel2.integration.VariableResolverFactory; 25 | import org.mvel2.math.MathProcessor; 26 | 27 | /** 28 | * @author Christopher Brock 29 | */ 30 | public class PostFixIncNode extends ASTNode { 31 | private String name; 32 | 33 | public PostFixIncNode(String name, ParserContext pCtx) { 34 | this.name = name; 35 | if (pCtx != null) { 36 | this.egressType = pCtx.getVarOrInputType(name); 37 | } 38 | } 39 | 40 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 41 | VariableResolver vResolver = factory.getVariableResolver(name); 42 | vResolver.setValue(MathProcessor.doOperations(ctx = vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1)); 43 | return ctx; 44 | } 45 | 46 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 47 | return getReducedValueAccelerated(ctx, thisValue, factory); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/PreFixDecNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.DataTypes; 21 | import org.mvel2.Operator; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolver; 24 | import org.mvel2.integration.VariableResolverFactory; 25 | import org.mvel2.math.MathProcessor; 26 | 27 | /** 28 | * @author Christopher Brock 29 | */ 30 | public class PreFixDecNode extends ASTNode { 31 | private String name; 32 | 33 | public PreFixDecNode(String name, ParserContext pCtx) { 34 | this.name = name; 35 | if (pCtx != null) { 36 | this.egressType = pCtx.getVarOrInputType(name); 37 | } 38 | } 39 | 40 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 41 | VariableResolver vResolver = factory.getVariableResolver(name); 42 | vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.SUB, DataTypes.INTEGER, 1)); 43 | return ctx; 44 | } 45 | 46 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 47 | return getReducedValueAccelerated(ctx, thisValue, factory); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/PreFixIncNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | import org.mvel2.DataTypes; 21 | import org.mvel2.Operator; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolver; 24 | import org.mvel2.integration.VariableResolverFactory; 25 | import org.mvel2.math.MathProcessor; 26 | 27 | 28 | /** 29 | * @author Christopher Brock 30 | */ 31 | public class PreFixIncNode extends ASTNode { 32 | private String name; 33 | 34 | public PreFixIncNode(String name, ParserContext pCtx) { 35 | this.name = name; 36 | if (pCtx != null) { 37 | this.egressType = pCtx.getVarOrInputType(name); 38 | } 39 | } 40 | 41 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 42 | VariableResolver vResolver = factory.getVariableResolver(name); 43 | vResolver.setValue(ctx = MathProcessor.doOperations(vResolver.getValue(), Operator.ADD, DataTypes.INTEGER, 1)); 44 | return ctx; 45 | } 46 | 47 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 48 | return getReducedValueAccelerated(ctx, thisValue, factory); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/ReduceableCodeException.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | public class ReduceableCodeException extends RuntimeException { 4 | private Object literal; 5 | 6 | public Object getLiteral() { 7 | return literal; 8 | } 9 | 10 | public ReduceableCodeException(Object literal) { 11 | this.literal = literal; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/RedundantCodeException.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | public class RedundantCodeException extends RuntimeException { 4 | } 5 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/RegExMatchNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.ast; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | import static java.lang.String.valueOf; 24 | import static java.util.regex.Pattern.compile; 25 | import static org.mvel2.MVEL.eval; 26 | 27 | public class RegExMatchNode extends ASTNode { 28 | private ASTNode node; 29 | private ASTNode patternNode; 30 | 31 | public RegExMatchNode(ASTNode matchNode, ASTNode patternNode) { 32 | this.node = matchNode; 33 | this.patternNode = patternNode; 34 | } 35 | 36 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 37 | return compile(valueOf(patternNode.getReducedValueAccelerated(ctx, thisValue, factory))).matcher(valueOf(node.getReducedValueAccelerated(ctx, thisValue, factory))).matches(); 38 | } 39 | 40 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 41 | return compile(valueOf(eval(expr, patternNode.start, patternNode.offset, ctx, factory))) 42 | .matcher(valueOf(eval(expr, node.start, node.offset, ctx, factory))).matches(); 43 | } 44 | 45 | public Class getEgressType() { 46 | return Boolean.class; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Safe.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.ast; 19 | 20 | /** 21 | * Marker interface to tell MVEL it can safely hard-reference. 22 | */ 23 | public interface Safe { 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Soundslike.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.CompileException; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | import org.mvel2.util.CompilerTools; 6 | 7 | import static org.mvel2.util.Soundex.soundex; 8 | 9 | public class Soundslike extends ASTNode { 10 | private ASTNode stmt; 11 | private ASTNode soundslike; 12 | 13 | public Soundslike(ASTNode stmt, ASTNode clsStmt) { 14 | this.stmt = stmt; 15 | this.soundslike = clsStmt; 16 | CompilerTools.expectType(clsStmt, String.class, true); 17 | } 18 | 19 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 20 | return soundex(String.valueOf(soundslike.getReducedValueAccelerated(ctx, thisValue, factory))) 21 | .equals(soundex((String) stmt.getReducedValueAccelerated(ctx, thisValue, factory))); 22 | } 23 | 24 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 25 | try { 26 | String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory)); 27 | if (i == null) throw new ClassCastException(); 28 | 29 | String x = (String) stmt.getReducedValue(ctx, thisValue, factory); 30 | if (x == null) throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), stmt.getStart()); 31 | 32 | return soundex(i).equals(soundex(x)); 33 | } 34 | catch (ClassCastException e) { 35 | throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart()); 36 | } 37 | 38 | } 39 | 40 | public Class getEgressType() { 41 | return Boolean.class; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/ast/Strsim.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.ast; 2 | 3 | import org.mvel2.CompileException; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | import org.mvel2.util.CompilerTools; 6 | 7 | import static org.mvel2.util.ParseTools.similarity; 8 | 9 | public class Strsim extends ASTNode { 10 | private ASTNode stmt; 11 | private ASTNode soundslike; 12 | 13 | public Strsim(ASTNode stmt, ASTNode clsStmt) { 14 | this.stmt = stmt; 15 | this.soundslike = clsStmt; 16 | CompilerTools.expectType(clsStmt, String.class, true); 17 | } 18 | 19 | public Object getReducedValueAccelerated(Object ctx, Object thisValue, VariableResolverFactory factory) { 20 | return similarity(String.valueOf(soundslike.getReducedValueAccelerated(ctx, thisValue, factory)), 21 | ((String) stmt.getReducedValueAccelerated(ctx, thisValue, factory))); 22 | } 23 | 24 | public Object getReducedValue(Object ctx, Object thisValue, VariableResolverFactory factory) { 25 | try { 26 | String i = String.valueOf(soundslike.getReducedValue(ctx, thisValue, factory)); 27 | if (i == null) throw new ClassCastException(); 28 | 29 | String x = (String) stmt.getReducedValue(ctx, thisValue, factory); 30 | if (x == null) throw new CompileException("not a string: " + stmt.getName(), stmt.getExpr(), getStart()); 31 | 32 | return similarity(i, x); 33 | } 34 | catch (ClassCastException e) { 35 | throw new CompileException("not a string: " + soundslike.getName(), soundslike.getExpr(), soundslike.getStart()); 36 | } 37 | 38 | } 39 | 40 | public Class getEgressType() { 41 | return Boolean.class; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/Accessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.compiler; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | public interface Accessor { 24 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory); 25 | 26 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value); 27 | 28 | public Class getKnownEgressType(); 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/AccessorNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.compiler; 20 | 21 | import java.io.Serializable; 22 | 23 | public interface AccessorNode extends Accessor, Serializable { 24 | public AccessorNode getNextNode(); 25 | 26 | public AccessorNode setNextNode(AccessorNode accessorNode); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/BlankLiteral.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.compiler; 20 | 21 | import java.io.Serializable; 22 | import java.util.Collection; 23 | 24 | import static java.lang.String.valueOf; 25 | import static java.lang.reflect.Array.getLength; 26 | import static org.mvel2.util.ParseTools.isNumeric; 27 | 28 | public class BlankLiteral implements Serializable { 29 | public static final BlankLiteral INSTANCE = new BlankLiteral(); 30 | 31 | public BlankLiteral() { 32 | } 33 | 34 | public boolean equals(Object obj) { 35 | if (obj == null || "".equals(valueOf(obj))) { 36 | return true; 37 | } 38 | else if (isNumeric(obj)) { 39 | return "0".equals(valueOf(obj)); 40 | } 41 | else if (obj instanceof Collection) { 42 | return ((Collection) obj).size() == 0; 43 | } 44 | else if (obj.getClass().isArray()) { 45 | return getLength(obj) == 0; 46 | } 47 | return false; 48 | } 49 | 50 | public String toString() { 51 | return ""; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/EndWithValue.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.compiler; 20 | 21 | /** 22 | * @author Christopher Brock 23 | */ 24 | public class EndWithValue extends RuntimeException { 25 | private Object value; 26 | 27 | 28 | public EndWithValue(Object value) { 29 | this.value = value; 30 | } 31 | 32 | public Object getValue() { 33 | return value; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/ExecutableStatement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.compiler; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | import java.io.Serializable; 24 | 25 | public interface ExecutableStatement extends Accessor, Serializable, Cloneable { 26 | public Object getValue(Object staticContext, VariableResolverFactory factory); 27 | 28 | public void setKnownIngressType(Class type); 29 | 30 | public void setKnownEgressType(Class type); 31 | 32 | public Class getKnownIngressType(); 33 | 34 | public Class getKnownEgressType(); 35 | 36 | public boolean isExplicitCast(); 37 | 38 | public boolean isConvertableIngressEgress(); 39 | 40 | public void computeTypeConversionRule(); 41 | 42 | public boolean intOptimized(); 43 | 44 | public boolean isLiteralOnly(); 45 | 46 | public boolean isEmptyStatement(); 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/compiler/Parser.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.compiler; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public interface Parser { 7 | public int getCursor(); 8 | 9 | public char[] getExpression(); 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/CharArrayCH.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.conversion; 20 | 21 | import org.mvel2.ConversionException; 22 | import org.mvel2.ConversionHandler; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class CharArrayCH implements ConversionHandler { 28 | private static final Map CNV = 29 | new HashMap(); 30 | 31 | 32 | public Object convertFrom(Object in) { 33 | if (!CNV.containsKey(in.getClass())) throw new ConversionException("cannot convert type: " 34 | + in.getClass().getName() + " to: " + Boolean.class.getName()); 35 | return CNV.get(in.getClass()).convert(in); 36 | } 37 | 38 | 39 | public boolean canConvertFrom(Class cls) { 40 | return CNV.containsKey(cls); 41 | } 42 | 43 | static { 44 | CNV.put(String.class, 45 | new Converter() { 46 | public Object convert(Object o) { 47 | return ((String) o).toCharArray(); 48 | } 49 | } 50 | ); 51 | 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/Converter.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | package org.mvel2.conversion; 21 | 22 | public interface Converter { 23 | public Object convert(Object o); 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/ListCH.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | 20 | package org.mvel2.conversion; 21 | 22 | import org.mvel2.ConversionHandler; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Arrays; 26 | import java.util.Collection; 27 | import java.util.List; 28 | 29 | public class ListCH implements ConversionHandler { 30 | public Object convertFrom(Object in) { 31 | Class type = in.getClass(); 32 | List newList = new ArrayList(); 33 | if (type.isArray()) { 34 | newList.addAll(Arrays.asList(((Object[]) in))); 35 | } 36 | else if (Collection.class.isAssignableFrom(type)) { 37 | newList.addAll((Collection) in); 38 | } 39 | else if (Iterable.class.isAssignableFrom(type)) { 40 | for (Object o : (Iterable) in) { 41 | newList.add(o); 42 | } 43 | } 44 | 45 | return newList; 46 | } 47 | 48 | public boolean canConvertFrom(Class cls) { 49 | return cls.isArray() || Collection.class.isAssignableFrom(cls) || Iterable.class.isAssignableFrom(cls); 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/ObjectCH.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.conversion; 20 | 21 | import org.mvel2.ConversionHandler; 22 | 23 | public class ObjectCH implements ConversionHandler { 24 | public Object convertFrom(Object in) { 25 | return in; 26 | } 27 | 28 | 29 | public boolean canConvertFrom(Class cls) { 30 | return true; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/SetCH.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.conversion; 20 | 21 | import org.mvel2.ConversionHandler; 22 | 23 | import java.util.Arrays; 24 | import java.util.Collection; 25 | import java.util.LinkedHashSet; 26 | import java.util.Set; 27 | 28 | public class SetCH implements ConversionHandler { 29 | public Object convertFrom(Object in) { 30 | Class type = in.getClass(); 31 | Set newSet = new LinkedHashSet(); 32 | if (type.isArray()) { 33 | newSet.addAll(Arrays.asList(((Object[]) in))); 34 | } 35 | else if (Collection.class.isAssignableFrom(type)) { 36 | newSet.addAll((Collection) in); 37 | } 38 | else if (Iterable.class.isAssignableFrom(type)) { 39 | for (Object o : (Iterable) in) { 40 | newSet.add(o); 41 | } 42 | } 43 | 44 | return newSet; 45 | } 46 | 47 | public boolean canConvertFrom(Class cls) { 48 | return cls.isArray() || Collection.class.isAssignableFrom(cls) || Iterable.class.isAssignableFrom(cls); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/StringCH.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.conversion; 20 | 21 | import org.mvel2.ConversionHandler; 22 | import org.mvel2.compiler.BlankLiteral; 23 | 24 | import static java.lang.String.valueOf; 25 | 26 | public class StringCH implements ConversionHandler { 27 | public Object convertFrom(Object in) { 28 | return valueOf(in); 29 | } 30 | 31 | 32 | public boolean canConvertFrom(Class cls) { 33 | return cls != BlankLiteral.class; 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/conversion/UnitConversion.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.conversion; 20 | 21 | import org.mvel2.ConversionHandler; 22 | import org.mvel2.Unit; 23 | 24 | 25 | public class UnitConversion implements ConversionHandler { 26 | public Object convertFrom(Object in) { 27 | try { 28 | return Unit.class.newInstance().convertFrom(in); 29 | } 30 | catch (InstantiationException e) { 31 | e.printStackTrace(); 32 | } 33 | catch (IllegalAccessException e) { 34 | e.printStackTrace(); 35 | } 36 | return null; 37 | } 38 | 39 | public boolean canConvertFrom(Class cls) { 40 | if (Unit.class.isAssignableFrom(cls) || Number.class.isAssignableFrom(cls)) { 41 | try { 42 | return Unit.class.newInstance().canConvertFrom(cls); 43 | } 44 | catch (InstantiationException e) { 45 | e.printStackTrace(); 46 | } 47 | catch (IllegalAccessException e) { 48 | e.printStackTrace(); 49 | } 50 | } 51 | return false; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/debug/Debugger.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.debug; 20 | 21 | public interface Debugger { 22 | public static int CONTINUE = 0; 23 | public static int STEP = 1; 24 | public static int STEP_OVER = STEP; 25 | 26 | 27 | /** 28 | * When a breakpoint is recached, 29 | * 30 | * @param frame 31 | * @return continuation command 32 | */ 33 | public int onBreak(Frame frame); 34 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/debug/Frame.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.debug; 20 | 21 | import org.mvel2.ParserContext; 22 | import org.mvel2.ast.LineLabel; 23 | import org.mvel2.integration.VariableResolverFactory; 24 | 25 | public class Frame { 26 | private LineLabel label; 27 | private VariableResolverFactory factory; 28 | private ParserContext parserContext; 29 | 30 | public Frame(LineLabel label, VariableResolverFactory factory, ParserContext pCtx) { 31 | this.label = label; 32 | this.factory = factory; 33 | this.parserContext = pCtx; 34 | } 35 | 36 | public String getSourceName() { 37 | return label.getSourceFile(); 38 | } 39 | 40 | public int getLineNumber() { 41 | return label.getLineNumber(); 42 | } 43 | 44 | public VariableResolverFactory getFactory() { 45 | return factory; 46 | } 47 | 48 | public void setFactory(VariableResolverFactory factory) { 49 | this.factory = factory; 50 | } 51 | 52 | public ParserContext getParserContext() { 53 | return parserContext; 54 | } 55 | 56 | public void setParserContext(ParserContext parserContext) { 57 | this.parserContext = parserContext; 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/GlobalListenerFactory.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.integration; 2 | 3 | import java.util.LinkedList; 4 | import java.util.List; 5 | 6 | public class GlobalListenerFactory { 7 | private static List propertyGetListeners; 8 | private static List propertySetListeners; 9 | 10 | public static boolean hasGetListeners() { 11 | return propertyGetListeners != null && !propertyGetListeners.isEmpty(); 12 | } 13 | 14 | public static boolean hasSetListeners() { 15 | return propertySetListeners != null && !propertySetListeners.isEmpty(); 16 | } 17 | 18 | public static boolean registerGetListener(Listener getListener) { 19 | if (propertyGetListeners == null) propertyGetListeners = new LinkedList(); 20 | return propertyGetListeners.add(getListener); 21 | } 22 | 23 | public static boolean registerSetListener(Listener getListener) { 24 | if (propertySetListeners == null) propertySetListeners = new LinkedList(); 25 | return propertySetListeners.add(getListener); 26 | } 27 | 28 | 29 | public static void notifyGetListeners(Object target, String name, VariableResolverFactory variableFactory) { 30 | if (propertyGetListeners != null) { 31 | for (Listener l : propertyGetListeners) { 32 | l.onEvent(target, name, variableFactory, null); 33 | } 34 | } 35 | } 36 | 37 | public static void notifySetListeners(Object target, String name, VariableResolverFactory variableFactory, Object value) { 38 | if (propertySetListeners != null) { 39 | for (Listener l : propertySetListeners) { 40 | l.onEvent(target, name, variableFactory, value); 41 | } 42 | } 43 | } 44 | 45 | public static void disposeAll() { 46 | propertyGetListeners = null; 47 | propertySetListeners = null; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/Listener.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.integration; 2 | 3 | public interface Listener { 4 | public void onEvent(Object context, String contextName, VariableResolverFactory variableFactory, Object value); 5 | } 6 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/ClassImportResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.integration.impl; 20 | 21 | import org.mvel2.integration.VariableResolver; 22 | 23 | public class ClassImportResolver implements VariableResolver { 24 | private String name; 25 | private Class type; 26 | 27 | public ClassImportResolver(String fqcn, String name) { 28 | this.name = name; 29 | try { 30 | this.type = Class.forName(fqcn, true, Thread.currentThread().getContextClassLoader()); 31 | } 32 | catch (Exception e) { 33 | throw new RuntimeException("failed import", e); 34 | } 35 | } 36 | 37 | public ClassImportResolver(String name, Class type) { 38 | this.name = name; 39 | this.type = type; 40 | } 41 | 42 | public void setName(String name) { 43 | this.name = name; 44 | } 45 | 46 | public void setStaticType(Class knownType) { 47 | this.type = knownType; 48 | } 49 | 50 | public String getName() { 51 | return name; 52 | } 53 | 54 | public Class getType() { 55 | return Class.class; 56 | } 57 | 58 | public Object getValue() { 59 | return type; 60 | } 61 | 62 | public int getFlags() { 63 | return 0; 64 | } 65 | 66 | public void setValue(Object value) { 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/IndexVariableResolver.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.integration.impl; 2 | 3 | import org.mvel2.integration.VariableResolver; 4 | 5 | public class IndexVariableResolver implements VariableResolver { 6 | private int indexPos; 7 | private Object[] vars; 8 | 9 | public IndexVariableResolver(int indexPos, Object[] vars) { 10 | this.indexPos = indexPos; 11 | this.vars = vars; 12 | } 13 | 14 | public String getName() { 15 | return null; 16 | } 17 | 18 | public Class getType() { 19 | return null; 20 | } 21 | 22 | public void setStaticType(Class type) { 23 | } 24 | 25 | public int getFlags() { 26 | return 0; 27 | } 28 | 29 | public Object getValue() { 30 | return vars[indexPos]; 31 | } 32 | 33 | public void setValue(Object value) { 34 | vars[indexPos] = value; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/LocalVariableResolverFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.integration.impl; 20 | 21 | public interface LocalVariableResolverFactory { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/PrecachedMapVariableResolver.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.integration.impl; 2 | 3 | import org.mvel2.integration.VariableResolver; 4 | 5 | import java.util.Map; 6 | 7 | import static org.mvel2.DataConversion.canConvert; 8 | import static org.mvel2.DataConversion.convert; 9 | 10 | public class PrecachedMapVariableResolver implements VariableResolver { 11 | private String name; 12 | private Class knownType; 13 | private Map.Entry entry; 14 | 15 | public PrecachedMapVariableResolver(Map.Entry entry, String name) { 16 | this.entry = entry; 17 | this.name = name; 18 | } 19 | 20 | public PrecachedMapVariableResolver(Map.Entry entry, String name, Class knownType) { 21 | this.name = name; 22 | this.knownType = knownType; 23 | this.entry = entry; 24 | } 25 | 26 | public void setName(String name) { 27 | this.name = name; 28 | } 29 | 30 | public void setStaticType(Class knownType) { 31 | this.knownType = knownType; 32 | } 33 | 34 | 35 | public String getName() { 36 | return name; 37 | } 38 | 39 | public Class getType() { 40 | return knownType; 41 | } 42 | 43 | public void setValue(Object value) { 44 | if (knownType != null && value != null && value.getClass() != knownType) { 45 | Class t = value.getClass(); 46 | if (!canConvert(knownType, t)) { 47 | throw new RuntimeException("cannot assign " + value.getClass().getName() + " to type: " 48 | + knownType.getName()); 49 | } 50 | try { 51 | value = convert(value, knownType); 52 | } 53 | catch (Exception e) { 54 | throw new RuntimeException("cannot convert value of " + value.getClass().getName() 55 | + " to: " + knownType.getName()); 56 | } 57 | } 58 | 59 | //noinspection unchecked 60 | entry.setValue(value); 61 | } 62 | 63 | public Object getValue() { 64 | return entry.getValue(); 65 | } 66 | 67 | public int getFlags() { 68 | return 0; 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/SimpleValueResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.integration.impl; 20 | 21 | import org.mvel2.integration.VariableResolver; 22 | 23 | public class SimpleValueResolver implements VariableResolver { 24 | private Object value; 25 | 26 | public SimpleValueResolver(Object value) { 27 | this.value = value; 28 | } 29 | 30 | public String getName() { 31 | return null; 32 | } 33 | 34 | public Class getType() { 35 | return Object.class; 36 | } 37 | 38 | public void setStaticType(Class type) { 39 | } 40 | 41 | public int getFlags() { 42 | return 0; 43 | } 44 | 45 | public Object getValue() { 46 | return value; 47 | } 48 | 49 | public void setValue(Object value) { 50 | this.value = value; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/StaticMethodImportResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.integration.impl; 20 | 21 | import org.mvel2.integration.VariableResolver; 22 | import org.mvel2.util.MethodStub; 23 | 24 | /** 25 | * @author Christopher Brock 26 | */ 27 | public class StaticMethodImportResolver implements VariableResolver { 28 | private String name; 29 | private MethodStub method; 30 | 31 | public StaticMethodImportResolver(String name, MethodStub method) { 32 | this.name = name; 33 | this.method = method; 34 | } 35 | 36 | public String getName() { 37 | return name; 38 | } 39 | 40 | public Class getType() { 41 | return null; 42 | } 43 | 44 | public void setStaticType(Class type) { 45 | } 46 | 47 | public int getFlags() { 48 | return 0; 49 | } 50 | 51 | public MethodStub getValue() { 52 | return method; 53 | } 54 | 55 | public void setValue(Object value) { 56 | this.method = (MethodStub) value; 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/integration/impl/TypeInjectionResolverFactory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.integration.impl; 20 | 21 | /** 22 | * This is a marker interface 23 | */ 24 | public interface TypeInjectionResolverFactory { 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/OptimizationNotSupported.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.optimizers; 19 | 20 | public class OptimizationNotSupported extends RuntimeException { 21 | 22 | public OptimizationNotSupported() { 23 | super(); 24 | } 25 | 26 | public OptimizationNotSupported(String message) { 27 | super(message); 28 | } 29 | 30 | public OptimizationNotSupported(String message, Throwable cause) { 31 | super(message, cause); 32 | } 33 | 34 | public OptimizationNotSupported(Throwable cause) { 35 | super(cause); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/OptimizerHook.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.optimizers; 20 | 21 | import org.mvel2.compiler.Accessor; 22 | 23 | /** 24 | * @author Christopher Brock 25 | */ 26 | public interface OptimizerHook { 27 | /** 28 | * Should answer back whether or not this hook understands how to work with the current 29 | * optimizer. 30 | * 31 | * @param optimizer - class type of the current optimizer being used 32 | * @return boolean 33 | */ 34 | public boolean isOptimizerSupported(Class optimizer); 35 | 36 | 37 | /** 38 | * The optimizer should delegate back to the hook through this method, passing an instance of itself 39 | * in the current state. 40 | * 41 | * @param optimizer - instance of optimizer 42 | * @return boolean 43 | */ 44 | public Accessor generateAccessor(AccessorOptimizer optimizer); 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/dynamic/DynamicAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.optimizers.dynamic; 20 | 21 | import org.mvel2.compiler.Accessor; 22 | 23 | public interface DynamicAccessor extends Accessor { 24 | public void deoptimize(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/impl/refl/collection/ListCreator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL (The MVFLEX Expression Language) 3 | * 4 | * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | package org.mvel2.optimizers.impl.refl.collection; 20 | 21 | import org.mvel2.compiler.Accessor; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | 24 | import java.util.ArrayList; 25 | import java.util.Arrays; 26 | import java.util.List; 27 | 28 | /** 29 | * @author Christopher Brock 30 | */ 31 | public class ListCreator implements Accessor { 32 | public Accessor[] values; 33 | 34 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { 35 | Object[] template = new Object[values.length]; 36 | for (int i = 0; i < values.length; i++) { 37 | template[i] = values[i].getValue(ctx, elCtx, variableFactory); 38 | } 39 | return new ArrayList(Arrays.asList(template)); 40 | } 41 | 42 | public ListCreator(Accessor[] values) { 43 | this.values = values; 44 | } 45 | 46 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) { 47 | return null; 48 | } 49 | 50 | public Class getKnownEgressType() { 51 | return List.class; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/impl/refl/nodes/ArrayLength.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL (The MVFLEX Expression Language) 3 | * 4 | * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | package org.mvel2.optimizers.impl.refl.nodes; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | 23 | import static java.lang.reflect.Array.getLength; 24 | 25 | /** 26 | * @author Christopher Brock 27 | */ 28 | public class ArrayLength extends BaseAccessor { 29 | 30 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { 31 | if (nextNode != null) { 32 | return nextNode.getValue(getLength(ctx), elCtx, variableFactory); 33 | } 34 | else { 35 | return getLength(ctx); 36 | } 37 | } 38 | 39 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) { 40 | return null; 41 | } 42 | 43 | public Class getKnownEgressType() { 44 | return Integer.class; 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/impl/refl/nodes/BaseAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL (The MVFLEX Expression Language) 3 | * 4 | * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | package org.mvel2.optimizers.impl.refl.nodes; 20 | 21 | import org.mvel2.compiler.AccessorNode; 22 | 23 | public abstract class BaseAccessor implements AccessorNode { 24 | protected AccessorNode nextNode; 25 | 26 | public AccessorNode setNextNode(AccessorNode accessorNode) { 27 | return this.nextNode = accessorNode; 28 | } 29 | 30 | public AccessorNode getNextNode() { 31 | return this.nextNode; 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/impl/refl/nodes/Notify.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.optimizers.impl.refl.nodes; 2 | 3 | import org.mvel2.compiler.AccessorNode; 4 | import org.mvel2.integration.GlobalListenerFactory; 5 | import org.mvel2.integration.VariableResolverFactory; 6 | 7 | 8 | public class Notify implements AccessorNode { 9 | private String name; 10 | private AccessorNode nextNode; 11 | 12 | public Notify(String name) { 13 | this.name = name; 14 | } 15 | 16 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory vrf) { 17 | GlobalListenerFactory.notifyGetListeners(ctx, name, vrf); 18 | return nextNode.getValue(ctx, elCtx, vrf); 19 | } 20 | 21 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) { 22 | GlobalListenerFactory.notifySetListeners(ctx, name, variableFactory, value); 23 | return nextNode.setValue(ctx, elCtx, variableFactory, value); 24 | } 25 | 26 | public AccessorNode getNextNode() { 27 | return nextNode; 28 | } 29 | 30 | public AccessorNode setNextNode(AccessorNode nextNode) { 31 | return this.nextNode = nextNode; 32 | } 33 | 34 | public Class getKnownEgressType() { 35 | return Object.class; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/optimizers/impl/refl/nodes/ThisValueAccessor.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL (The MVFLEX Expression Language) 3 | * 4 | * Copyright (C) 2007 Christopher Brock, MVFLEX/Valhalla Project and the Codehaus 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | * 18 | */ 19 | package org.mvel2.optimizers.impl.refl.nodes; 20 | 21 | import org.mvel2.compiler.AccessorNode; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | 24 | public class ThisValueAccessor implements AccessorNode { 25 | private AccessorNode nextNode; 26 | 27 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory vars) { 28 | if (nextNode != null) { 29 | return this.nextNode.getValue(elCtx, elCtx, vars); 30 | } 31 | else { 32 | return elCtx; 33 | } 34 | } 35 | 36 | public ThisValueAccessor() { 37 | } 38 | 39 | public AccessorNode getNextNode() { 40 | return nextNode; 41 | } 42 | 43 | public AccessorNode setNextNode(AccessorNode nextNode) { 44 | return this.nextNode = nextNode; 45 | } 46 | 47 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) { 48 | if (nextNode == null) throw new RuntimeException("assignment to reserved variable 'this' not permitted"); 49 | return this.nextNode.setValue(elCtx, elCtx, variableFactory, value); 50 | 51 | } 52 | 53 | public Class getKnownEgressType() { 54 | return Object.class; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/Command.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh; 20 | 21 | public interface Command { 22 | public Object execute(ShellSession session, String[] args); 23 | 24 | public String getDescription(); 25 | 26 | public String getHelp(); 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/CommandException.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh; 20 | 21 | public class CommandException extends RuntimeException { 22 | 23 | public CommandException() { 24 | super(); 25 | } 26 | 27 | public CommandException(String message) { 28 | super(message); 29 | } 30 | 31 | public CommandException(String message, Throwable cause) { 32 | super(message, cause); 33 | } 34 | 35 | public CommandException(Throwable cause) { 36 | super(cause); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/CommandSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh; 20 | 21 | import java.util.Map; 22 | 23 | public interface CommandSet { 24 | public Map load(); 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/DefaultEnvironment.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh; 20 | 21 | public interface DefaultEnvironment { 22 | public static final String PROMPT = 23 | "[@{ new java.text.SimpleDateFormat('hh:mmaa').format(new java.util.Date(System.currentTimeMillis()))}] mvel2$ "; 24 | 25 | } 26 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/Main.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh; 20 | 21 | import org.mvel2.MVEL; 22 | 23 | import java.io.File; 24 | import java.io.IOException; 25 | 26 | public class Main { 27 | public static void main(String[] args) throws IOException { 28 | if (args.length != 0) { 29 | MVEL.evalFile(new File(args[0])); 30 | } 31 | else { 32 | showSplash(); 33 | new ShellSession().run(); 34 | } 35 | } 36 | 37 | private static void showSplash() { 38 | System.out.println("\nMVEL-Shell (MVELSH)"); 39 | System.out.println("Copyright (C) 2010, Christopher Brock, The Codehaus"); 40 | System.out.println("Version " + MVEL.VERSION + "." + MVEL.VERSION_SUB + "\n"); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/basic/BasicCommandSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.basic; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.CommandSet; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class BasicCommandSet implements CommandSet { 28 | 29 | public Map load() { 30 | Map cmds = new HashMap(); 31 | 32 | cmds.put("set", new Set()); 33 | cmds.put("push", new PushContext()); 34 | cmds.put("help", new Help()); 35 | cmds.put("showvars", new ShowVars()); 36 | cmds.put("inspect", new ObjectInspector()); 37 | cmds.put("exit", new Exit()); 38 | 39 | return cmds; 40 | } 41 | } 42 | 43 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/basic/Exit.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.basic; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.ShellSession; 23 | 24 | public class Exit implements Command { 25 | 26 | public Object execute(ShellSession session, String[] args) { 27 | System.exit(0); 28 | return null; 29 | } 30 | 31 | 32 | public String getDescription() { 33 | return "exits the command shell"; 34 | } 35 | 36 | public String getHelp() { 37 | return "No help yet."; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/basic/Help.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.basic; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.ShellSession; 23 | 24 | import static org.mvel2.sh.text.TextUtil.pad; 25 | 26 | public class Help implements Command { 27 | public Object execute(ShellSession session, String[] args) { 28 | for (String command : session.getCommands().keySet()) { 29 | System.out.println(command + pad(command.length(), 25) + "- " + session.getCommands().get(command).getDescription()); 30 | } 31 | 32 | return null; 33 | } 34 | 35 | 36 | public String getDescription() { 37 | return "displays help for available shell commands"; 38 | } 39 | 40 | public String getHelp() { 41 | return "No help yet"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/basic/PushContext.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.basic; 20 | 21 | import org.mvel2.MVEL; 22 | import org.mvel2.sh.Command; 23 | import org.mvel2.sh.ShellSession; 24 | 25 | public class PushContext implements Command { 26 | public Object execute(ShellSession session, String[] args) { 27 | session.setCtxObject(MVEL.eval(args[0], session.getCtxObject(), session.getVariables())); 28 | return "Changed Context"; 29 | } 30 | 31 | public String getDescription() { 32 | return null; 33 | } 34 | 35 | public String getHelp() { 36 | return null; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/basic/Set.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.basic; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.CommandException; 23 | import org.mvel2.sh.ShellSession; 24 | import org.mvel2.util.StringAppender; 25 | 26 | import java.util.Map; 27 | 28 | public class Set implements Command { 29 | public Object execute(ShellSession session, String[] args) { 30 | 31 | Map env = session.getEnv(); 32 | 33 | if (args.length == 0) { 34 | for (String var : env.keySet()) { 35 | System.out.println(var + " = " + env.get(var)); 36 | } 37 | } 38 | else if (args.length == 1) { 39 | throw new CommandException("incorrect number of parameters"); 40 | } 41 | else { 42 | StringAppender sbuf = new StringAppender(); 43 | for (int i = 1; i < args.length; i++) { 44 | sbuf.append(args[i]); 45 | if (i < args.length) sbuf.append(" "); 46 | } 47 | 48 | env.put(args[0], sbuf.toString().trim()); 49 | } 50 | 51 | return null; 52 | } 53 | 54 | 55 | public String getDescription() { 56 | return "sets an environment variable"; 57 | } 58 | 59 | public String getHelp() { 60 | return null; 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/file/FileCommandSet.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.file; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.CommandSet; 23 | 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | public class FileCommandSet implements CommandSet { 28 | 29 | public Map load() { 30 | Map cmd = new HashMap(); 31 | 32 | cmd.put("ls", new DirList()); 33 | cmd.put("cd", new ChangeWorkingDir()); 34 | cmd.put("pwd", new PrintWorkingDirectory()); 35 | 36 | return cmd; 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/command/file/PrintWorkingDirectory.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.command.file; 20 | 21 | import org.mvel2.sh.Command; 22 | import org.mvel2.sh.ShellSession; 23 | 24 | public class PrintWorkingDirectory implements Command { 25 | 26 | public Object execute(ShellSession session, String[] args) { 27 | System.out.println(session.getEnv().get("$CWD")); 28 | return null; 29 | } 30 | 31 | 32 | public String getDescription() { 33 | return "prints the current working directory"; 34 | } 35 | 36 | public String getHelp() { 37 | return "no help yet."; 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/sh/text/TextUtil.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.sh.text; 20 | 21 | import static java.lang.String.valueOf; 22 | 23 | public class TextUtil { 24 | public static String pad(int colLength, int tabPos) { 25 | StringBuilder sAppend = new StringBuilder(); 26 | for (int len = tabPos - colLength; len != -1; len--) { 27 | sAppend.append(' '); 28 | } 29 | 30 | return sAppend.toString(); 31 | } 32 | 33 | public static String paint(char c, int amount) { 34 | StringBuilder append = new StringBuilder(); 35 | for (; amount != -1; amount--) { 36 | append.append(c); 37 | } 38 | return append.toString(); 39 | } 40 | 41 | public static String padTwo(Object first, Object second, int tab) { 42 | return new StringBuilder(valueOf(first)).append(pad(valueOf(first).length(), tab)).append(second).toString(); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/CompiledTemplate.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | import org.mvel2.templates.res.Node; 22 | 23 | import java.io.Serializable; 24 | 25 | public class CompiledTemplate implements Serializable { 26 | private char[] template; 27 | private Node root; 28 | 29 | public CompiledTemplate(char[] template, Node root) { 30 | this.template = template; 31 | this.root = root; 32 | } 33 | 34 | public char[] getTemplate() { 35 | return template; 36 | } 37 | 38 | public void setTemplate(char[] template) { 39 | this.template = template; 40 | } 41 | 42 | public Node getRoot() { 43 | return root; 44 | } 45 | 46 | public void setRoot(Node root) { 47 | this.root = root; 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/SimpleTemplateRegistry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | import java.util.HashMap; 22 | import java.util.Iterator; 23 | import java.util.Map; 24 | import java.util.Set; 25 | 26 | public class SimpleTemplateRegistry implements TemplateRegistry { 27 | private Map NAMED_TEMPLATES = new HashMap(); 28 | 29 | public void addNamedTemplate(String name, CompiledTemplate template) { 30 | NAMED_TEMPLATES.put(name, template); 31 | } 32 | 33 | public CompiledTemplate getNamedTemplate(String name) { 34 | CompiledTemplate t = NAMED_TEMPLATES.get(name); 35 | if (t == null) throw new TemplateError("no named template exists '" + name + "'"); 36 | return t; 37 | } 38 | 39 | public Iterator iterator() { 40 | return NAMED_TEMPLATES.keySet().iterator(); 41 | } 42 | 43 | public Set getNames() { 44 | return NAMED_TEMPLATES.keySet(); 45 | } 46 | 47 | public boolean contains(String name) { 48 | return NAMED_TEMPLATES.containsKey(name); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/TemplateDebug.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | import org.mvel2.templates.res.Node; 22 | 23 | public class TemplateDebug { 24 | 25 | public static void decompile(CompiledTemplate t, char[] template) { 26 | int i = 1; 27 | for (Node n = t.getRoot(); n != null; n = n.getNext()) { 28 | System.out.println((i++) + "> " + n.toString() + "['" + new String(template, n.getBegin(), n.getEnd() - n.getBegin()) + "']"); 29 | } 30 | } 31 | 32 | } 33 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/TemplateError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | public class TemplateError extends RuntimeException { 22 | public TemplateError() { 23 | super(); //To change body of overridden methods use File | Settings | File Templates. 24 | } 25 | 26 | public TemplateError(String s) { 27 | super(s); //To change body of overridden methods use File | Settings | File Templates. 28 | } 29 | 30 | public TemplateError(String s, Throwable throwable) { 31 | super(s, throwable); //To change body of overridden methods use File | Settings | File Templates. 32 | } 33 | 34 | public TemplateError(Throwable throwable) { 35 | super(throwable); //To change body of overridden methods use File | Settings | File Templates. 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/TemplateRegistry.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | import java.util.Iterator; 22 | import java.util.Set; 23 | 24 | public interface TemplateRegistry { 25 | Iterator iterator(); 26 | 27 | Set getNames(); 28 | 29 | boolean contains(String name); 30 | 31 | void addNamedTemplate(String name, CompiledTemplate template); 32 | 33 | CompiledTemplate getNamedTemplate(String name); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/TemplateRuntimeError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | public class TemplateRuntimeError extends RuntimeException { 22 | public TemplateRuntimeError() { 23 | super(); //To change body of overridden methods use File | Settings | File Templates. 24 | } 25 | 26 | public TemplateRuntimeError(String s) { 27 | super(s); //To change body of overridden methods use File | Settings | File Templates. 28 | } 29 | 30 | public TemplateRuntimeError(String s, Throwable throwable) { 31 | super(s, throwable); //To change body of overridden methods use File | Settings | File Templates. 32 | } 33 | 34 | public TemplateRuntimeError(Throwable throwable) { 35 | super(throwable); //To change body of overridden methods use File | Settings | File Templates. 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/TemplateSyntaxError.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates; 20 | 21 | public class TemplateSyntaxError extends RuntimeException { 22 | public TemplateSyntaxError() { 23 | super(); //To change body of overridden methods use File | Settings | File Templates. 24 | } 25 | 26 | public TemplateSyntaxError(String s) { 27 | super(s); //To change body of overridden methods use File | Settings | File Templates. 28 | } 29 | 30 | public TemplateSyntaxError(String s, Throwable throwable) { 31 | super(s, throwable); //To change body of overridden methods use File | Settings | File Templates. 32 | } 33 | 34 | public TemplateSyntaxError(Throwable throwable) { 35 | super(throwable); //To change body of overridden methods use File | Settings | File Templates. 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/CommentNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | import org.mvel2.templates.TemplateRuntime; 23 | import org.mvel2.templates.util.TemplateOutputStream; 24 | 25 | public class CommentNode extends Node { 26 | public CommentNode() { 27 | } 28 | 29 | public CommentNode(int begin, String name, char[] template, int start, int end) { 30 | this.name = name; 31 | this.end = this.cEnd = end; 32 | } 33 | 34 | public CommentNode(int begin, String name, char[] template, int start, int end, Node next) { 35 | this.begin = begin; 36 | this.end = this.cEnd = end; 37 | this.next = next; 38 | } 39 | 40 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 41 | if (next != null) 42 | return next.eval(runtime, appender, ctx, factory); 43 | else 44 | return null; 45 | } 46 | 47 | public boolean demarcate(Node terminatingNode, char[] template) { 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/CompiledIfNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.MVEL; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolverFactory; 24 | import org.mvel2.templates.TemplateRuntime; 25 | import org.mvel2.templates.util.TemplateOutputStream; 26 | import org.mvel2.util.ParseTools; 27 | 28 | import java.io.Serializable; 29 | 30 | public class CompiledIfNode extends IfNode { 31 | 32 | private Serializable ce; 33 | 34 | public CompiledIfNode(int begin, String name, char[] template, int start, int end, ParserContext context) { 35 | super(begin, name, template, start, end); 36 | while (cEnd > cStart && ParseTools.isWhitespace(template[cEnd])) cEnd--; 37 | if (cStart != cEnd) { 38 | ce = MVEL.compileExpression(template, cStart, cEnd - start, context); 39 | } 40 | } 41 | 42 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 43 | if (ce == null || MVEL.executeExpression(ce, ctx, factory, Boolean.class)) { 44 | return trueNode.eval(runtime, appender, ctx, factory); 45 | } 46 | return next != null ? next.eval(runtime, appender, ctx, factory) : null; 47 | } 48 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/CompiledTerminalExpressionNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.MVEL; 22 | import org.mvel2.ParserContext; 23 | import org.mvel2.integration.VariableResolverFactory; 24 | import org.mvel2.templates.TemplateRuntime; 25 | import org.mvel2.templates.util.TemplateOutputStream; 26 | 27 | import java.io.Serializable; 28 | 29 | public class CompiledTerminalExpressionNode extends TerminalExpressionNode { 30 | private Serializable ce; 31 | 32 | public CompiledTerminalExpressionNode(Node node, ParserContext context) { 33 | this.begin = node.begin; 34 | this.name = node.name; 35 | ce = MVEL.compileExpression(node.contents, node.cStart, node.cEnd - node.cStart, context); 36 | } 37 | 38 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 39 | return MVEL.executeExpression(ce, ctx, factory); 40 | } 41 | 42 | public boolean demarcate(Node terminatingNode, char[] template) { 43 | return false; 44 | } 45 | } -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/EndNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | import org.mvel2.templates.TemplateRuntime; 23 | import org.mvel2.templates.util.TemplateOutputStream; 24 | 25 | public class EndNode extends Node { 26 | public Object eval(TemplateRuntime runtie, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 27 | return appender.toString(); 28 | } 29 | 30 | public String toString() { 31 | return "EndNode"; 32 | } 33 | 34 | public boolean demarcate(Node terminatingNode, char[] template) { 35 | return false; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/Opcodes.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | public interface Opcodes { 22 | public static int IF = 1; 23 | public static int ELSE = 2; 24 | public static int FOREACH = 3; 25 | public static int END = 10; 26 | 27 | public static int INCLUDE_FILE = 50; 28 | public static int INCLUDE_NAMED = 51; 29 | public static int COMMENT = 52; 30 | public static int CODE = 53; 31 | public static int EVAL = 55; 32 | 33 | public static int DECLARE = 54; 34 | 35 | public static int STOP = 70; 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/TerminalExpressionNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.MVEL; 22 | import org.mvel2.integration.VariableResolverFactory; 23 | import org.mvel2.templates.TemplateRuntime; 24 | import org.mvel2.templates.util.TemplateOutputStream; 25 | 26 | public class TerminalExpressionNode extends Node { 27 | public TerminalExpressionNode() { 28 | } 29 | 30 | public TerminalExpressionNode(Node node) { 31 | this.begin = node.begin; 32 | this.name = node.name; 33 | this.contents = node.contents; 34 | this.cStart = node.cStart; 35 | this.cEnd = node.cEnd; 36 | } 37 | 38 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 39 | return MVEL.eval(contents, cStart, cEnd - cStart, ctx, factory); 40 | } 41 | 42 | public boolean demarcate(Node terminatingNode, char[] template) { 43 | return false; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/TerminalNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | import org.mvel2.templates.TemplateRuntime; 23 | import org.mvel2.templates.util.TemplateOutputStream; 24 | 25 | public class TerminalNode extends Node { 26 | public TerminalNode() { 27 | } 28 | 29 | public TerminalNode(int begin, int end) { 30 | this.begin = begin; 31 | this.end = end; 32 | } 33 | 34 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 35 | return next != null ? next.eval(runtime, appender, ctx, factory) : null; 36 | } 37 | 38 | public boolean demarcate(Node terminatingNode, char[] template) { 39 | return false; 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/res/TextNode.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.res; 20 | 21 | import org.mvel2.integration.VariableResolverFactory; 22 | import org.mvel2.templates.TemplateRuntime; 23 | import org.mvel2.templates.util.TemplateOutputStream; 24 | 25 | public class TextNode extends Node { 26 | public TextNode(int begin, int end) { 27 | this.begin = begin; 28 | this.end = end; 29 | } 30 | 31 | public TextNode(int begin, int end, ExpressionNode next) { 32 | this.begin = begin; 33 | this.end = end; 34 | this.next = next; 35 | } 36 | 37 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 38 | int len = end - begin; 39 | if (len != 0) { 40 | appender.append(new String(runtime.getTemplate(), begin, len)); 41 | } 42 | return next != null ? next.eval(runtime, appender, ctx, factory) : null; 43 | } 44 | 45 | public String toString() { 46 | return "TextNode(" + begin + "," + end + ")"; 47 | } 48 | 49 | public boolean demarcate(Node terminatingNode, char[] template) { 50 | return false; 51 | } 52 | 53 | public void calculateContents(char[] template) { 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/ArrayIterator.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.templates.util; 20 | 21 | import java.util.Iterator; 22 | 23 | public class ArrayIterator implements Iterator { 24 | private Object[] array; 25 | private int cursor = 0; 26 | 27 | public ArrayIterator(Object[] array) { 28 | this.array = array; 29 | } 30 | 31 | public boolean hasNext() { 32 | return cursor != array.length; 33 | } 34 | 35 | public Object next() { 36 | return array[cursor++]; 37 | } 38 | 39 | public void remove() { 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/CountIterator.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.templates.util; 2 | 3 | import java.util.Iterator; 4 | 5 | /** 6 | * User: christopherbrock 7 | * Date: 10-Aug-2010 8 | * Time: 6:42:20 PM 9 | */ 10 | public class CountIterator implements Iterator { 11 | int cursor; 12 | int countTo; 13 | 14 | public CountIterator(int countTo) { 15 | this.countTo = countTo; 16 | } 17 | 18 | public boolean hasNext() { 19 | return cursor < countTo; 20 | } 21 | 22 | public Object next() { 23 | return cursor++; 24 | } 25 | 26 | public void remove() { 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/TemplateOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.templates.util; 2 | 3 | public interface TemplateOutputStream { 4 | public TemplateOutputStream append(CharSequence c); 5 | 6 | public TemplateOutputStream append(char[] c); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/io/StandardOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.templates.util.io; 2 | 3 | import org.mvel2.templates.util.TemplateOutputStream; 4 | 5 | import java.io.IOException; 6 | import java.io.OutputStream; 7 | 8 | public class StandardOutputStream implements TemplateOutputStream { 9 | private OutputStream outputStream; 10 | 11 | public StandardOutputStream(OutputStream outputStream) { 12 | this.outputStream = outputStream; 13 | } 14 | 15 | public TemplateOutputStream append(CharSequence c) { 16 | try { 17 | for (int i = 0; i < c.length(); i++) { 18 | outputStream.write(c.charAt(i)); 19 | } 20 | 21 | return this; 22 | } 23 | catch (IOException e) { 24 | throw new RuntimeException("failed to write to stream", e); 25 | } 26 | } 27 | 28 | public TemplateOutputStream append(char[] c) { 29 | try { 30 | 31 | for (char i : c) { 32 | outputStream.write(i); 33 | } 34 | return this; 35 | } 36 | catch (IOException e) { 37 | throw new RuntimeException("failed to write to stream", e); 38 | } 39 | } 40 | 41 | @Override 42 | public String toString() { 43 | return null; 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/io/StringAppenderStream.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.templates.util.io; 2 | 3 | import org.mvel2.templates.util.TemplateOutputStream; 4 | import org.mvel2.util.StringAppender; 5 | 6 | public class StringAppenderStream implements TemplateOutputStream { 7 | private StringAppender appender; 8 | 9 | public StringAppenderStream(StringAppender appender) { 10 | this.appender = appender; 11 | } 12 | 13 | public TemplateOutputStream append(CharSequence c) { 14 | appender.append(c); 15 | return this; 16 | } 17 | 18 | public TemplateOutputStream append(char[] c) { 19 | appender.append(c); 20 | return this; 21 | } 22 | 23 | @Override 24 | public String toString() { 25 | return appender.toString(); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/templates/util/io/StringBuilderStream.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.templates.util.io; 2 | 3 | import org.mvel2.templates.util.TemplateOutputStream; 4 | 5 | public class StringBuilderStream implements TemplateOutputStream { 6 | private StringBuilder appender; 7 | 8 | public StringBuilderStream(StringBuilder appender) { 9 | this.appender = appender; 10 | } 11 | 12 | public TemplateOutputStream append(CharSequence c) { 13 | appender.append(c); 14 | return this; 15 | } 16 | 17 | public TemplateOutputStream append(char[] c) { 18 | appender.append(c); 19 | return this; 20 | } 21 | 22 | @Override 23 | public String toString() { 24 | return appender.toString(); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/ArrayTools.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | package org.mvel2.util; 19 | 20 | public class ArrayTools { 21 | 22 | public static int findFirst(char c, int start, int offset, char[] array) { 23 | int end = start + offset; 24 | for (int i = start; i < end; i++) { 25 | if (array[i] == c) return i; 26 | } 27 | return -1; 28 | } 29 | 30 | public static int findLast(char c, int start, int offset, char[] array) { 31 | for (int i = start + offset - 1; i >= 0; i--) { 32 | if (array[i] == c) return i; 33 | } 34 | return -1; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/CallableProxy.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import org.mvel2.integration.VariableResolverFactory; 4 | 5 | public interface CallableProxy { 6 | public Object call(Object ctx, Object thisCtx, VariableResolverFactory factory, Object[] parameters); 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/ErrorUtil.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import org.mvel2.CompileException; 4 | import org.mvel2.ErrorDetail; 5 | 6 | /** 7 | * @author Mike Brock . 8 | */ 9 | public class ErrorUtil { 10 | public static CompileException rewriteIfNeeded(CompileException caught, char[] outer, int outerCursor) { 11 | if (outer != caught.getExpr()) { 12 | String innerExpr = new String(caught.getExpr()).substring(caught.getCursor()); 13 | caught.setExpr(outer); 14 | 15 | String outerStr = new String(outer); 16 | 17 | int newCursor = outerStr.substring(outerStr.indexOf(new String(caught.getExpr()))) 18 | .indexOf(innerExpr); 19 | 20 | caught.setCursor(newCursor); 21 | } 22 | return caught; 23 | } 24 | 25 | public static ErrorDetail rewriteIfNeeded(ErrorDetail detail, char[] outer, int outerCursor) { 26 | if (outer != detail.getExpr()) { 27 | String innerExpr = new String(detail.getExpr()).substring(detail.getCursor()); 28 | detail.setExpr(outer); 29 | 30 | int newCursor = outerCursor; 31 | newCursor += new String(outer).substring(outerCursor).indexOf(innerExpr); 32 | 33 | detail.setCursor(newCursor); 34 | } 35 | return detail; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/JITClassLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.util; 20 | 21 | import sun.misc.Unsafe; 22 | 23 | import java.lang.reflect.Field; 24 | 25 | public class JITClassLoader extends ClassLoader implements MVELClassLoader { 26 | private static boolean sunJVM; 27 | private static Object sunUnsafe; 28 | 29 | static { 30 | try { 31 | Field f = Unsafe.class.getDeclaredField("theUnsafe"); 32 | f.setAccessible(true); 33 | sunUnsafe = f.get(null); 34 | sunJVM = true; 35 | } 36 | catch (Throwable t) { 37 | // t.printStackTrace(); 38 | sunJVM = false; 39 | } 40 | } 41 | 42 | 43 | public JITClassLoader(ClassLoader classLoader) { 44 | super(classLoader); 45 | } 46 | 47 | public Class defineClassX(String className, byte[] b, int off, int len) { 48 | if (sunJVM) { 49 | return ((Unsafe) sunUnsafe).defineClass(className, b, off, len); 50 | } 51 | else { 52 | return super.defineClass(className, b, off, len); 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/MVELClassLoader.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.util; 20 | 21 | public interface MVELClassLoader { 22 | public Class defineClassX(String className, byte[] b, int start, int end); 23 | 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/NullType.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public class NullType { 7 | } 8 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/SharedVariableSpaceModel.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import org.mvel2.integration.VariableResolver; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | import org.mvel2.integration.impl.IndexVariableResolver; 6 | import org.mvel2.integration.impl.IndexedVariableResolverFactory; 7 | import org.mvel2.integration.impl.SimpleValueResolver; 8 | 9 | /** 10 | * @author Mike Brock . 11 | */ 12 | public class SharedVariableSpaceModel extends VariableSpaceModel { 13 | private VariableResolver[] cachedGlobalResolvers; 14 | 15 | public SharedVariableSpaceModel(String[] allVars, Object[] vals) { 16 | this.allVars = allVars; 17 | 18 | cachedGlobalResolvers = new VariableResolver[vals.length]; 19 | for (int i = 0; i < vals.length; i++) { 20 | cachedGlobalResolvers[i] = new IndexVariableResolver(i, vals); 21 | } 22 | } 23 | 24 | public VariableResolverFactory createFactory() { 25 | VariableResolver[] resolvers = new VariableResolver[allVars.length]; 26 | for (int i = 0; i < resolvers.length; i++) { 27 | if (i >= cachedGlobalResolvers.length) { 28 | resolvers[i] = new SimpleValueResolver(null); 29 | } 30 | else { 31 | resolvers[i] = cachedGlobalResolvers[i]; 32 | } 33 | } 34 | 35 | return new IndexedVariableResolverFactory(allVars, resolvers); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/SimpleVariableSpaceModel.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import org.mvel2.integration.VariableResolver; 4 | import org.mvel2.integration.VariableResolverFactory; 5 | import org.mvel2.integration.impl.IndexVariableResolver; 6 | import org.mvel2.integration.impl.IndexedVariableResolverFactory; 7 | import org.mvel2.integration.impl.SimpleValueResolver; 8 | 9 | /** 10 | * @author Mike Brock . 11 | */ 12 | public class SimpleVariableSpaceModel extends VariableSpaceModel { 13 | public SimpleVariableSpaceModel(String[] varNames) { 14 | this.allVars = varNames; 15 | } 16 | 17 | public VariableResolverFactory createFactory(Object[] vals) { 18 | VariableResolver[] resolvers = new VariableResolver[allVars.length]; 19 | for (int i = 0; i < resolvers.length; i++) { 20 | if (i >= vals.length) { 21 | resolvers[i] = new SimpleValueResolver(null); 22 | } 23 | else { 24 | resolvers[i] = new IndexVariableResolver(i, vals); 25 | } 26 | } 27 | 28 | return new IndexedVariableResolverFactory(allVars, resolvers); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/Stack.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.util; 20 | 21 | import java.io.Serializable; 22 | 23 | public interface Stack extends Serializable { 24 | public boolean isEmpty(); 25 | 26 | public Object peek(); 27 | 28 | public Object peek2(); 29 | 30 | public void add(Object obj); 31 | 32 | public void push(Object obj); 33 | 34 | public Object pushAndPeek(Object obj); 35 | 36 | public void push(Object obj1, Object obj2); 37 | 38 | public void push(Object obj1, Object obj2, Object obj3); 39 | 40 | public Object pop(); 41 | 42 | public Object pop2(); 43 | 44 | public void discard(); 45 | 46 | public void clear(); 47 | 48 | public int size(); 49 | 50 | public void showStack(); 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/StackElement.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.util; 20 | 21 | import java.io.Serializable; 22 | 23 | public class StackElement implements Serializable { 24 | public StackElement(StackElement next, Object value) { 25 | this.next = next; 26 | this.value = value; 27 | } 28 | 29 | public StackElement next; 30 | public Object value; 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/ThisLiteral.java: -------------------------------------------------------------------------------- 1 | /** 2 | * MVEL 2.0 3 | * Copyright (C) 2007 The Codehaus 4 | * Mike Brock, Dhanji Prasanna, John Graham, Mark Proctor 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | 19 | package org.mvel2.util; 20 | 21 | public class ThisLiteral { 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/VariableSpaceCompiler.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import org.mvel2.MVEL; 4 | import org.mvel2.ParserContext; 5 | 6 | import java.util.Set; 7 | 8 | /** 9 | * @author Mike Brock . 10 | */ 11 | public class VariableSpaceCompiler { 12 | public static SharedVariableSpaceModel compileShared(String expr, ParserContext pCtx, Object[] vars) { 13 | String[] varNames = pCtx.getIndexedVarNames(); 14 | 15 | ParserContext analysisContext = ParserContext.create(); 16 | analysisContext.setIndexAllocation(true); 17 | 18 | MVEL.analysisCompile(expr, analysisContext); 19 | 20 | Set localNames = analysisContext.getVariables().keySet(); 21 | 22 | pCtx.addIndexedLocals(localNames); 23 | 24 | String[] locals = localNames.toArray(new String[localNames.size()]); 25 | String[] allVars = new String[varNames.length + locals.length]; 26 | 27 | System.arraycopy(varNames, 0, allVars, 0, varNames.length); 28 | System.arraycopy(locals, 0, allVars, varNames.length, locals.length); 29 | 30 | return new SharedVariableSpaceModel(allVars, vars); 31 | } 32 | 33 | public static SimpleVariableSpaceModel compile(String expr, ParserContext pCtx) { 34 | String[] varNames = pCtx.getIndexedVarNames(); 35 | 36 | ParserContext analysisContext = ParserContext.create(); 37 | analysisContext.setIndexAllocation(true); 38 | 39 | MVEL.analysisCompile(expr, analysisContext); 40 | 41 | Set localNames = analysisContext.getVariables().keySet(); 42 | 43 | pCtx.addIndexedLocals(localNames); 44 | 45 | String[] locals = localNames.toArray(new String[localNames.size()]); 46 | String[] allVars = new String[varNames.length + locals.length]; 47 | 48 | System.arraycopy(varNames, 0, allVars, 0, varNames.length); 49 | System.arraycopy(locals, 0, allVars, varNames.length, locals.length); 50 | 51 | return new SimpleVariableSpaceModel(allVars); 52 | } 53 | 54 | 55 | } 56 | -------------------------------------------------------------------------------- /src/main/java/org/mvel2/util/VariableSpaceModel.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public abstract class VariableSpaceModel { 7 | protected String[] allVars; 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/AccessorBMModel.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | 6 | import org.mvel2.DataConversion; 7 | import org.mvel2.compiler.Accessor; 8 | import org.mvel2.compiler.ExecutableStatement; 9 | import org.mvel2.integration.PropertyHandler; 10 | import org.mvel2.integration.VariableResolverFactory; 11 | import org.mvel2.integration.GlobalListenerFactory; 12 | import org.mvel2.tests.core.res.Foo; 13 | import org.mvel2.util.StringAppender; 14 | 15 | 16 | public class AccessorBMModel implements Accessor { 17 | private ExecutableStatement p0; 18 | private long foo; 19 | 20 | public PropertyHandler nullPropertyHandler; 21 | public PropertyHandler nullMethodHandler; 22 | 23 | public Object getValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory) { 24 | return new String[][]{{"2008-04-01", "2008-05-10"}, {"2007-03-01", "2007-02-12"}}; 25 | } 26 | 27 | public Object setValue(Object ctx, Object elCtx, VariableResolverFactory variableFactory, Object value) { 28 | Foo foo = (Foo) variableFactory.getVariableResolver("foo").getValue(); 29 | 30 | if (value == null) { 31 | foo.charTestFld = 0; 32 | } 33 | else { 34 | foo.charTestFld = (Character) value; 35 | } 36 | 37 | return value; 38 | } 39 | 40 | public Class getKnownEgressType() { 41 | return Object.class; 42 | } 43 | 44 | public void setNullPropertyHandler(PropertyHandler handler) { 45 | this.nullPropertyHandler = handler; 46 | } 47 | 48 | public void setNullMethodHandler(PropertyHandler handler) { 49 | this.nullMethodHandler = handler; 50 | } 51 | 52 | public String toString() { 53 | return "FOFOSLDJALKJ"; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/MVEL238.mvel: -------------------------------------------------------------------------------- 1 | import java.util.Calendar; 2 | import java.util.Date; 3 | 4 | var dayMapping = [ 5 | 1:"Sunday", 6 | 2:"Monday", 7 | 3:"Tuesday", 8 | 4:"Wednesday", 9 | 5:"Thursday", 10 | 6:"Friday", 11 | 7:"Sunday" 12 | ]; 13 | 14 | def getTheDay(myDate) { return dayMapping[getDayOfWeek(myDate)]; } 15 | 16 | def getDayOfWeek(myDate) { Calendar calendar = Calendar.getInstance(); calendar.setTime(myDate); return calendar.get(Calendar.DAY_OF_WEEK); } 17 | 18 | getTheDay(new Date()); -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/MVELTest.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core; 2 | 3 | import junit.framework.TestCase; 4 | import org.mvel2.MVEL; 5 | 6 | import java.io.File; 7 | import java.io.IOException; 8 | 9 | /** 10 | * @author yone098 11 | */ 12 | public class MVELTest extends TestCase { 13 | 14 | private File file; 15 | 16 | public void setUp() { 17 | file = new File("samples/scripts/multibyte.mvel"); 18 | } 19 | 20 | /** 21 | * evalFile with encoding(workspace encoding utf-8) 22 | * 23 | * @throws IOException 24 | */ 25 | public void testEvalFile1() throws IOException { 26 | Object obj = MVEL.evalFile(file, "UTF-8"); 27 | assertEquals("?????", obj); 28 | 29 | // use default encoding 30 | obj = MVEL.evalFile(file); 31 | assertEquals("?????", obj); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/ProjectionsTests.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core; 2 | 3 | import org.mvel2.MVEL; 4 | import org.mvel2.tests.core.res.Base; 5 | import org.mvel2.util.Make; 6 | 7 | import java.util.Collection; 8 | import java.util.Iterator; 9 | import java.util.Map; 10 | 11 | public class ProjectionsTests extends AbstractTest { 12 | public void testProjectionSupport() { 13 | assertEquals(true, test("(name in things)contains'Bob'")); 14 | } 15 | 16 | public void testProjectionSupport1() { 17 | assertEquals(true, test("(name in things) contains 'Bob'")); 18 | } 19 | 20 | public void testProjectionSupport2() { 21 | String ex = "(name in things).size()"; 22 | Map vars = createTestMap(); 23 | 24 | assertEquals(3, MVEL.eval(ex, new Base(), vars)); 25 | 26 | assertEquals(3, test("(name in things).size()")); 27 | } 28 | 29 | public void testProjectionSupport3() { 30 | String ex = "(toUpperCase() in ['bar', 'foo'])[1]"; 31 | Map vars = createTestMap(); 32 | 33 | assertEquals("FOO", MVEL.eval(ex, new Base(), vars)); 34 | 35 | assertEquals("FOO", test("(toUpperCase() in ['bar', 'foo'])[1]")); 36 | } 37 | 38 | public void testProjectionSupport4() { 39 | Collection col = (Collection) test("(toUpperCase() in ['zero', 'zen', 'bar', 'foo'] if ($ == 'bar'))"); 40 | assertEquals(1, col.size()); 41 | assertEquals("BAR", col.iterator().next()); 42 | } 43 | 44 | public void testProjectionSupport5() { 45 | Collection col = (Collection) test("(toUpperCase() in ['zero', 'zen', 'bar', 'foo'] if ($.startsWith('z')))"); 46 | assertEquals(2, col.size()); 47 | Iterator iter = col.iterator(); 48 | assertEquals("ZERO", iter.next()); 49 | assertEquals("ZEN", iter.next()); 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/PropertyAccessUnitTest.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core; 2 | 3 | import junit.framework.TestCase; 4 | import org.mvel2.PropertyAccessor; 5 | import org.mvel2.tests.core.res.Base; 6 | import org.mvel2.tests.core.res.Foo; 7 | 8 | public class PropertyAccessUnitTest extends TestCase { 9 | Base base = new Base(); 10 | 11 | public void testPropertyRead() { 12 | assertEquals("cat", PropertyAccessor.get("data", base)); 13 | } 14 | 15 | public void testDeepPropertyRead() { 16 | assertEquals("dog", PropertyAccessor.get("foo.bar.name", base)); 17 | } 18 | 19 | public void testWrite() { 20 | PropertyAccessor.set(base, "foo.bar.name", "cat"); 21 | assertEquals("cat", PropertyAccessor.get("foo.bar.name", base)); 22 | PropertyAccessor.set(base, "foo.bar.name", "dog"); 23 | } 24 | 25 | public void testCollectionsAccess() { 26 | PropertyAccessor.set(base, "funMap['foo'].bar.name", "cat"); 27 | assertEquals("cat", PropertyAccessor.get("funMap['foo'].bar.name", base)); 28 | } 29 | 30 | public void testMethodInvoke() { 31 | assertEquals("WOOF", PropertyAccessor.get("foo.toUC('woof')", base)); 32 | } 33 | 34 | public void testMethodInvoke2() { 35 | assertEquals("happyBar", PropertyAccessor.get("foo.happy()", base)); 36 | } 37 | 38 | public void testMapDirect() { 39 | assertTrue(PropertyAccessor.get("funMap['foo']", base) instanceof Foo); 40 | } 41 | 42 | public void testArrayAccess() { 43 | String[] a = new String[]{"foo", "bar",}; 44 | assertEquals("foo", PropertyAccessor.get("[0]", a)); 45 | } 46 | 47 | public void testArrayAccess2() { 48 | assertEquals("poo", PropertyAccessor.get("[0][0]", new Object[]{new String[]{"poo"}})); 49 | } 50 | 51 | public void testStaticMethodAccess() { 52 | assertEquals(String.class, PropertyAccessor.get("forName('java.lang.String')", Class.class)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/ScopeTests.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core; 2 | 3 | import junit.framework.TestCase; 4 | import org.mvel2.MVEL; 5 | import org.mvel2.ParserContext; 6 | import org.mvel2.integration.VariableResolver; 7 | import org.mvel2.integration.impl.IndexVariableResolver; 8 | 9 | import java.util.HashMap; 10 | 11 | /** 12 | * @author Mike Brock . 13 | */ 14 | public class ScopeTests extends TestCase { 15 | public void testNoScopeLeakageInterpreted() { 16 | String ex = "if (true) { var i = 0 }; i"; 17 | 18 | try { 19 | MVEL.eval(ex, new HashMap()); 20 | fail("should have failed"); 21 | } 22 | catch (Exception e) { 23 | // good! 24 | } 25 | } 26 | 27 | public void testNoScopeLeakageCompiled() { 28 | String ex = "if (true) { var i = 0 }; i"; 29 | 30 | try { 31 | MVEL.compileExpression(ex, ParserContext.create().stronglyTyped()); 32 | fail("should have failed"); 33 | } 34 | catch (Exception e) { 35 | e.printStackTrace(); 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/UnsupportedFeaturesTests.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core; 2 | 3 | import junit.framework.TestCase; 4 | import org.mvel2.MVEL; 5 | import org.mvel2.ParserContext; 6 | import org.mvel2.optimizers.OptimizerFactory; 7 | 8 | /** 9 | * @author Mike Brock . 10 | */ 11 | public class UnsupportedFeaturesTests extends TestCase { 12 | public void testJavaStyleClassLiterals() { 13 | MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true; 14 | 15 | OptimizerFactory.setDefaultOptimizer("ASM"); 16 | assertEquals(String.class, MVEL.executeExpression(MVEL.compileExpression("String.class"))); 17 | 18 | OptimizerFactory.setDefaultOptimizer("reflective"); 19 | assertEquals(String.class, MVEL.executeExpression(MVEL.compileExpression("String.class"))); 20 | 21 | OptimizerFactory.setDefaultOptimizer(OptimizerFactory.DYNAMIC); 22 | 23 | assertEquals(String.class, MVEL.eval("String.class")); 24 | 25 | assertEquals(String.class, MVEL.analyze("String.class", ParserContext.create())); 26 | 27 | MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = false; 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/AStatic.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class AStatic { 4 | public static String Process(String arg) { 5 | return arg; 6 | } 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Bar.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class Bar { 7 | private String name = "dog"; 8 | private boolean woof = true; 9 | private int age = 14; 10 | private String assignTest = ""; 11 | private List testList = new ArrayList(); 12 | private Integer[] intarray = new Integer[1]; 13 | 14 | public String getName() { 15 | return name; 16 | } 17 | 18 | public void setName(String name) { 19 | this.name = name; 20 | } 21 | 22 | public boolean isWoof() { 23 | return woof; 24 | } 25 | 26 | public void setWoof(boolean woof) { 27 | this.woof = woof; 28 | } 29 | 30 | public int getAge() { 31 | return age; 32 | } 33 | 34 | public void setAge(int age) { 35 | this.age = age; 36 | } 37 | 38 | public boolean isFoo(Object obj) { 39 | return obj instanceof Foo; 40 | } 41 | 42 | public String getAssignTest() { 43 | return assignTest; 44 | } 45 | 46 | public void setAssignTest(String assignTest) { 47 | this.assignTest = assignTest; 48 | } 49 | 50 | 51 | public List getTestList() { 52 | return testList; 53 | } 54 | 55 | public void setTestList(List testList) { 56 | this.testList = testList; 57 | } 58 | 59 | public String happy() { 60 | return "happyBar"; 61 | } 62 | 63 | public static int staticMethod() { 64 | return 1; 65 | } 66 | 67 | public Integer[] getIntarray() { 68 | return intarray; 69 | } 70 | 71 | public void setIntarray(Integer[] intarray) { 72 | this.intarray = intarray; 73 | } 74 | 75 | public boolean equals(Object o) { 76 | return o instanceof Bar; 77 | } 78 | } 79 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Cake.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.Set; 4 | 5 | 6 | public class Cake { 7 | private Set ingredients; 8 | 9 | public Set getIngredients() { 10 | return ingredients; 11 | } 12 | 13 | public void setIngredients(Set ingredients) { 14 | this.ingredients = ingredients; 15 | } 16 | } 17 | 18 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Cheesery.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class Cheesery { 4 | private String name; 5 | private Cheese cheese; 6 | 7 | public Cheesery(String name) { 8 | this(name, null); 9 | } 10 | 11 | public Cheesery(String name, 12 | Cheese cheese) { 13 | super(); 14 | this.name = name; 15 | this.cheese = cheese; 16 | } 17 | 18 | public String getName() { 19 | return name; 20 | } 21 | 22 | public void setName(String name) { 23 | this.name = name; 24 | } 25 | 26 | public Cheese getCheese() { 27 | return cheese; 28 | } 29 | 30 | public void setCheese(Cheese cheese) { 31 | this.cheese = cheese; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result + ((cheese == null) ? 0 : cheese.hashCode()); 39 | result = prime * result + ((name == null) ? 0 : name.hashCode()); 40 | return result; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | if (this == obj) return true; 46 | if (obj == null) return false; 47 | if (getClass() != obj.getClass()) return false; 48 | final Cheesery other = (Cheesery) obj; 49 | if (cheese == null) { 50 | if (other.cheese != null) return false; 51 | } 52 | else if (!cheese.equals(other.cheese)) return false; 53 | if (name == null) { 54 | if (other.name != null) return false; 55 | } 56 | else if (!name.equals(other.name)) return false; 57 | return true; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Column.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * User: christopherbrock 6 | * Date: 19-Feb-2009 7 | * Time: 12:32:25 PM 8 | * To change this template use File | Settings | File Templates. 9 | */ 10 | public class Column { 11 | private String name; 12 | private int length; 13 | 14 | public Column(String name, int length) { 15 | this.name = name; 16 | this.length = length; 17 | } 18 | 19 | public String getName() { 20 | return name; 21 | } 22 | 23 | public void setName(String name) { 24 | this.name = name; 25 | } 26 | 27 | public int getLength() { 28 | return length; 29 | } 30 | 31 | public void setLength(int length) { 32 | this.length = length; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/DefaultKnowledgeHelper.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | public class DefaultKnowledgeHelper implements KnowledgeHelper { 7 | 8 | private WorkingMemory workingMemory; 9 | 10 | public DefaultKnowledgeHelper() { 11 | 12 | } 13 | 14 | public DefaultKnowledgeHelper(WorkingMemory workingMemory) { 15 | this.workingMemory = workingMemory; 16 | } 17 | 18 | public WorkingMemory getWorkingMemory() { 19 | return this.workingMemory; 20 | } 21 | 22 | public List retracted = new ArrayList(); 23 | 24 | public void insert(Object object) { 25 | } 26 | 27 | public void retract(Object object) { 28 | retracted.add(object); 29 | } 30 | 31 | public void retract(FactHandle handle) { 32 | retracted.add(handle); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/DerivedClass.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class DerivedClass extends Base { 4 | } 5 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/FactHandle.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public interface FactHandle { 4 | int getId(); 5 | 6 | Object getObject(); 7 | } 8 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Grid.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * User: christopherbrock 6 | * Date: 19-Feb-2009 7 | * Time: 12:39:15 PM 8 | * To change this template use File | Settings | File Templates. 9 | */ 10 | public class Grid { 11 | private Model model; 12 | 13 | public Grid(Model model) { 14 | this.model = model; 15 | } 16 | 17 | public Model getModel() { 18 | return model; 19 | } 20 | 21 | public void setModel(Model model) { 22 | this.model = model; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/KnowledgeHelper.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public interface KnowledgeHelper { 4 | void insert(Object object); 5 | 6 | void retract(Object object); 7 | 8 | void retract(FactHandle handle); 9 | 10 | WorkingMemory getWorkingMemory(); 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MapObject.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public interface MapObject { 4 | public int getId(); 5 | } -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Model.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class Model { 4 | private Column[] columns; 5 | 6 | public Model(Column[] columns) { 7 | this.columns = columns; 8 | } 9 | 10 | 11 | public Column[] getColumns() { 12 | return columns; 13 | } 14 | 15 | public void setColumns(Column[] columns) { 16 | this.columns = columns; 17 | } 18 | } -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MyClass.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.EnumSet; 4 | import java.util.Set; 5 | 6 | public class MyClass implements MyInterface { 7 | private Set m_myEnumSet = EnumSet.noneOf(MY_ENUM.class); 8 | 9 | public boolean isType(MY_ENUM myenum) { 10 | return m_myEnumSet.contains(myenum); 11 | } 12 | 13 | public void setType(MY_ENUM myenum, boolean flag) { 14 | if (flag == true) { 15 | m_myEnumSet.add(myenum); 16 | } 17 | else { 18 | m_myEnumSet.remove(myenum); 19 | } 20 | } 21 | 22 | 23 | } -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MyEnum.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | 4 | public enum MyEnum { 5 | ALTERNATIVE("Alternative"), 6 | FULL_DOCUMENTATION("FullDocumentation"); 7 | 8 | private final String value; 9 | 10 | MyEnum(String v) { 11 | value = v; 12 | } 13 | 14 | public String value() { 15 | return value; 16 | } 17 | 18 | public static MyEnum fromValue(String v) { 19 | for (MyEnum c : MyEnum.values()) { 20 | if (c.value.equals(v)) { 21 | return c; 22 | } 23 | } 24 | throw new IllegalArgumentException(v); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MyInterface.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | 4 | public interface MyInterface { 5 | public enum MY_ENUM { 6 | ONE, TWO, THREE, FOUR 7 | } 8 | 9 | ; 10 | 11 | public boolean isType(MY_ENUM myenum); 12 | 13 | public void setType(MY_ENUM myenum, boolean flag); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MyInterface2.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public interface MyInterface2 extends MySuperInterface { 7 | public void execute(); 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MyInterface3.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public interface MyInterface3 extends MySuperInterface { 7 | public void execute2(); 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/MySuperInterface.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * @author Mike Brock . 5 | */ 6 | public interface MySuperInterface { 7 | public void superMethod(); 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/PDFFieldUtil.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.Calendar; 4 | import java.util.Date; 5 | 6 | public class PDFFieldUtil { 7 | public int calculateAge(Date gebDat) { 8 | long milliAge = System.currentTimeMillis() - gebDat.getTime(); 9 | Calendar geburtsTag = Calendar.getInstance(); 10 | geburtsTag.setTimeInMillis(milliAge); 11 | return geburtsTag.get(Calendar.YEAR) - 1970; 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/PojoStatic.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class PojoStatic { 4 | private String value; 5 | 6 | public PojoStatic(String value) { 7 | this.value = value; 8 | } 9 | 10 | public PojoStatic() { 11 | } 12 | 13 | public String getValue() { 14 | return value; 15 | } 16 | 17 | public void setValue(String string) { 18 | this.value = string; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/PresentationElements.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.List; 4 | 5 | public class PresentationElements { 6 | private List names; 7 | 8 | public List getNames() { 9 | return names; 10 | } 11 | 12 | public void setNames(List names) { 13 | this.names = names; 14 | } 15 | 16 | @Override 17 | public int hashCode() { 18 | final int prime = 31; 19 | int result = 1; 20 | result = prime * result + ((names == null) ? 0 : names.hashCode()); 21 | return result; 22 | } 23 | 24 | @Override 25 | public boolean equals(Object obj) { 26 | if (this == obj) return true; 27 | if (obj == null) return false; 28 | if (!(obj instanceof PresentationElements)) return false; 29 | PresentationElements other = (PresentationElements) obj; 30 | if (names == null) { 31 | if (other.names != null) return false; 32 | } 33 | else if (!names.equals(other.names)) return false; 34 | return true; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/RuleBase.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public interface RuleBase { 4 | public void removeRule(String pkgName, String ruleName); 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/RuleBaseImpl.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class RuleBaseImpl implements RuleBase { 4 | 5 | public void removeRule(String pkgName, 6 | String ruleName) { 7 | } 8 | 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/SampleBean.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class SampleBean { 7 | private Map map = new HashMap(); 8 | private Map map2 = new HashMap(); 9 | 10 | public SampleBean() { 11 | map.put("bar", new Bar()); 12 | } 13 | 14 | public Object getProperty(String name) { 15 | return map.get(name); 16 | } 17 | 18 | public Object setProperty(String name, Object value) { 19 | map.put(name, value); 20 | return value; 21 | } 22 | 23 | public Map getMap2() { 24 | return map2; 25 | } 26 | 27 | public void setMap2(Map map2) { 28 | this.map2 = map2; 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/SampleBeanAccessor.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import org.mvel2.asm.MethodVisitor; 4 | 5 | import static org.mvel2.asm.Opcodes.CHECKCAST; 6 | import static org.mvel2.asm.Opcodes.INVOKEVIRTUAL; 7 | 8 | import org.mvel2.integration.PropertyHandler; 9 | import org.mvel2.integration.VariableResolverFactory; 10 | import org.mvel2.optimizers.impl.asm.ProducesBytecode; 11 | 12 | public class SampleBeanAccessor implements PropertyHandler, ProducesBytecode { 13 | public Object getProperty(String name, Object contextObj, VariableResolverFactory variableFactory) { 14 | return ((SampleBean) contextObj).getProperty(name); 15 | } 16 | 17 | public Object setProperty(String name, Object contextObj, VariableResolverFactory variableFactory, Object value) { 18 | return ((SampleBean) contextObj).setProperty(name, value); 19 | } 20 | 21 | // implement the bytecode generation stubs to work with the JIT. 22 | public void produceBytecodeGet(MethodVisitor mv, String propertyName, VariableResolverFactory variableResolverFactory) { 23 | mv.visitTypeInsn(CHECKCAST, "org/mvel2/tests/core/res/SampleBean"); 24 | mv.visitLdcInsn(propertyName); 25 | mv.visitMethodInsn(INVOKEVIRTUAL, "org/mvel2/tests/core/res/SampleBean", "getProperty", "(Ljava/lang/String;)Ljava/lang/Object;"); 26 | } 27 | 28 | public void produceBytecodePut(MethodVisitor mv, String propertyName, VariableResolverFactory variableResolverFactory) { 29 | throw new RuntimeException("not implemented"); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Ship.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class Ship extends Object implements MapObject { 4 | 5 | public int getId() { 6 | return 1; 7 | } 8 | 9 | public String getName() { 10 | return "Name"; 11 | } 12 | } 13 | 14 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Status.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * @author Mike Brock 5 | */ 6 | public class Status { 7 | public static final int START = 0; 8 | public static final int STOP = 1; 9 | 10 | private int value; 11 | 12 | public Status(int value) { 13 | this.value = value; 14 | } 15 | 16 | public int getValue() { 17 | return value; 18 | } 19 | 20 | @Override 21 | public int hashCode() { 22 | final int prime = 31; 23 | int result = 1; 24 | result = prime * result + value; 25 | return result; 26 | } 27 | 28 | @Override 29 | public boolean equals(Object obj) { 30 | if ( this == obj ) return true; 31 | if ( obj == null ) return false; 32 | if ( getClass() != obj.getClass() ) return false; 33 | Status other = (Status) obj; 34 | if ( value != other.value ) return false; 35 | return true; 36 | } 37 | 38 | @Override 39 | public String toString() { 40 | return "Status [value=" + value + "]"; 41 | } 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Task.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.List; 4 | 5 | public class Task { 6 | private int priority; 7 | private List users; 8 | private List names; 9 | 10 | public int getPriority() { 11 | return priority; 12 | } 13 | 14 | public void setPriority(int priority) { 15 | this.priority = priority; 16 | } 17 | 18 | public List getUsers() { 19 | return users; 20 | } 21 | 22 | public void setUsers(List users) { 23 | this.users = users; 24 | } 25 | 26 | public List getNames() { 27 | return names; 28 | } 29 | 30 | public void setNames(List names) { 31 | this.names = names; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result + ((names == null) ? 0 : names.hashCode()); 39 | result = prime * result + priority; 40 | result = prime * result + ((users == null) ? 0 : users.hashCode()); 41 | return result; 42 | } 43 | 44 | @Override 45 | public boolean equals(Object obj) { 46 | if (this == obj) return true; 47 | if (obj == null) return false; 48 | if (!(obj instanceof Task)) return false; 49 | Task other = (Task) obj; 50 | if (names == null) { 51 | if (other.names != null) return false; 52 | } 53 | else if (!names.equals(other.names)) return false; 54 | if (priority != other.priority) return false; 55 | if (users == null) { 56 | if (other.users != null) return false; 57 | } 58 | else if (!users.equals(other.users)) return false; 59 | return true; 60 | } 61 | 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/TestClass.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | 6 | public class TestClass { 7 | private Map extra = new HashMap(); 8 | 9 | public Map getExtra() { 10 | return extra; 11 | } 12 | 13 | public void setExtra(Map extra) { 14 | this.extra = extra; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/TestInterface.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | /** 4 | * Created by IntelliJ IDEA. 5 | * User: brockm 6 | * Date: Jun 22, 2007 7 | * Time: 6:31:04 PM 8 | * To change this template use File | Settings | File Templates. 9 | */ 10 | public interface TestInterface { 11 | public String getName(); 12 | 13 | public boolean isFoo(); 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/TestMVEL197.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | 4 | import java.util.HashMap; 5 | import java.util.Map; 6 | 7 | import org.mvel2.templates.TemplateRuntime; 8 | 9 | public class TestMVEL197 { 10 | 11 | private String name1; 12 | 13 | private String name2; 14 | 15 | public String getName1() { 16 | return name1; 17 | } 18 | 19 | public void setName1(String name1) { 20 | this.name1 = name1; 21 | } 22 | 23 | public String getName2() { 24 | return name2; 25 | } 26 | 27 | public void setName2(String name2) { 28 | this.name2 = name2; 29 | } 30 | } -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Thing.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class Thing { 4 | private MyEnum myEnum; 5 | 6 | private String name; 7 | 8 | public Thing(String name) { 9 | this.name = name; 10 | } 11 | 12 | 13 | public String getName() { 14 | return name; 15 | } 16 | 17 | public void setName(String name) { 18 | this.name = name; 19 | } 20 | 21 | public MyEnum getMyEnum() { 22 | return myEnum; 23 | } 24 | 25 | public void setMyEnum(MyEnum myEnum) { 26 | this.myEnum = myEnum; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/User.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.io.Serializable; 4 | 5 | public class User implements Serializable { 6 | private String firstName; 7 | private String lastName; 8 | 9 | public User() { 10 | 11 | } 12 | 13 | public User(String firstName, String lastName) { 14 | this.firstName = firstName; 15 | this.lastName = lastName; 16 | } 17 | 18 | public String getFirstName() { 19 | return firstName; 20 | } 21 | 22 | public void setFirstName(String firstName) { 23 | this.firstName = firstName; 24 | } 25 | 26 | public String getLastName() { 27 | return lastName; 28 | } 29 | 30 | public void setLastName(String lastName) { 31 | this.lastName = lastName; 32 | } 33 | 34 | @Override 35 | public int hashCode() { 36 | final int prime = 31; 37 | int result = 1; 38 | result = prime * result + ((firstName == null) ? 0 : firstName.hashCode()); 39 | result = prime * result + ((lastName == null) ? 0 : lastName.hashCode()); 40 | return result; 41 | } 42 | 43 | @Override 44 | public boolean equals(Object obj) { 45 | if (this == obj) return true; 46 | if (obj == null) return false; 47 | if (!(obj instanceof User)) return false; 48 | User other = (User) obj; 49 | if (firstName == null) { 50 | if (other.firstName != null) return false; 51 | } 52 | else if (!firstName.equals(other.firstName)) return false; 53 | if (lastName == null) { 54 | if (other.lastName != null) return false; 55 | } 56 | else if (!lastName.equals(other.lastName)) return false; 57 | return true; 58 | } 59 | 60 | 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/Users.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | import java.util.List; 4 | 5 | public class Users { 6 | private List users; 7 | 8 | public List getUsers() { 9 | return users; 10 | } 11 | 12 | public void setUsers(List users) { 13 | this.users = users; 14 | } 15 | 16 | @Override 17 | public int hashCode() { 18 | final int prime = 31; 19 | int result = 1; 20 | result = prime * result + ((users == null) ? 0 : users.hashCode()); 21 | return result; 22 | } 23 | 24 | @Override 25 | public boolean equals(Object obj) { 26 | if (this == obj) return true; 27 | if (obj == null) return false; 28 | if (!(obj instanceof Users)) return false; 29 | Users other = (Users) obj; 30 | if (users == null) { 31 | if (other.users != null) return false; 32 | } 33 | else if (!users.equals(other.users)) return false; 34 | return true; 35 | } 36 | 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/WorkingMemory.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public interface WorkingMemory { 4 | public RuleBase getRuleBase(); 5 | } 6 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/WorkingMemoryImpl.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res; 2 | 3 | public class WorkingMemoryImpl implements WorkingMemory { 4 | private RuleBase ruleBasae; 5 | 6 | public WorkingMemoryImpl(RuleBase ruleBasae) { 7 | super(); 8 | this.ruleBasae = ruleBasae; 9 | } 10 | 11 | public RuleBase getRuleBase() { 12 | return ruleBasae; 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/res2/ClassProvider.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res.res2; 2 | 3 | public class ClassProvider { 4 | public PublicClass getPrivate() { 5 | return new PrivateClass(); 6 | } 7 | 8 | public PublicClass getPublic() { 9 | return new PublicClass(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/res2/Outer.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res.res2; 2 | 3 | public class Outer { 4 | 5 | public Inner getInner() { 6 | return new Inner(); 7 | } 8 | 9 | public class Inner extends Object { 10 | 11 | public int getValue() { 12 | return 2; 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/res2/PrivateClass.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res.res2; 2 | 3 | class PrivateClass extends PublicClass { 4 | @Override 5 | public void foo() { 6 | System.out.println("private!"); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/core/res/res2/PublicClass.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.core.res.res2; 2 | 3 | import java.io.Serializable; 4 | 5 | public class PublicClass implements Serializable { 6 | public void foo() { 7 | System.out.println("public!"); 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/fuzz/IdentifierFuzzer.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.fuzz; 2 | 3 | import org.mvel2.MVEL; 4 | import org.mvel2.util.ParseTools; 5 | 6 | import static java.lang.Character.isJavaIdentifierStart; 7 | 8 | public class IdentifierFuzzer { 9 | 10 | public static void main(String[] args) { 11 | try { 12 | for (int i = 0; i < 1000000; i++) { 13 | MVEL.compileExpression(getIndentifierSample()); 14 | } 15 | } 16 | catch (Throwable t) { 17 | t.printStackTrace(); 18 | } 19 | System.out.println("**Done**"); 20 | } 21 | 22 | private static char[] getIndentifierSample() { 23 | int idLength = (int) (10 * Math.random()) + 2; 24 | char[] sample = new char[idLength + 5]; 25 | 26 | boolean ok = false; 27 | char candidate; 28 | while (!ok) { 29 | if (isJavaIdentifierStart(candidate = (char) (128 * Math.random()))) { 30 | sample[0] = candidate; 31 | ok = true; 32 | } 33 | } 34 | for (int i = 1; i < idLength; i++) { 35 | ok = false; 36 | while (!ok) { 37 | candidate = (char) (128 * Math.random()); 38 | if (Character.isJavaIdentifierPart(candidate)) { 39 | sample[i] = candidate; 40 | ok = true; 41 | } 42 | } 43 | 44 | } 45 | 46 | if (ParseTools.isReservedWord(new String(sample, 0, idLength).trim())) { 47 | return getIndentifierSample(); 48 | } 49 | 50 | sample[idLength] = ' '; 51 | sample[idLength + 1] = '='; 52 | sample[idLength + 2] = ' '; 53 | sample[idLength + 3] = '1'; 54 | sample[idLength + 4] = ';'; 55 | return sample; 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/perftests/NullOutputStream.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.perftests; 2 | 3 | import java.io.IOException; 4 | import java.io.OutputStream; 5 | 6 | public class NullOutputStream extends OutputStream { 7 | public void write(int i) throws IOException { 8 | 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/perfTest1.mv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/src/test/java/org/mvel2/tests/templates/perfTest1.mv -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/templateError.mv: -------------------------------------------------------------------------------- 1 | 2 | @foreach{item : arrayList} 3 | @{ddo 4 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/templateError2.mv: -------------------------------------------------------------------------------- 1 | @{thisDoesntExist()} -- foo! -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/templateIfTest.mv: -------------------------------------------------------------------------------- 1 | @code{__a = 1; __b = 2; __c = 3}@if{__a == 1}@if{__b == 2}@if{__c == 3}Hello!@end{}@end{}@end{} -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/templateTest.mv: -------------------------------------------------------------------------------- 1 | @comment{ 2 | * 3 | * This is a simple template. 4 | * 5 | }@{_foo_}::@{_bar_} -------------------------------------------------------------------------------- /src/test/java/org/mvel2/tests/templates/tests/res/TestPluginNode.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.tests.templates.tests.res; 2 | 3 | import org.mvel2.integration.VariableResolverFactory; 4 | import org.mvel2.templates.TemplateRuntime; 5 | import org.mvel2.templates.util.TemplateOutputStream; 6 | import org.mvel2.templates.res.Node; 7 | import org.mvel2.util.StringAppender; 8 | 9 | import java.io.PrintStream; 10 | import java.io.PrintWriter; 11 | 12 | public class TestPluginNode extends Node { 13 | 14 | public Object eval(TemplateRuntime runtime, TemplateOutputStream appender, Object ctx, VariableResolverFactory factory) { 15 | appender.append("THIS_IS_A_TEST"); 16 | return next != null ? next.eval(runtime, appender, ctx, factory) : null; 17 | } 18 | 19 | public boolean demarcate(Node terminatingNode, char[] template) { 20 | return false; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/org/mvel2/util/FastListTest.java: -------------------------------------------------------------------------------- 1 | package org.mvel2.util; 2 | 3 | import junit.framework.TestCase; 4 | import org.mvel2.MVEL; 5 | 6 | import java.io.Serializable; 7 | import java.util.ArrayList; 8 | import java.util.HashMap; 9 | import java.util.List; 10 | import java.util.Map; 11 | 12 | public class FastListTest extends TestCase { 13 | protected Map map = new HashMap(); 14 | 15 | public FastListTest() { 16 | map.put("var0", "var0"); 17 | } 18 | 19 | public void testHashCode() { 20 | List list = (List) parseDirect("[ 'key1', var0 ]"); 21 | System.out.println(list.hashCode()); 22 | } 23 | 24 | public void testEquals() { 25 | List list1 = (List) parseDirect("[ 'key1', var0 ]"); 26 | List list2 = new ArrayList(); 27 | list2.add("key1"); 28 | list2.add("var0"); 29 | assertEquals(list2, list1); 30 | assertEquals(list1, list2); 31 | } 32 | 33 | public Object parseDirect(String ex) { 34 | return compiledExecute(ex); 35 | } 36 | 37 | public Object compiledExecute(String ex) { 38 | Serializable compiled = MVEL.compileExpression(ex); 39 | Object first = MVEL.executeExpression(compiled, null, map); 40 | Object second = MVEL.executeExpression(compiled, null, map); 41 | 42 | if (first != null && !first.getClass().isArray()) 43 | assertEquals(first, second); 44 | 45 | return second; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/test/resources/eventing-example.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikebrock/mvel/c8ded0833626cdc6fbe2755234904fce06a9c0fa/src/test/resources/eventing-example.jar --------------------------------------------------------------------------------