Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ConstantPoolGen


     * for the input document are created in topLevel(), not in this method.
     * However, we still need this method to create keys for documents loaded
     * via the XPath document() function.
     */
    private String compileBuildKeys(ClassGenerator classGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();

  final org.apache.bcel.generic.Type[] argTypes = {
      Util.getJCRefType(DOM_INTF_SIG),
      Util.getJCRefType(NODE_ITERATOR_SIG),
      Util.getJCRefType(TRANSLET_OUTPUT_SIG),
View Full Code Here


     * Compile transform() into the output class. This method is used to
     * initialize global variables and global parameters. The current node
     * is set to be the document's root node.
     */
    private void compileTransform(ClassGenerator classGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();

  /*
   * Define the the method transform with the following signature:
   * void transform(DOM, NodeIterator, HandlerBase)
   */
  final org.apache.bcel.generic.Type[] argTypes =
      new org.apache.bcel.generic.Type[3];
  argTypes[0] = Util.getJCRefType(DOM_INTF_SIG);
  argTypes[1] = Util.getJCRefType(NODE_ITERATOR_SIG);
  argTypes[2] = Util.getJCRefType(TRANSLET_OUTPUT_SIG);

  final String[] argNames = new String[3];
  argNames[0] = DOCUMENT_PNAME;
  argNames[1] = ITERATOR_PNAME;
  argNames[2] = TRANSLET_OUTPUT_PNAME;

  final InstructionList il = new InstructionList();
  final MethodGenerator transf =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames,
        "transform",
        _className,
        il,
        classGen.getConstantPool());
  transf.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize current with the root node
  final LocalVariableGen current =
      transf.addLocalVariable("current",
            org.apache.bcel.generic.Type.INT,
            null, null);
  final String applyTemplatesSig = classGen.getApplyTemplatesSig();
  final int applyTemplates = cpg.addMethodref(getClassName(),
                "applyTemplates",
                applyTemplatesSig);
  final int domField = cpg.addFieldref(getClassName(),
               DOM_FIELD,
               DOM_INTF_SIG);

  // push translet for PUTFIELD
  il.append(classGen.loadTranslet());
  // prepare appropriate DOM implementation
 
  if (isMultiDocument()) {
      il.append(new NEW(cpg.addClass(MULTI_DOM_CLASS)));
      il.append(DUP);
  }
 
  il.append(classGen.loadTranslet());
  il.append(transf.loadDOM());
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                 "makeDOMAdapter",
                 "("+DOM_INTF_SIG+")"+
                 DOM_ADAPTER_SIG)));
  // DOMAdapter is on the stack

  if (isMultiDocument()) {
      final int init = cpg.addMethodref(MULTI_DOM_CLASS,
                "<init>",
                "("+DOM_INTF_SIG+")V");
      il.append(new INVOKESPECIAL(init));
      // MultiDOM is on the stack
  }
 
  //store to _dom variable
  il.append(new PUTFIELD(domField));

  // continue with globals initialization
  final int gitr = cpg.addInterfaceMethodref(DOM_INTF,
              "getIterator",
              "()"+NODE_ITERATOR_SIG);
  il.append(transf.loadDOM());
  il.append(new INVOKEINTERFACE(gitr, 1));
        il.append(transf.nextNode());
  current.setStart(il.append(new ISTORE(current.getIndex())));

  // Transfer the output settings to the output post-processor
  il.append(classGen.loadTranslet());
  il.append(transf.loadHandler());
  final int index = cpg.addMethodref(TRANSLET_CLASS,
             "transferOutputSettings",
             "("+OUTPUT_HANDLER_SIG+")V");
  il.append(new INVOKEVIRTUAL(index));

        /*
         * Compile buildKeys() method. Note that this method is not
         * invoked here as keys for the input document are now created
         * in topLevel(). However, this method is still needed by the
         * LoadDocument class.
         */       
        final String keySig = compileBuildKeys(classGen);
        final int keyIdx = cpg.addMethodref(getClassName(),
                                               "buildKeys", keySig);
               
        // Look for top-level elements that need handling
  final Enumeration toplevel = elements();
  if (_globals.size() > 0 || toplevel.hasMoreElements()) {
      // Compile method for handling top-level elements
      final String topLevelSig = compileTopLevel(classGen);
      // Get a reference to that method
      final int topLevelIdx = cpg.addMethodref(getClassName(),
                 "topLevel",
                 topLevelSig);
      // Push all parameters on the stack and call topLevel()
      il.append(classGen.loadTranslet()); // The 'this' pointer
      il.append(classGen.loadTranslet());
View Full Code Here

     * create one entry in this key's index for each node in the set.
     */
    public void traverseNodeSet(ClassGenerator classGen,
        MethodGenerator methodGen,
        int buildKeyIndex) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // DOM.getStringValueX(nodeIndex) => String
  final int getNodeValue = cpg.addInterfaceMethodref(DOM_INTF,
                 GET_NODE_VALUE,
                 "(I)"+STRING_SIG);
                
  final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
                 "getNodeIdent",
                 "(I)"+NODE_SIG)
                
  // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
  final int keyDom = cpg.addMethodref(TRANSLET_CLASS,
           "setKeyIndexDom",
           "("+STRING_SIG+DOM_INTF_SIG+")V");        
                           

  // This variable holds the id of the node we found with the "match"
