Examples of MethodGenerator


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

      DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current"
  };

  final InstructionList il = new InstructionList();

  final MethodGenerator buildKeys =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames,
        "buildKeys", _className, il,
        classGen.getConstantPool());

  buildKeys.addException("org.apache.xalan.xsltc.TransletException");
 
  final Enumeration elements = elements();
  while (elements.hasMoreElements()) {
      // xsl:key
      final Object element = elements.nextElement();
View Full Code Here

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

  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());
      il.append(new GETFIELD(domField))// The DOM reference
      il.append(transf.loadIterator());
      il.append(transf.loadHandler());    // The output handler
      il.append(new INVOKEVIRTUAL(topLevelIdx));
 

  // start document
  il.append(transf.loadHandler());
  il.append(transf.startDocument());

  // push first arg for applyTemplates
  il.append(classGen.loadTranslet());
  // push translet for GETFIELD to get DOM arg
  il.append(classGen.loadTranslet());
  il.append(new GETFIELD(domField));
  // push remaining 2 args
  il.append(transf.loadIterator());
  il.append(transf.loadHandler());
  il.append(new INVOKEVIRTUAL(applyTemplates));
  // endDocument
  il.append(transf.loadHandler());
  il.append(transf.endDocument());

  il.append(RETURN);

  // Compute max locals + stack and add method to class
  classGen.addMethod(transf);
View Full Code Here

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

     * Compiles a constructor for the class <tt>_className</tt> that
     * inherits from {Any,Single,Multiple}NodeCounter. This constructor
     * 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)
