Package org.apache.bcel.generic

Examples of org.apache.bcel.generic.ConstantPoolGen


  return typeCheckContents(stable);
    }

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

  if (_disabled) return;
  // bug fix #4433133, add a call to named template from applyTemplates
  String className = classGen.getClassName();

  if (_compiled && isNamed()){
      String methodName = Util.escape(_name.toString());
      il.append(classGen.loadTranslet());
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadIterator());
      il.append(methodGen.loadHandler());
      il.append(methodGen.loadCurrentNode());
      il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
               methodName,
               "("
               + DOM_INTF_SIG
               + NODE_ITERATOR_SIG
               + TRANSLET_OUTPUT_SIG
View Full Code Here


  return Type.Void;
    }

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

        // If there are Params in the stylesheet or WithParams in this call?
  if (stylesheet.hasLocalParams() || hasContents()) {
      _calleeTemplate = getCalleeTemplate();
     
      // Build the parameter list if the called template is simple named
      if (_calleeTemplate != null) {
        buildParameterList();
      }
      // This is only needed when the called template is not
      // a simple named template.
      else {
          // Push parameter frame
          final int push = cpg.addMethodref(TRANSLET_CLASS,
                    PUSH_PARAM_FRAME,
                    PUSH_PARAM_FRAME_SIG);
          il.append(classGen.loadTranslet());
          il.append(new INVOKEVIRTUAL(push));
          translateContents(classGen, methodGen);
      }
  }

        // Generate a valid Java method name
  final String className = stylesheet.getClassName();
        String methodName = Util.escape(_name.toString());

        // Load standard arguments
  il.append(classGen.loadTranslet());
  il.append(methodGen.loadDOM());
  il.append(methodGen.loadIterator());
  il.append(methodGen.loadHandler());
  il.append(methodGen.loadCurrentNode());
       
        // Initialize prefix of method signature
  StringBuffer methodSig = new StringBuffer("(" + DOM_INTF_SIG
            + NODE_ITERATOR_SIG + TRANSLET_OUTPUT_SIG + NODE_SIG);
 
        // If calling a simply named template, push actual arguments
  if (_calleeTemplate != null) {
      Vector calleeParams = _calleeTemplate.getParameters();
      int numParams = _parameters.length;
     
      for (int i = 0; i < numParams; i++) {
          SyntaxTreeNode node = (SyntaxTreeNode)_parameters[i];
                methodSig.append(OBJECT_SIG);   // append Object to signature
               
                // Push 'null' if Param to indicate no actual parameter specified
                if (node instanceof Param) {
                    il.append(ACONST_NULL);
                }
                else // translate WithParam
                    node.translate(classGen, methodGen);
                }
            }
        }

        // Complete signature and generate invokevirtual call
  methodSig.append(")V");
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(className,
                 methodName,
                 methodSig.toString())));
 
  // Do not need to call Translet.popParamFrame() if we are
  // calling a simple named template.
  if (_calleeTemplate == null && (stylesheet.hasLocalParams() || hasContents())) {
      // Pop parameter frame
      final int pop = cpg.addMethodref(TRANSLET_CLASS,
               POP_PARAM_FRAME,
               POP_PARAM_FRAME_SIG);
      il.append(classGen.loadTranslet());
      il.append(new INVOKEVIRTUAL(pop));
  }
