Package org.mvel2

Examples of org.mvel2.ParserContext


            MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
            MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;

            MVELDialectRuntimeData data = (MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
            ParserConfiguration pconf = data.getParserConfiguration();
            ParserContext pctx = new ParserContext( pconf );

            Object o = MVEL.executeExpression( MVEL.compileExpression( value,
                                                                       pctx ) );
            if ( o != null && vtype == null ) {
                // was a compilation problem else where, so guess valuetype so we can continue
View Full Code Here


                    MVELDialectRuntimeData data = ( MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
                    ParserConfiguration conf = data.getParserConfiguration();
                    conf.setClassLoader( context.getPackageBuilder().getRootClassLoader() );

                    arguments.set( pos,
                            MVEL.executeExpression( MVEL.compileExpression( expr, new ParserContext( conf ) ) ) );
                } catch ( Exception e ) {
                    context.addError( new DescrBuildError( context.getParentDescr(),
                                                                  descr,
                                                                  null,
                                                                  "Unable to compile expression:\n" + expr ) );
View Full Code Here

                MVELDialectRuntimeData data = ( MVELDialectRuntimeData) context.getPkg().getDialectRuntimeRegistry().getDialectData( "mvel" );
                ParserConfiguration conf = data.getParserConfiguration();
                conf.setClassLoader( context.getPackageBuilder().getRootClassLoader() );

                arguments.set( position,
                        MVEL.executeExpression( MVEL.compileExpression( rewrittenExpr, new ParserContext( conf ) ) ) );
            } catch ( Exception e ) {
                context.addError( new DescrBuildError( context.getParentDescr(),
                        base,
                        null,
                        "Unable to compile expression:\n" + rewrittenExpr ) );
View Full Code Here

        try {           
            cls = runtimeData.getRootClassLoader().loadClass( this.className );
        } catch ( ClassNotFoundException e ) {
            throw new IllegalStateException( "Unable to compile as Class could not be found '" + className + "'");
        }
        ParserContext context = new ParserContext(runtimeData.getParserConfiguration());
        context.addInput( "this", cls );
        context.setStrongTyping( typesafe )
       
        MVEL.COMPILER_OPT_ALLOW_NAKED_METH_CALL = true;
        MVEL.COMPILER_OPT_ALLOW_OVERRIDE_ALL_PROPHANDLING = true;
        MVEL.COMPILER_OPT_ALLOW_RESOLVE_INNERCLASSES_WITH_DOTNOTATION = true;
        MVEL.COMPILER_OPT_SUPPORT_JAVA_STYLE_CLASS_LITERALS = true;
View Full Code Here

                Class<?> variableType = getVariableType(variableName);
                if (variableType != null) {
                    return new VariableExpression(variableName, analyzeExpressionNode(accessorNode), variableType);
                } else {
                    if (node.getLiteralValue() instanceof ParserContext) {
                        ParserContext pCtx = (ParserContext)node.getLiteralValue();
                        // it's not a variable but a method invocation on this
                        Class<?> thisClass = pCtx.getInputs().get("this");
                        try {
                            return new EvaluatedExpression(new MethodInvocation(thisClass.getMethod(variableName)));
                        } catch (NoSuchMethodException e) {
                            if (node.getEgressType() == Class.class) {
                                // there's no method on this with the given name, check if it is a class literal
                                Class<?> classLiteral = pCtx.getParserConfiguration().getImport(variableName);
                                if (classLiteral != null) {
                                    return new FixedExpression(Class.class, classLiteral);
                                }
                            }
                            throw new RuntimeException(e);
View Full Code Here

        readLocalsFromTuple = in.readBoolean();
    }   

    public Serializable getCompiledExpression(MVELDialectRuntimeData runtimeData ) {       
        ParserConfiguration conf = runtimeData.getParserConfiguration();
        final ParserContext parserContext = new ParserContext( conf );
        if ( MVELDebugHandler.isDebugMode() ) {
            parserContext.setDebugSymbols( true );
        }

        parserContext.setStrictTypeEnforcement( strictMode );
        parserContext.setStrongTyping( strictMode );
        parserContext.setIndexAllocation( true );

        if ( INTERCEPTORS != null ) {
            parserContext.setInterceptors(INTERCEPTORS);
        }

        parserContext.addIndexedInput( inputIdentifiers );
               
        String identifier = null;
        String type = null;
        try {
            for ( int i = 0, length = inputIdentifiers.length; i < length; i++ ) {
                identifier = inputIdentifiers[i];
                type = inputTypes[i];
                Class< ? > cls = loadClass( runtimeData.getRootClassLoader(),
                                            inputTypes[i] );
                parserContext.addInput( inputIdentifiers[i],
                                        cls );
            }
        } catch ( ClassNotFoundException e ) {
            throw new RuntimeDroolsException( "Unable to resolve class '" + type + "' for identifier '" + identifier );
        }

        parserContext.setSourceFile( name );

        String[] varNames = parserContext.getIndexedVarNames();
       
        ExecutableStatement stmt = (ExecutableStatement) compile( expression,
                                                                  runtimeData.getRootClassLoader(),
                                                                  parserContext,
                                                                  languageLevel );
       
        Set<String> localNames = parserContext.getVariables().keySet();

        parserContext.addIndexedLocals(localNames);

        String[] locals = localNames.toArray(new String[localNames.size()]);
        String[] allVars = new String[varNames.length + locals.length];

        System.arraycopy(varNames, 0, allVars, 0, varNames.length);
View Full Code Here

        String name = context.getRuleName();
        RuleInfo currentRule = getCurrentRule( drlInfo,
                                               name );
        String qName = drlInfo.getPackageName() + "." + name;
        MVELDialect dialect = (MVELDialect) drlInfo.getDialectRegistry().getDialect("mvel");
        ParserContext initialContext = createInitialContext( params,
                                                             qName,
                                                             dialect );
        MvelContext mCon = new MvelContext();
        mCon.setContext( initialContext );
View Full Code Here

        //Lookup ParserConfiguration to retrieve imports and package imports
        PackageRegistry packageRegistry = dialect.getPackageRegistry();
        MVELDialectRuntimeData data = (MVELDialectRuntimeData) packageRegistry.getDialectRuntimeRegistry().getDialectData( dialect.getId() );
        ParserConfiguration pconf = data.getParserConfiguration();

        final ParserContext context = new ParserContext( pconf.getImports(),
                                                         null,
                                                         qualifiedName );

        if ( pconf.getPackageImports() != null ) {
            for ( Iterator it = pconf.getPackageImports().iterator(); it.hasNext(); ) {
                String packageImport = (String) it.next();
                context.addPackageImport( packageImport );
            }
        }
        context.setStrictTypeEnforcement( false );

        context.setInterceptors( dialect.getInterceptors() );
        context.setInputs( params );
        context.addInput( "drools",
                          KnowledgeHelper.class );
        context.addInput( "kcontext",
                          RuleContext.class );
        context.setCompiled( true );
        return context;
    }
View Full Code Here

    public static Map<String, WorkDefinition> parse( final List<String> workItemDefinitions ) {

        final Map<String, WorkDefinition> workDefinitions = new HashMap<String, WorkDefinition>();

        //Add Data-type imports, in-case they are missing from definition
        final ParserContext context = new ParserContext();
        context.addImport( "ObjectDataType",
                           ObjectDataType.class );
        context.addImport( "StringDataType",
                           StringDataType.class );
        context.addImport( "IntegerDataType",
                           IntegerDataType.class );
        context.addImport( "FloatDataType",
                           FloatDataType.class );
        context.addImport( "BooleanDataType",
                           BooleanDataType.class );
        context.addImport( "ListDataType",
                           ListDataType.class );
        context.addImport( "EnumDataType",
                           EnumDataType.class );
        context.addImport( "UndefinedDataType",
                           UndefinedDataType.class );

        //Compile expression and convert String
        for ( String workItemDefinition : workItemDefinitions ) {
View Full Code Here

    }

    public Void execute(Context context) {
        //ParserContext ctx = new Parser
       
        ParserContext parserCtx = new ParserContext( );
        String t = headerText + text;
        MVEL.compileExpression( t, parserCtx );
       
        Map<String, Class> inputs = parserCtx.getInputs();
               
        Map<String, Object> vars = new HashMap<String, Object>();
       
        for ( String name : inputs.keySet() ) {
            vars.put( name, context.get( name ) );
View Full Code Here

TOP

Related Classes of org.mvel2.ParserContext

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.