View Full Code Here

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

     */
    private void compileStaticInitializer(ClassGenerator classGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = new InstructionList();

  final MethodGenerator staticConst =
      new MethodGenerator(ACC_PUBLIC|ACC_STATIC,
        org.apache.bcel.generic.Type.VOID,
        null, null, "<clinit>",
        _className, il, cpg);

  addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMES_ARRAY_FIELD);
  addStaticField(classGen, "[" + STRING_SIG, STATIC_URIS_ARRAY_FIELD);
  addStaticField(classGen, "[I", STATIC_TYPES_ARRAY_FIELD);
  addStaticField(classGen, "[" + STRING_SIG, STATIC_NAMESPACE_ARRAY_FIELD);
        // Create fields of type char[] that will contain literal text from
        // the stylesheet.
        final int charDataFieldCount = getXSLTC().getCharacterDataCount();
        for (int i = 0; i < charDataFieldCount; i++) {
            addStaticField(classGen, STATIC_CHAR_DATA_FIELD_SIG,
                           STATIC_CHAR_DATA_FIELD+i);
        }

  // Put the names array into the translet - used for dom/translet mapping
  final Vector namesIndex = getXSLTC().getNamesIndex();
  int size = namesIndex.size();
  String[] namesArray = new String[size];
  String[] urisArray = new String[size];
  int[] typesArray = new int[size];
 
  int index;
  for (int i = 0; i < size; i++) {
      String encodedName = (String)namesIndex.elementAt(i);
      if ((index = encodedName.lastIndexOf(':')) > -1) {
          urisArray[i] = encodedName.substring(0, index);
      }
     
      index = index + 1;
      if (encodedName.charAt(index) == '@') {
        typesArray[i] = DTM.ATTRIBUTE_NODE;
        index++;
      } else if (encodedName.charAt(index) == '?') {
        typesArray[i] = DTM.NAMESPACE_NODE;
        index++;
      } else {
          typesArray[i] = DTM.ELEMENT_NODE;
      }
     
      if (index == 0) {
          namesArray[i] = encodedName;
      }
      else {
          namesArray[i] = encodedName.substring(index);
      }     
  }
 
  il.append(new PUSH(cpg, size));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));   

  for (int i = 0; i < size; i++) {
      final String name = namesArray[i];
      il.append(DUP);
      il.append(new PUSH(cpg, i));
      il.append(new PUSH(cpg, name));
      il.append(AASTORE);
  }
  il.append(new PUTSTATIC(cpg.addFieldref(_className,
                 STATIC_NAMES_ARRAY_FIELD,
                 NAMES_INDEX_SIG)));

  il.append(new PUSH(cpg, size));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));   

  for (int i = 0; i < size; i++) {
      final String uri = urisArray[i];
      il.append(DUP);
      il.append(new PUSH(cpg, i));
      il.append(new PUSH(cpg, uri));
      il.append(AASTORE);
  }
  il.append(new PUTSTATIC(cpg.addFieldref(_className,
                 STATIC_URIS_ARRAY_FIELD,
                 URIS_INDEX_SIG)));

  il.append(new PUSH(cpg, size));
  il.append(new NEWARRAY(BasicType.INT));   

  for (int i = 0; i < size; i++) {
      final int nodeType = typesArray[i];
      il.append(DUP);
      il.append(new PUSH(cpg, i));
      il.append(new PUSH(cpg, nodeType));
      il.append(IASTORE);
  }
  il.append(new PUTSTATIC(cpg.addFieldref(_className,
                 STATIC_TYPES_ARRAY_FIELD,
                 TYPES_INDEX_SIG)));

  // Put the namespace names array into the translet
  final Vector namespaces = getXSLTC().getNamespaceIndex();
  il.append(new PUSH(cpg, namespaces.size()));
  il.append(new ANEWARRAY(cpg.addClass(STRING)));   

  for (int i = 0; i < namespaces.size(); i++) {
      final String ns = (String)namespaces.elementAt(i);
      il.append(DUP);
      il.append(new PUSH(cpg, i));
      il.append(new PUSH(cpg, ns));
      il.append(AASTORE);
  }
  il.append(new PUTSTATIC(cpg.addFieldref(_className,
                 STATIC_NAMESPACE_ARRAY_FIELD,
                 NAMESPACE_INDEX_SIG)));

        // Grab all the literal text in the stylesheet and put it in a char[]
        final int charDataCount = getXSLTC().getCharacterDataCount();
        final int toCharArray = cpg.addMethodref(STRING, "toCharArray", "()[C");
        for (int i = 0; i < charDataCount; i++) {
            il.append(new PUSH(cpg, getXSLTC().getCharacterData(i)));
            il.append(new INVOKEVIRTUAL(toCharArray));
            il.append(new PUTSTATIC(cpg.addFieldref(_className,
                                               STATIC_CHAR_DATA_FIELD+i,
                                               STATIC_CHAR_DATA_FIELD_SIG)));
        }

  il.append(RETURN);

  staticConst.stripAttributes(true);
  staticConst.setMaxLocals();
  staticConst.setMaxStack();
  classGen.addMethod(staticConst.getMethod());
     
    }