View Full Code Here

     * Gather all nodes that match the expression in the attribute "match"
     * and add one (or more) entries in this key's index.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final int current = methodGen.getLocalIndex("current");

  // AbstractTranslet.buildKeyIndex(name,node_id,value) => void
  final int key = cpg.addMethodref(TRANSLET_CLASS,
           "buildKeyIndex",
           "("+STRING_SIG+"I"+OBJECT_SIG+")V");
          
  // AbstractTranslet.SetKeyIndexDom(name, Dom) => void
  final int keyDom = cpg.addMethodref(TRANSLET_CLASS,
           "setKeyIndexDom",
           "("+STRING_SIG+DOM_INTF_SIG+")V");
          
  final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
                 "getNodeIdent",
                 "(I)"+NODE_SIG);                   

  // DOM.getAxisIterator(root) => NodeIterator
  final int git = cpg.addInterfaceMethodref(DOM_INTF,
              "getAxisIterator",
              "(I)"+NODE_ITERATOR_SIG);

  il.append(methodGen.loadCurrentNode());
  il.append(methodGen.loadIterator());
View Full Code Here

    }

    private void compileDefault(ClassGenerator classGen,
              MethodGenerator methodGen) {
  int index;
  ConstantPoolGen cpg = classGen.getConstantPool();
  InstructionList il = methodGen.getInstructionList();

  int[] fieldIndexes = getXSLTC().getNumberFieldIndexes();

  if (fieldIndexes[_level] == -1) {
      Field defaultNode = new Field(ACC_PRIVATE,
            cpg.addUtf8(FieldNames[_level]),
            cpg.addUtf8(NODE_COUNTER_SIG),
            null,
            cpg.getConstantPool());

      // Add a new private field to this class
      classGen.addField(defaultNode);

      // Get a reference to the newly added field
      fieldIndexes[_level] = cpg.addFieldref(classGen.getClassName(),
               FieldNames[_level],
               NODE_COUNTER_SIG);
  }

  // Check if field is initialized (runtime)
  il.append(classGen.loadTranslet());
  il.append(new GETFIELD(fieldIndexes[_level]));
  final BranchHandle ifBlock1 = il.append(new IFNONNULL(null));

  // Create an instance of DefaultNodeCounter
  index = cpg.addMethodref(ClassNames[_level],
         "getDefaultNodeCounter",
         "(" + TRANSLET_INTF_SIG
         + DOM_INTF_SIG
         + NODE_ITERATOR_SIG
         + ")" + NODE_COUNTER_SIG);
View Full Code Here

     * simply calls the same constructor in the super class.
     */
    private void compileConstructor(ClassGenerator classGen) {
  MethodGenerator cons;
  final InstructionList il = new InstructionList();
  final ConstantPoolGen cpg = classGen.getConstantPool();

  cons = new MethodGenerator(ACC_PUBLIC,
           org.apache.bcel.generic.Type.VOID,
           new org.apache.bcel.generic.Type[] {
               Util.getJCRefType(TRANSLET_INTF_SIG),
               Util.getJCRefType(DOM_INTF_SIG),
               Util.getJCRefType(NODE_ITERATOR_SIG)
           },
           new String[] {
               "dom",
               "translet",
               "iterator"
           },
           "<init>", _className, il, cpg);

  il.append(ALOAD_0);     // this
  il.append(ALOAD_1);     // translet
  il.append(ALOAD_2);     // DOM
  il.append(new ALOAD(3));// iterator

  int index = cpg.addMethodref(ClassNames[_level],
             "<init>",
             "(" + TRANSLET_INTF_SIG
             + DOM_INTF_SIG
             + NODE_ITERATOR_SIG
             + ")V");
View Full Code Here

             MatchGenerator matchGen,
             InstructionList il)
    {
  int field;
  LocalVariableGen local;
  ConstantPoolGen cpg = nodeCounterGen.getConstantPool();

  // Get NodeCounter._iterator and store locally
  local = matchGen.addLocalVariable("iterator",
            Util.getJCRefType(NODE_ITERATOR_SIG),
            null, null);
  field = cpg.addFieldref(NODE_COUNTER, "_iterator",
        ITERATOR_FIELD_SIG);
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  local.setStart(il.append(new ASTORE(local.getIndex())));
  matchGen.setIteratorIndex(local.getIndex());
 
  // Get NodeCounter._translet and store locally
  local = matchGen.addLocalVariable("translet",
          Util.getJCRefType(TRANSLET_SIG),
          null, null);
  field = cpg.addFieldref(NODE_COUNTER, "_translet",
        "Lorg/apache/xalan/xsltc/Translet;");
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  il.append(new CHECKCAST(cpg.addClass(TRANSLET_CLASS)));
  local.setStart(il.append(new ASTORE(local.getIndex())));
  nodeCounterGen.setTransletIndex(local.getIndex());

  // Get NodeCounter._document and store locally
  local = matchGen.addLocalVariable("document",
            Util.getJCRefType(DOM_INTF_SIG),
            null, null);
  field = cpg.addFieldref(_className, "_document", DOM_INTF_SIG);
  il.append(ALOAD_0); // 'this' pointer on stack
  il.append(new GETFIELD(field));
  // Make sure we have the correct DOM type on the stack!!!
  local.setStart(il.append(new ASTORE(local.getIndex())));
  matchGen.setDomIndex(local.getIndex());
View Full Code Here

              toString(),
              ACC_PUBLIC | ACC_SUPER,
              null,
              classGen.getStylesheet());
  InstructionList il = null;
  ConstantPoolGen cpg = nodeCounterGen.getConstantPool();

  // Add a new instance variable for each var in closure
  final int closureLen = (_closureVars == null) ? 0 :
      _closureVars.size();

  for (int i = 0; i < closureLen; i++) {
      VariableBase var =
    ((VariableRefBase) _closureVars.get(i)).getVariable();

      nodeCounterGen.addField(new Field(ACC_PUBLIC,
          cpg.addUtf8(var.getEscapedName()),
          cpg.addUtf8(var.getType().toSignature()),
          null, cpg.getConstantPool()));
  }

  // Add a single constructor to the class
  compileConstructor(nodeCounterGen);

  /*
   * Compile method matchesFrom()
   */
  if (_from != null) {
      il = new InstructionList();
      matchGen =
    new MatchGenerator(ACC_PUBLIC | ACC_FINAL,
           org.apache.bcel.generic.Type.BOOLEAN,
           new org.apache.bcel.generic.Type[] {
               org.apache.bcel.generic.Type.INT,
           },
           new String[] {
               "node",
           },
           "matchesFrom", _className, il, cpg);

      compileLocals(nodeCounterGen,matchGen,il);

      // Translate Pattern
      il.append(matchGen.loadContextNode());
      _from.translate(nodeCounterGen, matchGen);
      _from.synthesize(nodeCounterGen, matchGen);
      il.append(IRETURN);
       
      nodeCounterGen.addMethod(matchGen);
  }

  /*
   * Compile method matchesCount()
   */
  if (_count != null) {
      il = new InstructionList();
      matchGen = new MatchGenerator(ACC_PUBLIC | ACC_FINAL,
            org.apache.bcel.generic.Type.BOOLEAN,
            new org.apache.bcel.generic.Type[] {
                org.apache.bcel.generic.Type.INT,
            },
            new String[] {
                "node",
            },
            "matchesCount", _className, il, cpg);

      compileLocals(nodeCounterGen,matchGen,il);
     
      // Translate Pattern
      il.append(matchGen.loadContextNode());
      _count.translate(nodeCounterGen, matchGen);
      _count.synthesize(nodeCounterGen, matchGen);
     
      il.append(IRETURN);
       
      nodeCounterGen.addMethod(matchGen);
  }
 
  getXSLTC().dumpClass(nodeCounterGen.getJavaClass());

  // Push an instance of the newly created class
  cpg = classGen.getConstantPool();
  il = methodGen.getInstructionList();

  final int index = cpg.addMethodref(_className, "<init>",
             "(" + TRANSLET_INTF_SIG
             + DOM_INTF_SIG
             + NODE_ITERATOR_SIG
             + ")V");
  il.append(new NEW(cpg.addClass(_className)));
  il.append(DUP);
  il.append(classGen.loadTranslet());
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadIterator());
  il.append(new INVOKESPECIAL(index));

  // Initialize closure variables
  for (int i = 0; i < closureLen; i++) {
      final VariableRefBase varRef = (VariableRefBase) _closureVars.get(i);
      final VariableBase var = varRef.getVariable();
      final Type varType = var.getType();

      // Store variable in new closure
      il.append(DUP);
      il.append(var.loadInstruction());
      il.append(new PUTFIELD(
        cpg.addFieldref(_className, var.getEscapedName(),
      varType.toSignature())));
  }
    }
