Examples of ClassGenerator


Examples of org.apache.xalan.xsltc.compiler.util.ClassGenerator

     */
    public void translate() {
  _className = getXSLTC().getClassName();

  // Define a new class by extending TRANSLET_CLASS
  final ClassGenerator classGen =
      new ClassGenerator(_className,
             TRANSLET_CLASS,
             Constants.EMPTYSTRING,
             ACC_PUBLIC | ACC_SUPER,
             null, this);
 
  addDOMField(classGen);

  // Compile transform() to initialize parameters, globals & output
  // and run the transformation
  compileTransform(classGen);

  // Translate all non-template elements and filter out all templates
  final Enumeration elements = elements();
  while (elements.hasMoreElements()) {
      Object element = elements.nextElement();
      // xsl:template
      if (element instanceof Template) {
    // Separate templates by modes
    final Template template = (Template)element;
    //_templates.addElement(template);
    getMode(template.getModeName()).addTemplate(template);
      }
      // xsl:attribute-set
      else if (element instanceof AttributeSet) {
    ((AttributeSet)element).translate(classGen, null);
      }
      else if (element instanceof Output) {
    // save the element for later to pass to compileConstructor
    Output output = (Output)element;
    if (output.enabled()) _lastOutputElement = output;
      }
      else {
    // Global variables and parameters are handled elsewhere.
    // Other top-level non-template elements are ignored. Literal
    // elements outside of templates will never be output.
      }
  }

  checkOutputMethod();
  processModes();
  compileModes(classGen);
        compileStaticInitializer(classGen);
  compileConstructor(classGen, _lastOutputElement);

  if (!getParser().errorsFound()) {
      getXSLTC().dumpClass(classGen.getJavaClass());
  }
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.util.ClassGenerator

    public void translate() {
  Output lastOutputElement = null;
  _className = getXSLTC().getClassName();

  // Define a new class by extending TRANSLET_CLASS
  final ClassGenerator classGen =
      new ClassGenerator(_className,
             TRANSLET_CLASS,
             Constants.EMPTYSTRING,
             ACC_PUBLIC | ACC_SUPER,
             null, this);
 
  addDOMField(classGen);

  // Compile transform() to initialize parameters, globals & output
  // and run the transformation
  compileTransform(classGen);

  // Translate all non-template elements and filter out all templates
  final Enumeration elements = elements();
  while (elements.hasMoreElements()) {
      Object element = elements.nextElement();
      // xsl:template
      if (element instanceof Template) {
    // Separate templates by modes
    final Template template = (Template)element;
    _templates.addElement(template);
    getMode(template.getModeName()).addTemplate(template);
      }
      // xsl:attribute-set
      else if (element instanceof AttributeSet) {
    ((AttributeSet)element).translate(classGen, null);
      }
      else if (element instanceof Output) {
    // save the element for later to pass to compileConstructor
    Output output = (Output)element;
    if (output.enabled()) lastOutputElement = output;
      }
      else {
    // Global variables and parameters are handled elsewhere.
    // Other top-level non-template elements are ignored. Literal
    // elements outside of templates will never be output.
      }
  }

  processModes();
  compileModes(classGen);
  compileConstructor(classGen, lastOutputElement);

  if (!getParser().errorsFound()) {
      getXSLTC().dumpClass(classGen.getJavaClass());
  }
    }
View Full Code Here

Examples of org.apache.xalan.xsltc.compiler.util.ClassGenerator

    public void translate() {
  Output lastOutputElement = null;
  _className = getXSLTC().getClassName();

  // Define a new class by extending TRANSLET_CLASS
  final ClassGenerator classGen =
      new ClassGenerator(_className,
             TRANSLET_CLASS,
             //getXSLTC().getFileName(),
             "",
             ACC_PUBLIC | ACC_SUPER,
             null, this);
 
  addDOMField(classGen);

  // Compile a default constructor to init the namesIndex table
  //compileConstructor(classGen);

  // Compile transform() to initialize parameters, globals & output
  // and run the transformation
  compileTransform(classGen);

  // Translate all non-template elements and filter out all templates
  final Enumeration elements = elements();
  while (elements.hasMoreElements()) {
      Object element = elements.nextElement();
      // xsl:template
      if (element instanceof Template) {
    _templates.addElement(element);
   
    // Separate templates by modes
    final Template template = (Template)element;
    getMode(template.getModeName()).addTemplate(template);
      }
      // xsl:attribute-set
      else if (element instanceof AttributeSet) {
    ((AttributeSet)element).translate(classGen, null);
      }
      else if (element instanceof Output) {
    // save the element for later to pass to compileConstructor
    lastOutputElement = (Output)element;
      }
      else {
    // Global variables and parameters are handled elsewhere.
    // Other top-level non-template elements are ignored. Literal
    // elements outside of templates will never be output.
      }
  }

  processModes();
  compileModes(classGen);

  compileConstructor(classGen, lastOutputElement);

  getXSLTC().dumpClass(classGen.getJavaClass());
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

    public static ClassGenerator createInvokerClassGenerator(final String className,
                                                              final InvokerDataProvider data,
                                                              final ClassLoader classLoader,
                                                              final TypeResolver typeResolver) {
        final ClassGenerator generator = new ClassGenerator(className, classLoader, typeResolver)
                .addStaticField(ACC_PRIVATE + ACC_FINAL, "serialVersionUID", Long.TYPE, INVOKER_SERIAL_UID)
                .addDefaultConstructor();

        generator.addMethod(ACC_PUBLIC, "hashCode", generator.methodDescr(Integer.TYPE), new ClassGenerator.MethodBody() {
            public void body(MethodVisitor mv) {
                push(data.hashCode());
                mv.visitInsn(IRETURN);
            }
        })
        .addMethod(ACC_PUBLIC, "getMethodBytecode", generator.methodDescr(List.class), new GetMethodBytecodeMethod(data))
        .addMethod(ACC_PUBLIC, "equals", generator.methodDescr(Boolean.TYPE, Object.class), new EqualsMethod());

        return generator;
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

import static org.mvel2.asm.Opcodes.IASTORE;

public class ASMConditionEvaluatorJitter {

    public static ConditionEvaluator jitEvaluator(String expression, Condition condition, Declaration[] declarations, ClassLoader classLoader, LeftTuple leftTuple) {
        ClassGenerator generator = new ClassGenerator(getUniqueClassName(), classLoader)
                .setInterfaces(ConditionEvaluator.class)
                .addStaticField(ACC_PRIVATE | ACC_FINAL, "EXPRESSION", String.class, expression)
                .addField(ACC_PRIVATE | ACC_FINAL, "declarations", Declaration[].class)
                .addDefaultConstructor(new ClassGenerator.MethodBody() {
                    public void body(MethodVisitor mv) {
                        putFieldInThisFromRegistry("declarations", Declaration[].class, 1);
                        mv.visitInsn(RETURN);
                    }
                }, Declaration[].class);

        generator.addMethod(ACC_PUBLIC,
                            "evaluate",
                            generator.methodDescr(boolean.class, Object.class, InternalWorkingMemory.class, LeftTuple.class),
                            new EvaluateMethodGenerator(condition, declarations, leftTuple));

        return generator.newInstance(Declaration[].class, declarations);
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

public class ASMPredicateStubBuilder extends AbstractASMPredicateBuilder {

    protected byte[] createPredicateBytecode(final RuleBuildContext ruleContext, final Map vars) {
        final InvokerDataProvider data = new InvokerContext(vars);
        final ClassGenerator generator = InvokerGenerator.createInvokerStubGenerator(data, ruleContext);
        createStubPredicate(generator, data, vars);
        return generator.generateBytecode();
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

public class ASMEvalStubBuilder extends AbstractASMEvalBuilder {

    protected byte[] createEvalBytecode(final RuleBuildContext ruleContext, final Map vars) {
        final InvokerDataProvider data = new InvokerContext(vars);
        final ClassGenerator generator = InvokerGenerator.createInvokerStubGenerator(data, ruleContext);
        createStubEval(generator, data, vars);
        return generator.generateBytecode();
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

        if (isOr(ruleContext.getRule().getLhs())) {
            return super.createConsequenceBytecode(ruleContext, consequenceContext);
        }

        final InvokerDataProvider data = new InvokerContext(consequenceContext);
        final ClassGenerator generator = InvokerGenerator.createInvokerStubGenerator(data, ruleContext);
        createStubConsequence(generator, data, consequenceContext);
        return generator.generateBytecode();
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

public class ASMReturnValueStubBuilder extends AbstractASMReturnValueBuilder {

    protected byte[] createReturnValueBytecode(RuleBuildContext ruleContext, Map vars, boolean readLocalsFromTuple) {
        final InvokerDataProvider data = new InvokerContext(vars);
        final ClassGenerator generator = InvokerGenerator.createInvokerStubGenerator(data, ruleContext);
        createStubReturnValue(generator, data, vars);
        return generator.generateBytecode();
    }
View Full Code Here

Examples of org.drools.core.rule.builder.dialect.asm.ClassGenerator

import static org.mvel2.asm.Opcodes.*;

public class ASMConditionEvaluatorJitter {

    public static ConditionEvaluator jitEvaluator(String expression, Condition condition, Declaration[] declarations, ClassLoader classLoader, LeftTuple leftTuple) {
        ClassGenerator generator = new ClassGenerator(getUniqueClassName(), classLoader)
                .setInterfaces(ConditionEvaluator.class)
                .addStaticField(ACC_PRIVATE | ACC_FINAL, "EXPRESSION", String.class, expression)
                .addField(ACC_PRIVATE | ACC_FINAL, "declarations", Declaration[].class)
                .addDefaultConstructor(new ClassGenerator.MethodBody() {
                    public void body(MethodVisitor mv) {
                        putFieldInThisFromRegistry("declarations", Declaration[].class, 1);
                        mv.visitInsn(RETURN);
                    }
                }, Declaration[].class);

        generator.addMethod(ACC_PUBLIC,
                            "evaluate",
                            generator.methodDescr(boolean.class, InternalFactHandle.class, InternalWorkingMemory.class, LeftTuple.class),
                            new EvaluateMethodGenerator(condition, declarations, leftTuple));

        return generator.newInstance(Declaration[].class, declarations);
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.