View Full Code Here

     * This method is called when the name of the element is known at compile time.
     * In this case, there is no need to inspect the element name at runtime to
     * determine if a prefix exists, needs to be generated, etc.
     */
    public void translateLiteral(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  if (!_ignore) {
      il.append(methodGen.loadHandler());
      _name.translate(classGen, methodGen);
View Full Code Here

     * when the prefix is not known at compile time (vi) calls namespace()
     * on the handler (vii) evaluates the contents (viii) calls endElement().
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  LocalVariableGen local = null;
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Optimize translation if element name is a literal
  if (_isLiteralName) {
      translateLiteral(classGen, methodGen);
      return;
  }

  if (!_ignore) {
      
            // if the qname is an AVT, then the qname has to be checked at runtime if it is a valid qname
            LocalVariableGen nameValue =
                    methodGen.addLocalVariable2("nameValue",
                                                Util.getJCRefType(STRING_SIG),
                                                null);
                   
            // store the name into a variable first so _name.translate only needs to be called once 
            _name.translate(classGen, methodGen);
            nameValue.setStart(il.append(new ASTORE(nameValue.getIndex())));
            il.append(new ALOAD(nameValue.getIndex()));
           
            // call checkQName if the name is an AVT
            final int check = cpg.addMethodref(BASIS_LIBRARY_CLASS, "checkQName",
                            "("
                            +STRING_SIG
                            +")V");                
            il.append(new INVOKESTATIC(check));
           
            // Push handler for call to endElement()
            il.append(methodGen.loadHandler());        
           
            // load name value again
            nameValue.setEnd(il.append(new ALOAD(nameValue.getIndex())));
                   
      if (_namespace != null) {
    _namespace.translate(classGen, methodGen);
      }
      else {
                // If name is an AVT and namespace is not specified, need to
                // look up any prefix in the stylesheet by calling
                //   BasisLibrary.lookupStylesheetQNameNamespace(
                //                name, stylesheetNode, ancestorsArray,
                //                prefixURIsIndexArray, prefixURIPairsArray,
                //                !ignoreDefaultNamespace)
                String transletClassName = getXSLTC().getClassName();
                il.append(DUP);
                il.append(new PUSH(cpg, getNodeIDForStylesheetNSLookup()));
                il.append(new GETSTATIC(cpg.addFieldref(
                                             transletClassName,
                                             STATIC_NS_ANCESTORS_ARRAY_FIELD,
                                             NS_ANCESTORS_INDEX_SIG)));
                il.append(new GETSTATIC(cpg.addFieldref(
                                             transletClassName,
                                             STATIC_PREFIX_URIS_IDX_ARRAY_FIELD,
                                             PREFIX_URIS_IDX_SIG)));
                il.append(new GETSTATIC(cpg.addFieldref(
                                             transletClassName,
                                             STATIC_PREFIX_URIS_ARRAY_FIELD,
                                             PREFIX_URIS_ARRAY_SIG)));
                // Default namespace is significant
                il.append(ICONST_0);
                il.append(
                    new INVOKESTATIC(
                        cpg.addMethodref(BASIS_LIBRARY_CLASS,
                                           LOOKUP_STYLESHEET_QNAME_NS_REF,
                                           LOOKUP_STYLESHEET_QNAME_NS_SIG)));
      }

            // Push additional arguments
      il.append(methodGen.loadHandler());
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadCurrentNode());
       
            // Invoke BasisLibrary.startXslElemCheckQName()
            il.append(new INVOKESTATIC(
            cpg.addMethodref(BASIS_LIBRARY_CLASS, "startXslElement",
                    "(" + STRING_SIG
                    + STRING_SIG
                    + TRANSLET_OUTPUT_SIG
                    + DOM_INTF_SIG + "I)" + STRING_SIG)));               

View Full Code Here

  }
  return Type.NodeSet;
    }

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

  // context node is on the stack
  int gname = cpg.addInterfaceMethodref(DOM_INTF,
                "getNodeName",
                "(I)Ljava/lang/String;");
  int cmp = cpg.addMethodref(STRING_CLASS,
           "equals", "(Ljava/lang/Object;)Z");

  // Push current node on the stack
  il.append(methodGen.loadCurrentNode());
  il.append(SWAP);

  // Overwrite current node with matching node
  il.append(methodGen.storeCurrentNode());

  // If pattern not reduced then check kernel
  if (!_typeChecked) {
      il.append(methodGen.loadCurrentNode());
      final int getType = cpg.addInterfaceMethodref(DOM_INTF,
                "getType", "(I)I");
      il.append(methodGen.loadDOM());
      il.append(methodGen.loadCurrentNode());
      il.append(new INVOKEINTERFACE(getType, 2));
      il.append(new PUSH(cpg, DOM.PROCESSING_INSTRUCTION));
View Full Code Here

  else if (hasContents()) {
      compileResultTree(classGen, methodGen);
  }
  // If neither are present then store empty string in parameter slot
  else {
      final ConstantPoolGen cpg = classGen.getConstantPool();
      final InstructionList il = methodGen.getInstructionList();
      il.append(new PUSH(cpg, Constants.EMPTYSTRING));
  }
    }
