Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.InstructionList


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

  final InstructionList mainIL = new InstructionList();
  final MethodGenerator methodGen =
      new MethodGenerator(ACC_PUBLIC | ACC_FINAL,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames, functionName()+'_'+max,
        getClassName(), mainIL,
        classGen.getConstantPool());
  methodGen.addException("org.apache.xalan.xsltc.TransletException");

  // Create the local variable to hold the current node
  final LocalVariableGen current;
  current = methodGen.addLocalVariable2("current",
                org.apache.bcel.generic.Type.INT,
                mainIL.getEnd());
  _currentIndex = current.getIndex();

  // Create the "body" instruction list that will eventually hold the
  // code for the entire method (other ILs will be appended).
  final InstructionList body = new InstructionList();
  body.append(NOP);

  // Create an instruction list that contains the default next-node
  // iteration
  final InstructionList ilLoop = new InstructionList();
  ilLoop.append(methodGen.loadIterator());
  ilLoop.append(methodGen.nextNode());
  ilLoop.append(DUP);
  ilLoop.append(new ISTORE(_currentIndex));

  // The body of this code can get very large - large than can be handled
  // by a single IFNE(body.getStart()) instruction - need workaround:
        final BranchHandle ifeq = ilLoop.append(new IFEQ(null));
  final BranchHandle loop = ilLoop.append(new GOTO_W(null));
  ifeq.setTarget(ilLoop.append(RETURN)); // applyTemplates() ends here!
  final InstructionHandle ihLoop = ilLoop.getStart();

  // Compile default handling of elements (traverse children)
  InstructionList ilRecurse =
      compileDefaultRecursion(classGen, methodGen, ihLoop);
  InstructionHandle ihRecurse = ilRecurse.getStart();

  // Compile default handling of text/attribute nodes (output text)
  InstructionList ilText =
      compileDefaultText(classGen, methodGen, ihLoop);
  InstructionHandle ihText = ilText.getStart();

  // Distinguish attribute/element/namespace tests for further processing
  final int[] types = new int[DOM.NTYPES + names.size()];
  for (int i = 0; i < types.length; i++) {
      types[i] = i;
  }

  final boolean[] isAttribute = new boolean[types.length];
  final boolean[] isNamespace = new boolean[types.length];
  for (int i = 0; i < names.size(); i++) {
      final String name = (String)names.elementAt(i);
      isAttribute[i+DOM.NTYPES] = isAttributeName(name);
      isNamespace[i+DOM.NTYPES] = isNamespaceName(name);
  }

  // Compile all templates - regardless of pattern type
  compileTemplateCalls(classGen, methodGen, ihLoop, min, max);

  // Handle template with explicit "*" pattern
  final TestSeq elemTest = _testSeq[DOM.ELEMENT];
  InstructionHandle ihElem = ihRecurse;
  if (elemTest != null) {
      ihElem = elemTest.compile(classGen, methodGen, ihLoop);
  }

  // Handle template with explicit "@*" pattern
  final TestSeq attrTest = _testSeq[DOM.ATTRIBUTE];
  InstructionHandle ihAttr = ihLoop;
  if (attrTest != null) {
      ihAttr = attrTest.compile(classGen, methodGen, ihAttr);
  }

  // Do tests for id() and key() patterns first
  InstructionList ilKey = null;
  if (_idxTestSeq != null) {
      loop.setTarget(_idxTestSeq.compile(classGen, methodGen, body.getStart()));
      ilKey = _idxTestSeq.getInstructionList();
  }
  else {
      loop.setTarget(body.getStart());
  }

  // If there is a match on node() we need to replace ihElem
  // and ihText if the priority of node() is higher
  if (_childNodeTestSeq != null) {
      // Compare priorities of node() and "*"
      double nodePrio = _childNodeTestSeq.getPriority();
      int    nodePos  = _childNodeTestSeq.getPosition();
      double elemPrio = (0 - Double.MAX_VALUE);
      int    elemPos  = Integer.MIN_VALUE;

      if (elemTest != null) {
    elemPrio = elemTest.getPriority();
    elemPos  = elemTest.getPosition();
      }

      if (elemPrio == Double.NaN || elemPrio < nodePrio ||
    (elemPrio == nodePrio && elemPos < nodePos))
      {
    ihElem = _childNodeTestSeq.compile(classGen, methodGen, ihLoop);
      }

      // Compare priorities of node() and text()
      final TestSeq textTest = _testSeq[DOM.TEXT];
      double textPrio = (0 - Double.MAX_VALUE);
      int    textPos  = Integer.MIN_VALUE;

      if (textTest != null) {
    textPrio = textTest.getPriority();
    textPos  = textTest.getPosition();
      }

      if (textPrio == Double.NaN || textPrio < nodePrio ||
          (textPrio == nodePrio && textPos < nodePos))
      {
    ihText = _childNodeTestSeq.compile(classGen, methodGen, ihLoop);
    _testSeq[DOM.TEXT] = _childNodeTestSeq;
      }
  }

  // Handle templates with "ns:*" pattern
  InstructionHandle elemNamespaceHandle = ihElem;
  InstructionList nsElem = compileNamespaces(classGen, methodGen,
               isNamespace, isAttribute,
               false, ihElem);
  if (nsElem != null) elemNamespaceHandle = nsElem.getStart();

  // Handle templates with "ns:@*" pattern
  InstructionList nsAttr = compileNamespaces(classGen, methodGen,
               isNamespace, isAttribute,
               true, ihAttr);
  InstructionHandle attrNamespaceHandle = ihAttr;
  if (nsAttr != null) attrNamespaceHandle = nsAttr.getStart();

  // Handle templates with "ns:elem" or "ns:@attr" pattern
  final InstructionHandle[] targets = new InstructionHandle[types.length];
  for (int i = DOM.NTYPES; i < targets.length; i++) {
      final TestSeq testSeq = _testSeq[i];
View Full Code Here


    /**
     * Peephole optimization: Remove sequences of [ALOAD, POP].
     */
    private void peepHoleOptimization(MethodGenerator methodGen) {
  InstructionList il = methodGen.getInstructionList();
  InstructionFinder find = new InstructionFinder(il);
  InstructionHandle ih;
  String pattern;

  // Remove seqences of ALOAD, POP (GTM)
  pattern = "`ALOAD'`POP'`Instruction'";
  for(Iterator iter=find.search(pattern); iter.hasNext();){
      InstructionHandle[] match = (InstructionHandle[])iter.next();
      try {
    if ((!match[0].hasTargeters()) && (!match[1].hasTargeters())) {
                    il.delete(match[0], match[1]);
                }
      }
      catch (TargetLostException e) {
                // TODO: move target down into the list
            }
  }
  // Replace sequences of ILOAD_?, ALOAD_?, SWAP with ALOAD_?, ILOAD_?
  pattern = "`ILOAD'`ALOAD'`SWAP'`Instruction'";
  for(Iterator iter=find.search(pattern); iter.hasNext();){
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
                org.apache.bcel.generic.Instruction iload;
                org.apache.bcel.generic.Instruction aload;
                if ((!match[0].hasTargeters()) &&
                    (!match[1].hasTargeters()) &&
                    (!match[2].hasTargeters())) {
                    iload = match[0].getInstruction();
                    aload = match[1].getInstruction();
                    il.insert(match[0], aload);
                    il.insert(match[0], iload);
                    il.delete(match[0], match[2]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
        }

        // Replace sequences of ALOAD_1, ALOAD_1 with ALOAD_1, DUP
  pattern = "`ALOAD_1'`ALOAD_1'`Instruction'";
        for(Iterator iter=find.search(pattern); iter.hasNext();){
            InstructionHandle[] match = (InstructionHandle[])iter.next();
            try {
          org.apache.bcel.generic.Instruction iload;
                org.apache.bcel.generic.Instruction aload;
                if ((!match[0].hasTargeters()) && (!match[1].hasTargeters())) {
                    il.insert(match[1], new DUP());
                    il.delete(match[1]);
                }
            }
            catch (TargetLostException e) {
                // TODO: move target down into the list
            }
View Full Code Here

  return _type = Type.String;
    }
   
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  // Feck the this pointer on the stack...
  il.append(classGen.loadTranslet());
  // ...then the entity name...
  _entity.translate(classGen, methodGen);
  // ...to get the value from the hashtable in AbstractTranslet.
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                 "getUnparsedEntity",
                 "(Ljava/lang/String;)"+
                 "Ljava/lang/String;")));
    }
