Package org.mvel2.optimizers

Examples of org.mvel2.optimizers.AccessorOptimizer


                                 final Object invokerLookup,
                                 final BaseDescr descrLookup) {
        TemplateRegistry registry = getRuleTemplateRegistry();

        context.getMethods().add(
                TemplateRuntime.execute(registry.getNamedTemplate(ruleTemplate), null, new MapVariableResolverFactory(vars), registry)
        );

        registry = getInvokerTemplateRegistry();
        final String invokerClassName = context.getPkg().getName() + "." + context.getProcessDescr().getClassName() + StringUtils.ucFirst(className) + "Invoker";

        context.getInvokers().put(invokerClassName,
                TemplateRuntime.execute(registry.getNamedTemplate(invokerTemplate), null, new MapVariableResolverFactory(vars), registry)
        );

        context.getInvokerLookups().put(invokerClassName,
                invokerLookup);
        context.getDescrLookups().put(invokerClassName,
View Full Code Here


    public static void generateMethodTemplate(final String ruleTemplate, final RuleBuildContext context, final Map vars) {
        TemplateRegistry registry = getRuleTemplateRegistry(context.getPackageBuilder().getRootClassLoader());

        context.addMethod((String) TemplateRuntime.execute( registry.getNamedTemplate(ruleTemplate),
                                                            null,
                                                            new MapVariableResolverFactory(vars),
                                                            registry) );
    }
View Full Code Here

        final String invokerClassName = context.getPkg().getName() + "." + context.getRuleDescr().getClassName() + StringUtils.ucFirst( className ) + "Invoker";

        context.getInvokers().put( invokerClassName,
                                   (String) TemplateRuntime.execute( registry.getNamedTemplate( invokerTemplate ),
                                                                     null,
                                                                     new MapVariableResolverFactory( vars ),
                                                                     registry ) );

        context.getInvokerLookups().put( invokerClassName,
                                             invokerLookup );
        context.getDescrLookups().put( invokerClassName,
View Full Code Here

  public boolean isResolveable(String name) {
    return workItem.getResult(name) != null;
  }
 
  public VariableResolver getVariableResolver(String name) {
    return new SimpleValueResolver(workItem.getResult(name));
  }
View Full Code Here

 
  public VariableResolver getVariableResolver(String name) {
    Object value = ((VariableScopeInstance)
      nodeInstance.resolveContextInstance(
          VariableScope.VARIABLE_SCOPE, name)).getVariable(name);
    return new SimpleValueResolver(value);
  }
View Full Code Here

    return variableScope.getVariable(name) != null;
  }
 
  public VariableResolver getVariableResolver(String name) {
    Object value = variableScope.getVariable(name);
    return new SimpleValueResolver(value);
  }
View Full Code Here

        return (newObjectOptimizer = new NewObjectArray(getBaseComponentType(egressType.getComponentType()), typeDescr.getCompiledArraySize()))
            .getValue(ctx, thisValue, factory);
      }

      try {
        AccessorOptimizer optimizer = getThreadAccessorOptimizer();

        ParserContext pCtx = this.pCtx;
        if (pCtx == null) {
          pCtx = new ParserContext();
          pCtx.getParserConfiguration().setAllImports(getInjectedImports(factory));
        }

        newObjectOptimizer = optimizer.optimizeObjectCreation(pCtx, name, 0, name.length, ctx, thisValue, factory);

        /**
         * Check to see if the optimizer actually produced the object during optimization.  If so,
         * we return that value now.
         */
        if (optimizer.getResultOptPass() != null) {
          egressType = optimizer.getEgressType();
          return optimizer.getResultOptPass();
        }
      }
      catch (CompileException e) {
        throw ErrorUtil.rewriteIfNeeded(e, expr, start);
      }
View Full Code Here

  }

  private Object get(Object ctx, Object elCtx, VariableResolverFactory variableFactory) {
    if (nextAccessor == null) {
      Object o = accessor.getValue(ctx, elCtx, variableFactory);
      AccessorOptimizer ao = OptimizerFactory.getDefaultAccessorCompiler();
      Class ingress = accessor.getKnownEgressType();

      nextAccessor = ao.optimizeAccessor(getCurrentThreadParserContext(), nextExpr, start, offset, o, elCtx, variableFactory,
          false, ingress);
      return ao.getResultOptPass();
    }
    else {
      return accessor.getValue(ctx, elCtx, variableFactory);
    }
  }
View Full Code Here

  private Object optimize(Object ctx, Object thisValue, VariableResolverFactory factory) {
    if ((fields & DEOP) != 0) {
      fields ^= DEOP;
    }

    AccessorOptimizer optimizer;
    Object retVal = null;

    if ((fields & NOJIT) != 0 || factory != null && factory.isResolveable(nameCache)) {
      optimizer = getAccessorCompiler(SAFE_REFLECTIVE);
    }
    else {
      optimizer = getDefaultAccessorCompiler();
    }

    ParserContext pCtx;

    if ((fields & PCTX_STORED) != 0) {
      pCtx = (ParserContext) literal;
    }
    else {
      pCtx = new ParserContext(new ParserConfiguration(getInjectedImports(factory), null));
    }

    try {
      pCtx.optimizationNotify();
      setAccessor(optimizer.optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, egressType));
    }
    catch (OptimizationNotSupported ne) {
      setAccessor((optimizer = getAccessorCompiler(SAFE_REFLECTIVE))
          .optimizeAccessor(pCtx, expr, start, offset, ctx, thisValue, factory, true, null));
    }

    if (accessor == null) {
      return get(expr, start, offset, ctx, factory, thisValue, pCtx);
    }

    if (retVal == null) {
      retVal = optimizer.getResultOptPass();
    }

    if (egressType == null) {
      egressType = optimizer.getEgressType();
    }

    return retVal;
  }
View Full Code Here

    if (accessor != null) {
      return accessor.getValue(main.getReducedValueAccelerated(ctx, thisValue, factory), thisValue, factory);
    }
    else {
      try {
        AccessorOptimizer o = OptimizerFactory.getThreadAccessorOptimizer();
        accessor = o.optimizeAccessor(getCurrentThreadParserContext(), expr, start, offset,
            main.getReducedValueAccelerated(ctx, thisValue, factory), thisValue, factory, false, main.getEgressType());
        return o.getResultOptPass();
      }
      finally {
        OptimizerFactory.clearThreadAccessorOptimizer();
      }
    }
View Full Code Here

TOP

Related Classes of org.mvel2.optimizers.AccessorOptimizer

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.