View Full Code Here

     * This code generates a sequence of bytecodes that call the
     * addParameter() method in AbstractTranslet. The method call will add
     * (or update) the parameter frame with the new parameter value.
     */
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  // Make name acceptable for use as field name in class
  String name = Util.escape(_name.getLocalPart());

  // Load reference to the translet (method is in AbstractTranslet)
  il.append(classGen.loadTranslet());

  // Load the name of the parameter
  il.append(new PUSH(cpg, name)); // TODO: namespace ?
  // Generete the value of the parameter (use value in 'select' by def.)
  translateValue(classGen, methodGen);
  // Mark this parameter value is not being the default value
  il.append(new PUSH(cpg, false));
  // Pass the parameter to the template
  il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
                 ADD_PARAMETER,
                 ADD_PARAMETER_SIG)));
  il.append(POP); // cleanup stack
    }
View Full Code Here

     * Translate the code required for getting the node for which the
     * QName, local-name or namespace URI should be extracted.
     */
    public void translate(ClassGenerator classGen,
        MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();

  il.append(methodGen.loadDOM());
 
  // Function was called with no parameters
  if (argumentCount() == 0) {
      il.append(methodGen.loadContextNode());
  }
  // Function was called with node parameter
  else if (_paramType == Type.Node) {
      _param.translate(classGen, methodGen);
  }
  else if (_paramType == Type.Reference) {
      _param.translate(classGen, methodGen);
      il.append(new INVOKESTATIC(cpg.addMethodref
               (BASIS_LIBRARY_CLASS,
          "referenceToNodeSet",
          "(Ljava/lang/Object;)" +
          "Lorg/apache/xalan/xsltc/" +
          "NodeIterator;")));
View Full Code Here

  }
  return Type.Void;
    }
 
    public void translate(ClassGenerator classGen, MethodGenerator methodGen) {
  final ConstantPoolGen cpg = classGen.getConstantPool();
  final InstructionList il = methodGen.getInstructionList();
  final Type tselect = _select.getType();

  final String CPY1_SIG = "("+NODE_ITERATOR_SIG+TRANSLET_OUTPUT_SIG+")V";
  final int cpy1 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY1_SIG);

  final String CPY2_SIG = "("+NODE_SIG+TRANSLET_OUTPUT_SIG+")V";
  final int cpy2 = cpg.addInterfaceMethodref(DOM_INTF, "copy", CPY2_SIG);

  if (tselect instanceof NodeSetType) {
      il.append(methodGen.loadDOM());

      // push NodeIterator
      _select.translate(classGen, methodGen)
      _select.startResetIterator(classGen, methodGen);

      // call copy from the DOM 'library'
      il.append(methodGen.loadHandler());
      il.append(new INVOKEINTERFACE(cpy1, 3));
  }
  else if (tselect instanceof NodeType) {
      il.append(methodGen.loadDOM());
      _select.translate(classGen, methodGen)
      il.append(methodGen.loadHandler());
      il.append(new INVOKEINTERFACE(cpy2, 3));
  }
  else if (tselect instanceof ResultTreeType) {
      _select.translate(classGen, methodGen)
      // We want the whole tree, so we start with the root node
      il.append(ICONST_1);
      il.append(methodGen.loadHandler());
      il.append(new INVOKEINTERFACE(cpy2, 3));
  }
  else if (tselect instanceof ReferenceType) {
      _select.translate(classGen, methodGen);
      il.append(methodGen.loadHandler());
      il.append(methodGen.loadCurrentNode());
      il.append(methodGen.loadDOM());
      final int copy = cpg.addMethodref(BASIS_LIBRARY_CLASS, "copy",
                "("
                + OBJECT_SIG 
                + TRANSLET_OUTPUT_SIG
                + NODE_SIG
                + DOM_INTF_SIG
                + ")V");
      il.append(new INVOKESTATIC(copy));
  }
  else {
      il.append(classGen.loadTranslet());
      _select.translate(classGen, methodGen);
      il.append(methodGen.loadHandler());
      il.append(new INVOKEVIRTUAL(cpg.addMethodref(TRANSLET_CLASS,
               CHARACTERSW,
               CHARACTERSW_SIG)));
  }

    }
View Full Code Here

     * Stylesheet.compileConstructor() and not as the syntax tree is traversed.
     */
    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");

  // Call getKeyIndex in AbstractTranslet with the name of the key
  // to get the index for this key (which is also a node iterator).
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.