View Full Code Here

     */
    public void translate(ClassGenerator classGen,
        MethodGenerator methodGen) {

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Returns the KeyIndex object of a given name
  final int getKeyIndex = cpg.addMethodref(TRANSLET_CLASS,
             "getKeyIndex",
             "(Ljava/lang/String;)"+
             KEY_INDEX_SIG);
 
  // Initialises a KeyIndex to return nodes with specific values
  final int lookupId = cpg.addMethodref(KEY_INDEX_CLASS,
                "containsID",
                "(ILjava/lang/Object;)I");
  final int lookupKey = cpg.addMethodref(KEY_INDEX_CLASS,
                 "containsKey",
                 "(ILjava/lang/Object;)I");
  final int getNodeIdent = cpg.addInterfaceMethodref(DOM_INTF,
                 "getNodeIdent",
                 "(I)"+NODE_SIG);              

  // Call getKeyIndex in AbstractTranslet with the name of the key
  // to get the index for this key (which is also a node iterator).
  il.append(classGen.loadTranslet());
  il.append(new PUSH(cpg,_index));
  il.append(new INVOKEVIRTUAL(getKeyIndex));
 
  // Now use the value in the second argument to determine what nodes
  // the iterator should return.
  il.append(SWAP);
  il.append(new PUSH(cpg,_value));
  if (this instanceof IdPattern)
  {
      il.append(new INVOKEVIRTUAL(lookupId));
  }
  else
  {
      il.append(new INVOKEVIRTUAL(lookupKey));
  }

  _trueList.add(il.append(new IFNE(null)));
  _falseList.add(il.append(new GOTO(null)));
    }