View Full Code Here

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

    private void compileConstructor(ClassGenerator classGen, Output output) {

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

  final MethodGenerator constructor =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        null, null, "<init>",
        _className, il, cpg);

  // Call the constructor in the AbstractTranslet superclass
  il.append(classGen.loadTranslet());
  il.append(new INVOKESPECIAL(cpg.addMethodref(TRANSLET_CLASS,
                 "<init>", "()V")));
 
  il.append(classGen.loadTranslet());
  il.append(new GETSTATIC(cpg.addFieldref(_className,
                                          STATIC_NAMES_ARRAY_FIELD,
                                          NAMES_INDEX_SIG)));
  il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                         NAMES_INDEX,
                                         NAMES_INDEX_SIG)));
 
  il.append(classGen.loadTranslet());
  il.append(new GETSTATIC(cpg.addFieldref(_className,
                                          STATIC_URIS_ARRAY_FIELD,
                                          URIS_INDEX_SIG)));
  il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                         URIS_INDEX,
                                         URIS_INDEX_SIG)));

  il.append(classGen.loadTranslet());
  il.append(new GETSTATIC(cpg.addFieldref(_className,
                                          STATIC_TYPES_ARRAY_FIELD,
                                          TYPES_INDEX_SIG)));
  il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                         TYPES_INDEX,
                                         TYPES_INDEX_SIG)));

  il.append(classGen.loadTranslet());
  il.append(new GETSTATIC(cpg.addFieldref(_className,
                                          STATIC_NAMESPACE_ARRAY_FIELD,
                                          NAMESPACE_INDEX_SIG)));
  il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                         NAMESPACE_INDEX,
                                         NAMESPACE_INDEX_SIG)));

  il.append(classGen.loadTranslet());
        il.append(new PUSH(cpg, AbstractTranslet.CURRENT_TRANSLET_VERSION));
  il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                                         TRANSLET_VERSION_INDEX,
                                         TRANSLET_VERSION_INDEX_SIG)));
 
  if (_hasIdCall) {
      il.append(classGen.loadTranslet());
      il.append(new PUSH(cpg, Boolean.TRUE));
      il.append(new PUTFIELD(cpg.addFieldref(TRANSLET_CLASS,
                     HASIDCALL_INDEX,
                     HASIDCALL_INDEX_SIG)));
  }
 
  // Compile in code to set the output configuration from <xsl:output>
  if (output != null) {
      // Set all the output settings files in the translet
      output.translate(classGen, constructor);
  }

  // Compile default decimal formatting symbols.
  // This is an implicit, nameless xsl:decimal-format top-level element.
  if (_numberFormattingUsed)
      DecimalFormatting.translateDefaultDFS(classGen, constructor);

  il.append(RETURN);

  constructor.stripAttributes(true);
  constructor.setMaxLocals();
  constructor.setMaxStack();
  classGen.addMethod(constructor.getMethod());
    }
View Full Code Here

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

      DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME
  };

  final InstructionList il = new InstructionList();

  final MethodGenerator toplevel =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames,
        "topLevel", _className, il,
        classGen.getConstantPool());

  toplevel.addException("org.apache.xalan.xsltc.TransletException");

  // Define and initialize 'current' variable with the root node
  final LocalVariableGen current =
      toplevel.addLocalVariable("current",
            org.apache.bcel.generic.Type.INT,
            il.getEnd(), null);

  final int setFilter = cpg.addInterfaceMethodref(DOM_INTF,
             "setFilter",
             "(Lorg/apache/xalan/xsltc/StripFilter;)V");

  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  il.append(new ISTORE(current.getIndex()));

  // Resolve any forward referenes and translate global variables/params
  _globals = resolveReferences(_globals);
  final int count = _globals.size();
  for (int i = 0; i < count; i++) {
      final VariableBase var = (VariableBase)_globals.elementAt(i);
      var.translate(classGen,toplevel);
  }

  // Compile code for other top-level elements
  Vector whitespaceRules = new Vector();
  while (elements.hasMoreElements()) {
      final Object element = elements.nextElement();
      // xsl:decimal-format
      if (element instanceof DecimalFormatting) {
    ((DecimalFormatting)element).translate(classGen,toplevel);
      }
      // xsl:strip/preserve-space
      else if (element instanceof Whitespace) {
    whitespaceRules.addAll(((Whitespace)element).getRules());
      }
  }

  // Translate all whitespace strip/preserve rules
  if (whitespaceRules.size() > 0) {
      Whitespace.translateRules(whitespaceRules,classGen);
  }

  if (classGen.containsMethod(STRIP_SPACE, STRIP_SPACE_PARAMS) != null) {
      il.append(toplevel.loadDOM());
      il.append(classGen.loadTranslet());
      il.append(new INVOKEINTERFACE(setFilter, 2));
  }

  il.append(RETURN);

  // Compute max locals + stack and add method to class
  toplevel.stripAttributes(true);
  toplevel.setMaxLocals();
  toplevel.setMaxStack();
  toplevel.removeNOPs();

  classGen.addMethod(toplevel.getMethod());
 
  return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V");
    }