View Full Code Here

  }
    }

    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  int index;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Push "this" for the call to characters()
  il.append(classGen.loadTranslet());

  if (hasValue()) {
      compileDefault(classGen, methodGen);
      _value.translate(classGen, methodGen);

      // Using java.lang.Math.floor(number + 0.5) to return a double value
            il.append(new PUSH(cpg, 0.5));
            il.append(DADD);
      index = cpg.addMethodref(MATH_CLASS, "floor", "(D)D");
      il.append(new INVOKESTATIC(index));

      // Call setValue on the node counter
      index = cpg.addMethodref(NODE_COUNTER,
             "setValue",
             "(D)" + NODE_COUNTER_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }
  else if (isDefault()) {
      compileDefault(classGen, methodGen);
  }
  else {
      compilePatterns(classGen, methodGen);
  }

  // Call setStartNode()
  if (!hasValue()) {
      il.append(methodGen.loadContextNode());
      index = cpg.addMethodref(NODE_COUNTER,
             SET_START_NODE,
             "(I)" + NODE_COUNTER_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }

  // Call getCounter() with or without args
  if (_formatNeeded) {
      if (_format != null) {
    _format.translate(classGen, methodGen);
      }
      else {
    il.append(new PUSH(cpg, "1"));
      }

      if (_lang != null) {
    _lang.translate(classGen, methodGen);
      }
      else {
    il.append(new PUSH(cpg, "en"));   // TODO ??
      }

      if (_letterValue != null) {
    _letterValue.translate(classGen, methodGen);
      }
      else {
    il.append(new PUSH(cpg, Constants.EMPTYSTRING));
      }

      if (_groupingSeparator != null) {
    _groupingSeparator.translate(classGen, methodGen);
      }
      else {
    il.append(new PUSH(cpg, Constants.EMPTYSTRING));
      }

      if (_groupingSize != null) {
    _groupingSize.translate(classGen, methodGen);
      }
      else {
    il.append(new PUSH(cpg, "0"));
      }

      index = cpg.addMethodref(NODE_COUNTER, "getCounter",
             "(" + STRING_SIG + STRING_SIG
             + STRING_SIG + STRING_SIG
             + STRING_SIG + ")" + STRING_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }
  else {
      index = cpg.addMethodref(NODE_COUNTER, "setDefaultFormatting",
             "()" + NODE_COUNTER_SIG);
      il.append(new INVOKEVIRTUAL(index));

      index = cpg.addMethodref(NODE_COUNTER, "getCounter",
             "()" + STRING_SIG);
      il.append(new INVOKEVIRTUAL(index));
  }

  // Output the resulting string to the handler
  il.append(methodGen.loadHandler());
  index = cpg.addMethodref(TRANSLET_CLASS,
         CHARACTERSW,
         CHARACTERSW_SIG);
  il.append(new INVOKEVIRTUAL(index));
    }
View Full Code Here

     * Calls to 'function-available' are resolved at compile time since
     * the namespaces declared in the stylsheet are not available at run
     * time. Consequently, arguments to this function must be literals.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  methodGen.getInstructionList().append(new PUSH(cpg, getResult()));
    }
View Full Code Here

TOP

Related Classes of org.apache.bcel.generic.ConstantPoolGen

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.