View Full Code Here

              MethodGenerator methodGen,
              Expression nodeSet,
              Vector sortObjects)
    {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // SortingIterator.SortingIterator(NodeIterator,NodeSortRecordFactory);
  final int init = cpg.addMethodref(SORT_ITERATOR, "<init>",
            "("
            + NODE_ITERATOR_SIG
            + NODE_SORT_FACTORY_SIG
            + ")V")

        // Backwards branches are prohibited if an uninitialized object is
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
        // We don't know whether this code might contain backwards branches
        // so we mustn't create the new object until after we've created
        // the suspect arguments to its constructor.  Instead we calculate
        // the values of the arguments to the constructor first, store them
        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

        LocalVariableGen nodesTemp =
            methodGen.addLocalVariable("sort_tmp1",
                                       Util.getJCRefType(NODE_ITERATOR_SIG),
                                       null, null);

        LocalVariableGen sortRecordFactoryTemp =
            methodGen.addLocalVariable("sort_tmp2",
                                      Util.getJCRefType(NODE_SORT_FACTORY_SIG),
                                      null, null);

  // Get the current node iterator
  if (nodeSet == null) {  // apply-templates default
      final int children = cpg.addInterfaceMethodref(DOM_INTF,
                 "getAxisIterator",
                 "(I)"+
                 NODE_ITERATOR_SIG);
      il.append(methodGen.loadDOM());
      il.append(new PUSH(cpg, Axis.CHILD));
      il.append(new INVOKEINTERFACE(children, 2));
  }
  else {
      nodeSet.translate(classGen, methodGen);
  }

        nodesTemp.setStart(il.append(new ASTORE(nodesTemp.getIndex())));
 
  // Compile the code for the NodeSortRecord producing class and pass
  // that as the last argument to the SortingIterator constructor.
  compileSortRecordFactory(sortObjects, classGen, methodGen);
        sortRecordFactoryTemp.setStart(
                il.append(new ASTORE(sortRecordFactoryTemp.getIndex())));

  il.append(new NEW(cpg.addClass(SORT_ITERATOR)));
  il.append(DUP);
        nodesTemp.setEnd(il.append(new ALOAD(nodesTemp.getIndex())));
        sortRecordFactoryTemp.setEnd(
                il.append(new ALOAD(sortRecordFactoryTemp.getIndex())));
  il.append(new INVOKESPECIAL(init));
    }