View Full Code Here

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

      DOCUMENT_PNAME, ITERATOR_PNAME, TRANSLET_OUTPUT_PNAME, "current"
  };

  final InstructionList il = new InstructionList();

  final MethodGenerator buildKeys =
      new MethodGenerator(ACC_PUBLIC,
        org.apache.bcel.generic.Type.VOID,
        argTypes, argNames,
        "buildKeys", _className, il,
        classGen.getConstantPool());

  buildKeys.addException("org.apache.xalan.xsltc.TransletException");
 
  final Enumeration elements = elements();
  // Compile code for other top-level elements
  while (elements.hasMoreElements()) {
      // xsl:key
      final Object element = elements.nextElement();
      if (element instanceof Key) {
    final Key key = (Key)element;
    key.translate(classGen, buildKeys);
    _keys.put(key.getName(),key);
      }
  }
 
  il.append(RETURN);
 
  // Compute max locals + stack and add method to class
  buildKeys.stripAttributes(true);
  buildKeys.setMaxLocals();
  buildKeys.setMaxStack();
  buildKeys.removeNOPs();

  classGen.addMethod(buildKeys.getMethod());
 
  return("("+DOM_INTF_SIG+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+"I)V");
    }
View Full Code Here

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

  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,
            il.getEnd(), 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
  il.append(new PUSH(cpg, DTM.ROOT_NODE));
  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 -- TODO: omit if not needed               
       
        final String keySig = compileBuildKeys(classGen);
        final int    keyIdx = cpg.addMethodref(getClassName(),
                                               "buildKeys", keySig);
        il.append(classGen.loadTranslet());     // The 'this' pointer
        il.append(classGen.loadTranslet());
        il.append(new GETFIELD(domField));      // The DOM reference
        il.append(transf.loadIterator());       // Not really used, but...
        il.append(transf.loadHandler());        // The output handler
        il.append(new PUSH(cpg, DTM.ROOT_NODE)); // Start with the root node
        il.append(new INVOKEVIRTUAL(keyIdx));


    // 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, toplevel);
      // 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());
      il.append(new GETFIELD(domField))// The DOM reference
      il.append(transf.loadIterator());
      il.append(transf.loadHandler());    // The output handler
      il.append(new INVOKEVIRTUAL(topLevelIdx));
  }
 



  // start document
  il.append(transf.loadHandler());
  il.append(transf.startDocument());

  // push first arg for applyTemplates
  il.append(classGen.loadTranslet());
  // push translet for GETFIELD to get DOM arg
  il.append(classGen.loadTranslet());
  il.append(new GETFIELD(domField));
  // push remaining 2 args
  il.append(transf.loadIterator());
  il.append(transf.loadHandler());
  il.append(new INVOKEVIRTUAL(applyTemplates));
  // endDocument
  il.append(transf.loadHandler());
  il.append(transf.endDocument());

  il.append(RETURN);

  // Compute max locals + stack and add method to class
  transf.stripAttributes(true);
  transf.setMaxLocals();
  transf.setMaxStack();
  transf.removeNOPs();

  classGen.addMethod(transf.getMethod());
    }
