Package org.mvel2.util

Examples of org.mvel2.util.InternalNumber


    protected static String JAVA_RULE_MVEL             = "javaRule.mvel";
    protected static String JAVA_INVOKERS_MVEL         = "javaInvokers.mvel";

    public static void setConsequenceTemplate( String name ) {
        JAVA_RULE_MVEL = name;
        RULE_REGISTRY = new SimpleTemplateRegistry();
    }
View Full Code Here


        RULE_REGISTRY = new SimpleTemplateRegistry();
    }

    public static void setInvokerTemplate( String name ) {
        JAVA_INVOKERS_MVEL = name;
        INVOKER_REGISTRY = new SimpleTemplateRegistry();
    }
View Full Code Here

                                 final ProcessBuildContext context,
                                 final String className,
                                 final Map vars,
                                 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

        generateMethodTemplate(ruleTemplate, context, vars);
        generateInvokerTemplate(invokerTemplate, context, className, vars, invokerLookup, descrLookup);
    }

    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 RuleBuildContext context,
                                               final String className,
                                               final Map vars,
                                               final Object invokerLookup,
                                               final BaseDescr descrLookup) {
        TemplateRegistry registry = getInvokerTemplateRegistry(context.getPackageBuilder().getRootClassLoader());
        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,
View Full Code Here

          case DIV:
            return ((Float) val1).doubleValue() / ((Float) val2).doubleValue();
          case MULT:
            return ((Float) val1) * ((Float) val2);
          case POWER:
            return narrowType(new InternalNumber((Float) val1, MATH_CONTEXT).pow(new InternalNumber((Float) val2).intValue(), MATH_CONTEXT), -1);
          case MOD:
            return ((Float) val1) % ((Float) val2);
          case GTHAN:
            return ((Float) val1) > ((Float) val2) ? Boolean.TRUE : Boolean.FALSE;
          case GETHAN:
View Full Code Here

  }


  private static InternalNumber getInternalNumberFromType(Object in, int type) {
    if (in == null)
      return new InternalNumber(0, MATH_CONTEXT);
    switch (type) {
      case BIG_DECIMAL:
        return new InternalNumber(((BigDecimal) in).doubleValue());
      case DataTypes.BIG_INTEGER:
        return new InternalNumber((BigInteger) in, MathContext.DECIMAL128);
      case DataTypes.INTEGER:
      case DataTypes.W_INTEGER:
        return new InternalNumber((Integer) in, MathContext.DECIMAL32);
      case DataTypes.LONG:
      case DataTypes.W_LONG:
        return new InternalNumber((Long) in, MathContext.DECIMAL64);
      case DataTypes.STRING:
        return new InternalNumber((String) in, MathContext.DECIMAL64);
      case DataTypes.FLOAT:
      case DataTypes.W_FLOAT:
        return new InternalNumber((Float) in, MathContext.DECIMAL64);
      case DataTypes.DOUBLE:
      case DataTypes.W_DOUBLE:
        return new InternalNumber((Double) in, MathContext.DECIMAL64);
      case DataTypes.SHORT:
      case DataTypes.W_SHORT:
        return new InternalNumber((Short) in, MathContext.DECIMAL32);
      case DataTypes.CHAR:
      case DataTypes.W_CHAR:
        return new InternalNumber((Character) in, MathContext.DECIMAL32);
      case DataTypes.BOOLEAN:
      case DataTypes.W_BOOLEAN:
        return new InternalNumber(((Boolean) in) ? 1 : 0);
      case DataTypes.UNIT:
        return new InternalNumber(((Unit) in).getValue(), MathContext.DECIMAL64);
      case DataTypes.W_BYTE:
      case DataTypes.BYTE:
        return new InternalNumber(((Byte) in).intValue());


    }

    throw new RuntimeException("cannot convert <" + in + "> to a numeric type: " + in.getClass() + " [" + type + "]");
View Full Code Here

          case DIV:
            return ((Float) val1).doubleValue() / ((Float) val2).doubleValue();
          case MULT:
            return ((Float) val1) * ((Float) val2);
          case POWER:
            return narrowType(new InternalNumber((Float) val1, MATH_CONTEXT).pow(new InternalNumber((Float) val2).intValue(), MATH_CONTEXT), -1);
          case MOD:
            return ((Float) val1) % ((Float) val2);
          case GTHAN:
            return ((Float) val1) > ((Float) val2) ? Boolean.TRUE : Boolean.FALSE;
          case GETHAN:
View Full Code Here

  }


  private static InternalNumber getInternalNumberFromType(Object in, int type) {
    if (in == null)
      return new InternalNumber(0, MATH_CONTEXT);
    switch (type) {
      case BIG_DECIMAL:
        return new InternalNumber(((BigDecimal) in).doubleValue());
      case DataTypes.BIG_INTEGER:
        return new InternalNumber((BigInteger) in, MathContext.DECIMAL128);
      case DataTypes.INTEGER:
      case DataTypes.W_INTEGER:
        return new InternalNumber((Integer) in, MathContext.DECIMAL32);
      case DataTypes.LONG:
      case DataTypes.W_LONG:
        return new InternalNumber((Long) in, MathContext.DECIMAL64);
      case DataTypes.STRING:
        return new InternalNumber((String) in, MathContext.DECIMAL64);
      case DataTypes.FLOAT:
      case DataTypes.W_FLOAT:
        return new InternalNumber((Float) in, MathContext.DECIMAL64);
      case DataTypes.DOUBLE:
      case DataTypes.W_DOUBLE:
        return new InternalNumber((Double) in, MathContext.DECIMAL64);
      case DataTypes.SHORT:
      case DataTypes.W_SHORT:
        return new InternalNumber((Short) in, MathContext.DECIMAL32);
      case DataTypes.CHAR:
      case DataTypes.W_CHAR:
        return new InternalNumber((Character) in, MathContext.DECIMAL32);
      case DataTypes.BOOLEAN:
      case DataTypes.W_BOOLEAN:
        return new InternalNumber(((Boolean) in) ? 1 : 0);
      case DataTypes.UNIT:
        return new InternalNumber(((Unit) in).getValue(), MathContext.DECIMAL64);
      case DataTypes.W_BYTE:
      case DataTypes.BYTE:
        return new InternalNumber(((Byte) in).intValue());


    }

    throw new RuntimeException("cannot convert <" + in + "> to a numeric type: " + in.getClass() + " [" + type + "]");
View Full Code Here

        String[] allVars = new String[varNames.length + locals.length];

        System.arraycopy(varNames, 0, allVars, 0, varNames.length);
        System.arraycopy(locals, 0, allVars, varNames.length, locals.length);       
       
        this.varModel = new SimpleVariableSpaceModel(allVars);
        this.allVarsLength = allVars.length;
       
        return stmt;
    }
View Full Code Here

TOP

Related Classes of org.mvel2.util.InternalNumber

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.