View Full Code Here

    compileSortRecordFactory(sortObjects, classGen, methodGen,
        sortRecordClass);
  }

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

        // Backwards branches are prohibited if an uninitialized object is
        // on the stack by section 4.9.4 of the JVM Specification, 2nd Ed.
        // We don't know whether this code might contain backwards branches
        // so we mustn't create the new object until after we've created
        // the suspect arguments to its constructor.  Instead we calculate
        // the values of the arguments to the constructor first, store them
        // in temporary variables, create the object and reload the
        // arguments from the temporaries to avoid the problem.

  // Compile code that initializes the static _sortOrder
        LocalVariableGen sortOrderTemp
                 = methodGen.addLocalVariable("sort_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortOrder(classGen, methodGen);
      il.append(AASTORE);
  }
        sortOrderTemp.setStart(il.append(new ASTORE(sortOrderTemp.getIndex())));

        LocalVariableGen sortTypeTemp
                 = methodGen.addLocalVariable("sort_type_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
  il.append(new PUSH(cpg, nsorts));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));
  for (int level = 0; level < nsorts; level++) {
      final Sort sort = (Sort)sortObjects.elementAt(level);
      il.append(DUP);
      il.append(new PUSH(cpg, level));
      sort.translateSortType(classGen, methodGen);
      il.append(AASTORE);
  }
        sortTypeTemp.setStart(il.append(new ASTORE(sortTypeTemp.getIndex())));

        LocalVariableGen sortLangTemp
                 = methodGen.addLocalVariable("sort_lang_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
              final Sort sort = (Sort)sortObjects.elementAt(level);
              il.append(DUP);
              il.append(new PUSH(cpg, level));
              sort.translateLang(classGen, methodGen);
              il.append(AASTORE);
        }
        sortLangTemp.setStart(il.append(new ASTORE(sortLangTemp.getIndex())));

        LocalVariableGen sortCaseOrderTemp
                 = methodGen.addLocalVariable("sort_case_order_tmp",
                                      Util.getJCRefType("[" + STRING_SIG),
                                      null, null);
        il.append(new PUSH(cpg, nsorts));
        il.append(new ANEWARRAY(cpg.addClass(STRING)));
        for (int level = 0; level < nsorts; level++) {
            final Sort sort = (Sort)sortObjects.elementAt(level);
            il.append(DUP);
            il.append(new PUSH(cpg, level));
            sort.translateCaseOrder(classGen, methodGen);
            il.append(AASTORE);
        }
        sortCaseOrderTemp.setStart(
                il.append(new ASTORE(sortCaseOrderTemp.getIndex())));
 
  il.append(new NEW(cpg.addClass(sortRecordFactoryClass)));
  il.append(DUP);
  il.append(methodGen.loadDOM());
  il.append(new PUSH(cpg, sortRecordClass));
  il.append(classGen.loadTranslet());

        sortOrderTemp.setEnd(il.append(new ALOAD(sortOrderTemp.getIndex())));
        sortTypeTemp.setEnd(il.append(new ALOAD(sortTypeTemp.getIndex())));
        sortLangTemp.setEnd(il.append(new ALOAD(sortLangTemp.getIndex())));
        sortCaseOrderTemp.setEnd(
                il.append(new ALOAD(sortCaseOrderTemp.getIndex())));

  il.append(new INVOKESPECIAL(
      cpg.addMethodref(sortRecordFactoryClass, "<init>",
    "(" + DOM_INTF_SIG
        + STRING_SIG
        + TRANSLET_INTF_SIG
        + "[" + STRING_SIG
                    + "[" + STRING_SIG
                    + "[" + STRING_SIG
        + "[" + STRING_SIG + ")V")));

  // Initialize closure variables in sortRecordFactory
  final ArrayList dups = new ArrayList();

  for (int j = 0; j < nsorts; j++) {
      final Sort sort = (Sort) sortObjects.get(j);
      final int length = (sort._closureVars == null) ? 0 :
    sort._closureVars.size();

      for (int i = 0; i < length; i++) {
    VariableRefBase varRef = (VariableRefBase) sort._closureVars.get(i);

    // Discard duplicate variable references
    if (dups.contains(varRef)) continue;

    final VariableBase var = varRef.getVariable();

    // Store variable in new closure
    il.append(DUP);
    il.append(var.loadInstruction());
    il.append(new PUTFIELD(
      cpg.addFieldref(sortRecordFactoryClass, var.getEscapedName(),
          var.getType().toSignature())));
    dups.add(varRef);
      }
  }