View Full Code Here

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

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = new InstructionList();
  final XSLTC xsltc = classGen.getParser().getXSLTC();

  // private boolean Translet.stripSpace(int type) - cannot be static
  final MethodGenerator stripSpace =
      new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
      org.apache.bcel.generic.Type.BOOLEAN,
      new org.apache.bcel.generic.Type[] {
          Util.getJCRefType(DOM_INTF_SIG),
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT
      },
      new String[] { "dom","node","type" },
      "stripSpace",classGen.getClassName(),il,cpg);

  classGen.addInterface("org/apache/xalan/xsltc/StripFilter");

  final int paramDom = stripSpace.getLocalIndex("dom");
  final int paramCurrent = stripSpace.getLocalIndex("node");
  final int paramType = stripSpace.getLocalIndex("type");

  BranchHandle strip[] = new BranchHandle[rules.size()];
  BranchHandle preserve[] = new BranchHandle[rules.size()];
  int sCount = 0;
  int pCount = 0;

  // Traverse all strip/preserve rules
  for (int i = 0; i<rules.size(); i++) {
      // Get the next rule in the prioritised list
      WhitespaceRule rule = (WhitespaceRule)rules.elementAt(i);

      // Returns the namespace for a node in the DOM
      final int gns = cpg.addInterfaceMethodref(DOM_INTF,
                  "getNamespaceName",
                  "(I)Ljava/lang/String;");

      final int strcmp = cpg.addMethodref("java/lang/String",
            "compareTo",
            "(Ljava/lang/String;)I");

      // Handle elements="ns:*" type rule
      if (rule.getStrength() == RULE_NAMESPACE) {
    il.append(new ALOAD(paramDom));
    il.append(new ILOAD(paramCurrent));
    il.append(new INVOKEINTERFACE(gns,2));
    il.append(new PUSH(cpg, rule.getNamespace()));
    il.append(new INVOKEVIRTUAL(strcmp));
    il.append(ICONST_0);

    if (rule.getAction() == STRIP_SPACE) {
        strip[sCount++] = il.append(new IF_ICMPEQ(null));
    }
    else {
        preserve[pCount++] = il.append(new IF_ICMPEQ(null));
    }
      }
      // Handle elements="ns:el" type rule
      else if (rule.getStrength() == RULE_ELEMENT) {
    // Create the QName for the element
    final Parser parser = classGen.getParser();
    QName qname;
    if (rule.getNamespace() != Constants.EMPTYSTRING )
        qname = parser.getQName(rule.getNamespace(), null,
              rule.getElement());
    else
        qname = parser.getQName(rule.getElement());

    // Register the element.
    final int elementType = xsltc.registerElement(qname);
    il.append(new ILOAD(paramType));
    il.append(new PUSH(cpg, elementType));

    // Compare current node type with wanted element type
    if (rule.getAction() == STRIP_SPACE)
        strip[sCount++] = il.append(new IF_ICMPEQ(null));
    else
        preserve[pCount++] = il.append(new IF_ICMPEQ(null));
      }
  }

  if (defaultAction == STRIP_SPACE) {
      compileStripSpace(strip, sCount, il);
      compilePreserveSpace(preserve, pCount, il);
  }
  else {
      compilePreserveSpace(preserve, pCount, il);
      compileStripSpace(strip, sCount, il);
  }

  stripSpace.stripAttributes(true);
  stripSpace.setMaxLocals();
  stripSpace.setMaxStack();
  stripSpace.removeNOPs();

  classGen.addMethod(stripSpace.getMethod());
    }
View Full Code Here

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

  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = new InstructionList();
  final XSLTC xsltc = classGen.getParser().getXSLTC();

  // private boolean Translet.stripSpace(int type) - cannot be static
  final MethodGenerator stripSpace =
      new MethodGenerator(ACC_PUBLIC | ACC_FINAL ,
      org.apache.bcel.generic.Type.BOOLEAN,
      new org.apache.bcel.generic.Type[] {
          Util.getJCRefType(DOM_INTF_SIG),
          org.apache.bcel.generic.Type.INT,
          org.apache.bcel.generic.Type.INT
      },
      new String[] { "dom","node","type" },
      "stripSpace",classGen.getClassName(),il,cpg);

  classGen.addInterface("org/apache/xalan/xsltc/StripFilter");

  if (defaultAction == STRIP_SPACE)
      il.append(ICONST_1);
  else
      il.append(ICONST_0);
  il.append(IRETURN);

  stripSpace.stripAttributes(true);
  stripSpace.setMaxLocals();
  stripSpace.setMaxStack();
  stripSpace.removeNOPs();

  classGen.addMethod(stripSpace.getMethod());
    }
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.