kinman      2002/12/04 18:39:03

  Modified:    jasper2/src/share/org/apache/jasper/compiler Generator.java
                        Node.java TagPluginManager.java
               jasper2/src/share/org/apache/jasper/compiler/tagplugin
                        TagPluginContext.java
  Log:
  - More updates on tag plugin work.
  
  Revision  Changes    Path
  1.136     +118 -74   
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java
  
  Index: Generator.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Generator.java,v
  retrieving revision 1.135
  retrieving revision 1.136
  diff -u -r1.135 -r1.136
  --- Generator.java    3 Dec 2002 23:49:46 -0000       1.135
  +++ Generator.java    5 Dec 2002 02:39:03 -0000       1.136
  @@ -1483,21 +1483,14 @@
   
           public void visit(Node.CustomTag n) throws JasperException {
   
  -         Hashtable handlerInfosByShortName = (Hashtable)
  -             handlerInfos.get(n.getPrefix());
  -         if (handlerInfosByShortName == null) {
  -             handlerInfosByShortName = new Hashtable();
  -             handlerInfos.put(n.getPrefix(), handlerInfosByShortName);
  -         }
  -         TagHandlerInfo handlerInfo = (TagHandlerInfo)
  -             handlerInfosByShortName.get(n.getShortName());
  -         if (handlerInfo == null) {
  -             handlerInfo = new TagHandlerInfo(n,
  -                                              n.getTagHandlerClass(),
  -                                              err);
  -             handlerInfosByShortName.put(n.getShortName(), handlerInfo);
  +         // Use plugin to generate more efficient code if there is one.
  +         if (n.useTagPlugin()) {
  +             generateTagPlugin(n);
  +             return;
            }
   
  +         TagHandlerInfo handlerInfo = getTagHandlerInfo(n);
  +
            // Create variable names
            String baseVar = createTagVarName(n.getName(), n.getPrefix(),
                                              n.getShortName());
  @@ -1879,6 +1872,48 @@
            }
        }
   
  +     public void visit(Node.GenAttribute n) throws JasperException {
  +         Node.CustomTag tag = n.getTag();
  +            Node.JspAttribute[] attrs = tag.getJspAttributes();
  +            for (int i=0; i<attrs.length; i++) {
  +             if (attrs[i].getName() == n.getName()) {
  +                 out.print(evaluateAttribute(getTagHandlerInfo(tag),
  +                             attrs[i], tag, null));
  +                 break;
  +             }
  +         }
  +     }
  +
  +     private TagHandlerInfo getTagHandlerInfo(Node.CustomTag n)
  +                     throws JasperException {
  +            Hashtable handlerInfosByShortName = (Hashtable)
  +                handlerInfos.get(n.getPrefix());
  +            if (handlerInfosByShortName == null) {
  +                handlerInfosByShortName = new Hashtable();
  +                handlerInfos.put(n.getPrefix(), handlerInfosByShortName);
  +            }
  +            TagHandlerInfo handlerInfo = (TagHandlerInfo)
  +                handlerInfosByShortName.get(n.getShortName());
  +            if (handlerInfo == null) {
  +                handlerInfo = new TagHandlerInfo(n,
  +                                                 n.getTagHandlerClass(),
  +                                                 err);
  +                handlerInfosByShortName.put(n.getShortName(), handlerInfo);
  +            }
  +         return handlerInfo;
  +     }
  +
  +     private void generateTagPlugin(Node.CustomTag n)
  +                             throws JasperException {
  +         if (n.getAtSTag() != null) {
  +             n.getAtSTag().visit(this);
  +         }
  +         visitBody(n);
  +         if (n.getAtETag() != null) {
  +             n.getAtETag().visit(this);
  +         }
  +     }
  +
        private void generateCustomStart(Node.CustomTag n,
                                         TagHandlerInfo handlerInfo,
                                         String tagHandlerVar,
  @@ -2336,6 +2371,70 @@
            }
        }
   
  +     private String evaluateAttribute(TagHandlerInfo handlerInfo,
  +                                      Node.JspAttribute attr,
  +                                      Node.CustomTag n,
  +                                      String tagHandlerVar)
  +                     throws JasperException {
  +
  +         String attrValue = attr.getValue();
  +         if (attrValue == null) {
  +                if(attr.isNamedAttribute()) {
  +                    if(n.checkIfAttributeIsJspFragment(attr.getName())) {
  +                        // XXX - no need to generate temporary variable here
  +                        attrValue = generateNamedAttributeJspFragment( 
  +                                attr.getNamedAttributeNode(),
  +                                tagHandlerVar );
  +                    }
  +                    else {
  +                        attrValue = generateNamedAttributeValue( 
  +                            attr.getNamedAttributeNode());
  +                    }
  +                } 
  +                else {
  +                    return null;
  +                }
  +            }
  +
  +         String attrName = attr.getName();
  +
  +         Method m = null;
  +         Class[] c = null;
  +         if (attr.isDynamic()) {
  +             c = OBJECT_CLASS;
  +            } else {
  +             m = handlerInfo.getSetterMethod(attrName);
  +             if (m == null) {
  +                 err.jspError(n, "jsp.error.unable.to_find_method",
  +                                  attrName);
  +             }
  +             c = m.getParameterTypes();
  +             // XXX assert(c.length > 0)
  +         }
  +
  +         if (attr.isExpression()) {
  +             // Do nothing
  +         } else if (attr.isNamedAttribute()) {
  +             if (!n.checkIfAttributeIsJspFragment(attr.getName())
  +                         && !attr.isDynamic()) {
  +                 attrValue = convertString(
  +                                c[0], attrValue, attrName,
  +                             handlerInfo.getPropertyEditorClass(attrName),
  +                             false);
  +             }
  +         } else if (attr.isELInterpreterInput()) {
  +                // run attrValue through the expression interpreter
  +                attrValue = JspUtil.interpreterCall(this.isTagFile,
  +                         attrValue, c[0], n.getPrefix(), "_jspx_fnmap", false );
  +            } else {
  +             attrValue = convertString(
  +                                c[0], attrValue, attrName,
  +                             handlerInfo.getPropertyEditorClass(attrName),
  +                             true);
  +         }
  +         return attrValue;
  +     }
  +
        private void generateSetters(Node.CustomTag n,
                                     String tagHandlerVar,
                                     TagHandlerInfo handlerInfo,
  @@ -2390,63 +2489,8 @@
   
            Node.JspAttribute[] attrs = n.getJspAttributes();
            for (int i=0; i<attrs.length; i++) {
  -             String attrValue = attrs[i].getValue();
  -             if (attrValue == null) {
  -                    if( attrs[i].isNamedAttribute() ) {
  -                        if( n.checkIfAttributeIsJspFragment( 
  -                            attrs[i].getName() ) ) 
  -                        {
  -                            // XXX - no need to generate temporary variable 
  -                            // here
  -                            attrValue = generateNamedAttributeJspFragment( 
  -                                attrs[i].getNamedAttributeNode(),
  -                                tagHandlerVar );
  -                        }
  -                        else {
  -                            attrValue = generateNamedAttributeValue( 
  -                                attrs[i].getNamedAttributeNode() );
  -                        }
  -                    } 
  -                    else {
  -                        continue;
  -                    }
  -             }
  -             String attrName = attrs[i].getName();
  -
  -             Method m = null;
  -             Class[] c = null;
  -             if (attrs[i].isDynamic()) {
  -                 c = OBJECT_CLASS;
  -             } else {
  -                 m = handlerInfo.getSetterMethod(attrName);
  -                 if (m == null) {
  -                     err.jspError(n, "jsp.error.unable.to_find_method",
  -                                  attrName);
  -                 }
  -                 c = m.getParameterTypes();
  -                 // XXX assert(c.length > 0)
  -             }
  -
  -             if (attrs[i].isExpression()) {
  -                 // Do nothing
  -             } else if (attrs[i].isNamedAttribute()) {
  -                 if (!n.checkIfAttributeIsJspFragment(attrs[i].getName())
  -                         && !attrs[i].isDynamic()) {
  -                     attrValue = convertString(
  -                                c[0], attrValue, attrName,
  -                             handlerInfo.getPropertyEditorClass(attrName),
  -                             false);
  -                 }
  -             } else if (attrs[i].isELInterpreterInput()) {
  -                    // run attrValue through the expression interpreter
  -                    attrValue = JspUtil.interpreterCall(this.isTagFile,
  -                        attrValue, c[0], n.getPrefix(), "_jspx_fnmap", false );
  -                } else {
  -                 attrValue = convertString(
  -                                c[0], attrValue, attrName,
  -                             handlerInfo.getPropertyEditorClass(attrName),
  -                             true);
  -             }
  +             String attrValue = evaluateAttribute(handlerInfo, attrs[i],
  +                                             n, tagHandlerVar);
                
                if (attrs[i].isDynamic()) {
                    out.printin(tagHandlerVar);
  @@ -2467,7 +2511,7 @@
                } else {
                    out.printin(tagHandlerVar);
                    out.print(".");
  -                 out.print(m.getName());
  +                 
out.print(handlerInfo.getSetterMethod(attrs[i].getName()).getName());
                    out.print("(");
                    out.print(attrValue);
                    out.println(");");
  
  
  
  1.44      +15 -8     
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java
  
  Index: Node.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Node.java,v
  retrieving revision 1.43
  retrieving revision 1.44
  diff -u -r1.43 -r1.44
  --- Node.java 4 Dec 2002 00:48:42 -0000       1.43
  +++ Node.java 5 Dec 2002 02:39:03 -0000       1.44
  @@ -1226,7 +1226,7 @@
            useTagPlugin = use;
        }
   
  -     public boolean getUseTagPlugin() {
  +     public boolean useTagPlugin() {
            return useTagPlugin;
        }
   
  @@ -1287,18 +1287,25 @@
        * to indicate generated codes for the specified attribute.
        */
       public static class GenAttribute extends Node {
  -     String attribute;
  +     String name;    // name of the attribute
  +     CustomTag tag;  // The tag this attribute belongs
   
  -     public GenAttribute(Mark start, String attribute) {
  +     public GenAttribute(Mark start, String name, CustomTag tag) {
            super(start, null);
  +         this.name = name;
  +         this.tag = tag;
        }
   
        public void accept(Visitor v) throws JasperException {
            v.visit(this);
        }
   
  -     public String getAttribute() {
  -         return attribute;
  +     public String getName() {
  +         return name;
  +     }
  +
  +     public CustomTag getTag() {
  +         return tag;
        }
       }
   
  
  
  
  1.4       +4 -8      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java
  
  Index: TagPluginManager.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/TagPluginManager.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TagPluginManager.java     4 Dec 2002 00:48:42 -0000       1.3
  +++ TagPluginManager.java     5 Dec 2002 02:39:03 -0000       1.4
  @@ -184,10 +184,6 @@
            n.setUseTagPlugin(true);
        }
   
  -     public String getTagName() {
  -         return node.getName();
  -     }
  -
        public boolean isScriptless() {
            return node.getChildInfo().isScriptless();
        }
  @@ -201,7 +197,7 @@
        }
   
        public void generateAttribute(String attribute) {
  -         curNodes.add(new Node.GenAttribute(node.getStart(), null));
  +         curNodes.add(new Node.GenAttribute(node.getStart(), attribute, node));
        }
   
        public void dontUseTagPlugin() {
  
  
  
  1.4       +3 -8      
jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java
  
  Index: TagPluginContext.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/tagplugin/TagPluginContext.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- TagPluginContext.java     4 Dec 2002 01:41:19 -0000       1.3
  +++ TagPluginContext.java     5 Dec 2002 02:39:03 -0000       1.4
  @@ -71,11 +71,6 @@
   
   public interface TagPluginContext {
       /**
  -     * @return The name for the current tag
  -     */
  -    String getTagName();
  -
  -    /**
         * @return true if the body of the tag is scriptless.
         */
       boolean isScriptless();
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to