View Full Code Here

  argNames[4] = "type";
  argNames[5] = "lang";
  argNames[6] = "case_order";
 

  InstructionList il = new InstructionList();
  final MethodGenerator constructor =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames, "<init>",
        className, il, cpg);

  // Push all parameters onto the stack and called super.<init>()
  il.append(ALOAD_0);
  il.append(ALOAD_1);
  il.append(ALOAD_2);
  il.append(new ALOAD(3));
  il.append(new ALOAD(4));
  il.append(new ALOAD(5));
  il.append(new ALOAD(6));
  il.append(new ALOAD(7));
  il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
      "<init>",
      "(" + DOM_INTF_SIG
    + STRING_SIG
    + TRANSLET_INTF_SIG
    + "[" + STRING_SIG
    + "[" + STRING_SIG
    + "[" + STRING_SIG
    + "[" + STRING_SIG + ")V")));
  il.append(RETURN);

  // Override the definition of makeNodeSortRecord()
  il = new InstructionList();
  final MethodGenerator makeNodeSortRecord =
      new MethodGenerator(ACC_PUBLIC,
    Util.getJCRefType(NODE_SORT_RECORD_SIG),
    new org.apache.bcel.generic.Type[] {
        org.apache.bcel.generic.Type.INT,
        org.apache.bcel.generic.Type.INT },
    new String[] { "node", "last" }, "makeNodeSortRecord",
    className, il, cpg);

  il.append(ALOAD_0);
  il.append(ILOAD_1);
  il.append(ILOAD_2);
  il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_FACTORY,
      "makeNodeSortRecord", "(II)" + NODE_SORT_RECORD_SIG)));
  il.append(DUP);
  il.append(new CHECKCAST(cpg.addClass(sortRecordClass)));

  // Initialize closure in record class
  final int ndups = dups.size();
  for (int i = 0; i < ndups; i++) {
      final VariableRefBase varRef = (VariableRefBase) dups.get(i);
      final VariableBase var = varRef.getVariable();
      final Type varType = var.getType();
     
      il.append(DUP);

      // Get field from factory class
      il.append(ALOAD_0);
      il.append(new GETFIELD(
    cpg.addFieldref(className,
        var.getEscapedName(), varType.toSignature())));

      // Put field in record class
      il.append(new PUTFIELD(
    cpg.addFieldref(sortRecordClass,
        var.getEscapedName(), varType.toSignature())));
  }
  il.append(POP);
  il.append(ARETURN);

  constructor.setMaxLocals();
  constructor.setMaxStack();
  sortRecordFactory.addMethod(constructor);
  makeNodeSortRecord.setMaxLocals();
View Full Code Here

    private static MethodGenerator compileInit(Vector sortObjects,
             NodeSortRecordGenerator sortRecord,
             ConstantPoolGen cpg,
             String className)
    {
  final InstructionList il = new InstructionList();
  final MethodGenerator init =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        null, null, "<init>", className,
        il, cpg);

  // Call the constructor in the NodeSortRecord superclass
  il.append(ALOAD_0);
  il.append(new INVOKESPECIAL(cpg.addMethodref(NODE_SORT_RECORD,
                 "<init>", "()V")));

 

  il.append(RETURN);

  return init;
    }
View Full Code Here

     */
    private static MethodGenerator compileExtract(Vector sortObjects,
           NodeSortRecordGenerator sortRecord,
           ConstantPoolGen cpg,
           String className) {
  final InstructionList il = new InstructionList();
 
  // String NodeSortRecord.extractValueFromDOM(dom,node,level);
  final CompareGenerator extractMethod =
      new CompareGenerator(ACC_PUBLIC | ACC_FINAL,
         org.apache.bcel.generic.Type.STRING,
         new org.apache.bcel.generic.Type[] {
                         Util.getJCRefType(DOM_INTF_SIG),
             org.apache.bcel.generic.Type.INT,
             org.apache.bcel.generic.Type.INT,
             Util.getJCRefType(TRANSLET_SIG),
             org.apache.bcel.generic.Type.INT
         },
         new String[] { "dom",
            "current",
            "level",
            "translet",
            "last"
         },
         "extractValueFromDOM", className, il, cpg);

  // Values needed for the switch statement
  final int levels = sortObjects.size();
  final int match[] = new int[levels];
  final InstructionHandle target[] = new InstructionHandle[levels];
  InstructionHandle tblswitch = null;

  // Compile switch statement only if the key has multiple levels
  if (levels > 1) {
      // Put the parameter to the swtich statement on the stack
      il.append(new ILOAD(extractMethod.getLocalIndex("level")));
      // Append the switch statement here later on
      tblswitch = il.append(new NOP());
  }

  // Append all the cases for the switch statment
  for (int level = 0; level < levels; level++) {
      match[level] = level;
      final Sort sort = (Sort)sortObjects.elementAt(level);
      target[level] = il.append(NOP);
      sort.translateSelect(sortRecord, extractMethod);
      il.append(ARETURN);
  }
 
  // Compile def. target for switch statement if key has multiple levels
  if (levels > 1) {
      // Append the default target - it will _NEVER_ be reached
      InstructionHandle defaultTarget =
    il.append(new PUSH(cpg, EMPTYSTRING));
      il.insert(tblswitch,new TABLESWITCH(match, target, defaultTarget));
      il.append(ARETURN);
  }

  return extractMethod;
    }
View Full Code Here

     * compiled first.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

        // Check whether all attributes are unique.
        _allAttributesUnique = checkAttributesUnique();

  // Compile code to emit element start tag
  il.append(methodGen.loadHandler());
 
  il.append(new PUSH(cpg, _name));
  il.append(DUP2);     // duplicate these 2 args for endElement
  il.append(methodGen.startElement());

  // The value of an attribute may depend on a (sibling) variable
        int j=0;
        while (j < elementCount())  {
            final SyntaxTreeNode item = (SyntaxTreeNode) elementAt(j);
            if (item instanceof Variable) {
                item.translate(classGen, methodGen);
            }
            j++;
        }

  // Compile code to emit namespace attributes
  if (_accessedPrefixes != null) {
      boolean declaresDefaultNS = false;
      Enumeration e = _accessedPrefixes.keys();

      while (e.hasMoreElements()) {
    final String prefix = (String)e.nextElement();
    final String uri = (String)_accessedPrefixes.get(prefix);

    if (uri != Constants.EMPTYSTRING ||
      prefix != Constants.EMPTYSTRING)
    {
        if (prefix == Constants.EMPTYSTRING) {
      declaresDefaultNS = true;
        }
        il.append(methodGen.loadHandler());
        il.append(new PUSH(cpg,prefix));
        il.append(new PUSH(cpg,uri));
        il.append(methodGen.namespace());
    }
      }

      /*
       * If our XslElement parent redeclares the default NS, and this
       * element doesn't, it must be redeclared one more time.
       */
      if (!declaresDefaultNS && (_parent instanceof XslElement)
        && ((XslElement) _parent).declaresDefaultNS())
      {
    il.append(methodGen.loadHandler());
    il.append(new PUSH(cpg, Constants.EMPTYSTRING));
    il.append(new PUSH(cpg, Constants.EMPTYSTRING));
    il.append(methodGen.namespace());
      }
  }

  // Output all attributes
  if (_attributeElements != null) {
      final int count = _attributeElements.size();
      for (int i = 0; i < count; i++) {
    SyntaxTreeNode node =
        (SyntaxTreeNode)_attributeElements.elementAt(i);
    if (!(node instanceof XslAttribute)) {
        node.translate(classGen, methodGen);
          }
      }
  }
 
  // Compile code to emit attributes and child elements
  translateContents(classGen, methodGen);

  // Compile code to emit element end tag
  il.append(methodGen.endElement());
    }
View Full Code Here

TOP

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

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.