bckfnn      2004/10/20 14:04:43

  Modified:    src/java/org/apache/fop/fo FOEventHandler.java
                        FOTreeBuilder.java FObj.java
               src/java/org/apache/fop/fo/flow Marker.java
                        RetrieveMarker.java
               src/java/org/apache/fop/layoutmgr
                        RetrieveMarkerLayoutManager.java
  Added:       src/java/org/apache/fop/fo PropertyListMaker.java
  Log:
  Fourth phase of performance improvement.
  - Add PropertyListMaker to support fo:maker and fo:retrieve-marker.
  
  PR: 31699
  
  Revision  Changes    Path
  1.4       +20 -1     xml-fop/src/java/org/apache/fop/fo/FOEventHandler.java
  
  Index: FOEventHandler.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOEventHandler.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- FOEventHandler.java       30 Sep 2004 19:55:35 -0000      1.3
  +++ FOEventHandler.java       20 Oct 2004 21:04:43 -0000      1.4
  @@ -82,6 +82,11 @@
        */
       private Set idReferences = new HashSet();
   
  +    /*
  +     * The property list maker.
  +     */
  +    protected PropertyListMaker propertyListMaker;
  +
       /**
        * Main constructor
        * @param FOUserAgent the apps.FOUserAgent instance for this process
  @@ -121,6 +126,20 @@
        */
       public FontInfo getFontInfo() {
           return this.fontInfo;
  +    }
  +
  +    /**
  +     * Return the propertyListMaker.
  +    */
  +    public PropertyListMaker getPropertyListMaker() {
  +        return propertyListMaker;
  +    }
  +     
  +    /**
  +     * Set a new propertyListMaker.
  +     */
  +    public void setPropertyListMaker(PropertyListMaker propertyListMaker) {
  +        this.propertyListMaker = propertyListMaker;
       }
   
       /**
  
  
  
  1.56      +6 -1      xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java
  
  Index: FOTreeBuilder.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FOTreeBuilder.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- FOTreeBuilder.java        19 Oct 2004 12:52:09 -0000      1.55
  +++ FOTreeBuilder.java        20 Oct 2004 21:04:43 -0000      1.56
  @@ -106,7 +106,12 @@
           //This creates either an AreaTreeHandler and ultimately a Renderer, or
           //one of the RTF-, MIF- etc. Handlers.
           foEventHandler = RendererFactory.createFOEventHandler(foUserAgent, 
renderType, stream);
  -        
  +        foEventHandler.setPropertyListMaker(new PropertyListMaker() {
  +            public PropertyList make(FObj fobj, PropertyList parentPropertyList) {
  +                return new StaticPropertyList(fobj, parentPropertyList);
  +            }
  +        });
  +
           // Add standard element mappings
           setupDefaultMappings();
   
  
  
  
  1.84      +1 -2      xml-fop/src/java/org/apache/fop/fo/FObj.java
  
  Index: FObj.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/FObj.java,v
  retrieving revision 1.83
  retrieving revision 1.84
  diff -u -r1.83 -r1.84
  --- FObj.java 20 Oct 2004 18:21:27 -0000      1.83
  +++ FObj.java 20 Oct 2004 21:04:43 -0000      1.84
  @@ -101,8 +101,7 @@
        * Create a default property list for this element. 
        */
       protected PropertyList createPropertyList(PropertyList parent, FOEventHandler 
foEventHandler) throws SAXParseException {
  -        //return foEventHandler.getPropertyListMaker().make(this, parent);
  -        return new StaticPropertyList(this, parent);
  +        return foEventHandler.getPropertyListMaker().make(this, parent);
       }
   
       /**
  
  
  
  1.1                  xml-fop/src/java/org/apache/fop/fo/PropertyListMaker.java
  
  Index: PropertyListMaker.java
  ===================================================================
  /*
   * Copyright 2004 The Apache Software Foundation.
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *      http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  
  /* $Id: PropertyListMaker.java,v 1.1 2004/10/20 21:04:43 bckfnn Exp $ */
  
  package org.apache.fop.fo;
  
  /**
   * A PropertyListMaker is a factory that creates PropertyLists. 
   */
  public interface PropertyListMaker {
      PropertyList make(FObj fobj, PropertyList parentPropertyList);
  
  }
  
  
  
  1.18      +85 -0     xml-fop/src/java/org/apache/fop/fo/flow/Marker.java
  
  Index: Marker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/Marker.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- Marker.java       19 Oct 2004 13:45:37 -0000      1.17
  +++ Marker.java       20 Oct 2004 21:04:43 -0000      1.18
  @@ -18,14 +18,21 @@
   
   package org.apache.fop.fo.flow;
   
  +import java.util.HashMap;
  +import java.util.Iterator;
  +
   // XML
   import org.xml.sax.Locator;
   import org.xml.sax.SAXParseException;
   
   // FOP
   import org.apache.fop.fo.FONode;
  +import org.apache.fop.fo.FObj;
   import org.apache.fop.fo.FObjMixed;
  +import org.apache.fop.fo.FOEventHandler;
  +import org.apache.fop.fo.properties.Property;
   import org.apache.fop.fo.PropertyList;
  +import org.apache.fop.fo.PropertyListMaker;
   
   /**
    * Marker formatting object.
  @@ -35,6 +42,10 @@
       private String markerClassName;
       // End of property values
   
  +    private MarkerPropertyList propertyList;
  +    private PropertyListMaker savePropertyListMaker;
  +    private HashMap children = new HashMap();
  +
       /**
        * Create a marker fo.
        * @param parent the parent fo node
  @@ -49,6 +60,52 @@
       public void bind(PropertyList pList) throws SAXParseException {
           markerClassName = pList.get(PR_MARKER_CLASS_NAME).getString();
       }
  +    
  +    /**
  +     * Rebind the marker and all the children using the specified 
  +     * parentPropertyList which comes from the fo:retrieve-marker element.
  +     * @param parentPropertyList The property list from fo:retrieve-marker.
  +     */
  +    public void rebind(PropertyList parentPropertyList) throws SAXParseException {
  +        // Set a new parent property list and bind all the children again.
  +        propertyList.setParentPropertyList(parentPropertyList);
  +        for (Iterator i = children.keySet().iterator(); i.hasNext(); ) {
  +            FObj child = (FObj) i.next();
  +            PropertyList childList = (PropertyList) children.get(child);
  +            child.bind(childList);
  +        }
  +    }
  +
  +    protected PropertyList createPropertyList(PropertyList parent, FOEventHandler 
foEventHandler) throws SAXParseException {
  +        propertyList = new MarkerPropertyList(this, parent);
  +        return propertyList;
  +    }
  +
  +    protected void startOfNode() {
  +        FOEventHandler foEventHandler = getFOEventHandler(); 
  +        // Push a new property list maker which will make MarkerPropertyLists.
  +        savePropertyListMaker = foEventHandler.getPropertyListMaker();
  +        foEventHandler.setPropertyListMaker(new PropertyListMaker() {
  +            public PropertyList make(FObj fobj, PropertyList parentPropertyList) {
  +                PropertyList pList = new MarkerPropertyList(fobj, 
parentPropertyList);
  +                children.put(fobj, pList);
  +                return pList;
  +            }
  +        });
  +    }
  +
  +    protected void addChildNode(FONode child) throws SAXParseException {
  +        if (!children.containsKey(child)) {
  +            children.put(child, propertyList);
  +        }
  +        super.addChildNode(child);
  +    }
  +
  +    protected void endOfNode() {
  +        // Pop the MarkerPropertyList maker.
  +        getFOEventHandler().setPropertyListMaker(savePropertyListMaker);
  +        savePropertyListMaker = null;
  +    }
   
       /**
        * @see org.apache.fop.fo.FONode#validateChildNode(Locator, String, String)
  @@ -85,4 +142,32 @@
       public int getNameId() {
           return FO_MARKER;
       }
  +
  +    /**
  +     * An implementation of PropertyList which only stores the explicit
  +     * assigned properties. It is memory efficient but slow. 
  +     */
  +    public class MarkerPropertyList extends PropertyList {
  +        HashMap explicit = new HashMap();
  +        public MarkerPropertyList(FObj fobj, PropertyList parentPropertyList) {
  +            super(fobj, parentPropertyList);
  +        }
  +        
  +        /**
  +         * Set the parent property list. Used to assign a new parent 
  +         * before re-binding all the child elements.   
  +         */
  +        public void setParentPropertyList(PropertyList parentPropertyList) {
  +            this.parentPropertyList = parentPropertyList;
  +        }
  +
  +        public void putExplicit(int propId, Property value) {
  +            explicit.put(new Integer(propId), value);
  +        }
  +
  +        public Property getExplicit(int propId) {
  +            return (Property) explicit.get(new Integer(propId));
  +        }
  +    }
  +
   }
  
  
  
  1.22      +17 -0     xml-fop/src/java/org/apache/fop/fo/flow/RetrieveMarker.java
  
  Index: RetrieveMarker.java
  ===================================================================
  RCS file: /home/cvs/xml-fop/src/java/org/apache/fop/fo/flow/RetrieveMarker.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- RetrieveMarker.java       19 Oct 2004 13:45:37 -0000      1.21
  +++ RetrieveMarker.java       20 Oct 2004 21:04:43 -0000      1.22
  @@ -28,7 +28,9 @@
   // FOP
   import org.apache.fop.fo.FONode;
   import org.apache.fop.fo.FObjMixed;
  +import org.apache.fop.fo.FOEventHandler;
   import org.apache.fop.fo.PropertyList;
  +import org.apache.fop.fo.StaticPropertyList;
   import org.apache.fop.layoutmgr.RetrieveMarkerLayoutManager;
   
   
  @@ -44,6 +46,8 @@
       private int retrieveBoundary;
       // End of property values
   
  +    private PropertyList propertyList;
  +
       /**
        * Create a retrieve marker object.
        *
  @@ -69,6 +73,19 @@
       protected void validateChildNode(Locator loc, String nsURI, String localName) 
           throws SAXParseException {
               invalidChildError(loc, nsURI, localName);
  +    }
  +
  +    protected PropertyList createPropertyList(PropertyList parent, 
  +            FOEventHandler foEventHandler) throws SAXParseException {
  +        // TODO: A special RetrieveMarkerPropertyList would be more memory
  +        // efficient. Storing a StaticPropertyList like this will keep all
  +        // the parent PropertyLists alive.
  +        propertyList = new StaticPropertyList(this, parent);
  +        return propertyList;
  +    }
  +
  +    public PropertyList getPropertyList() {
  +        return propertyList;
       }
   
       /**
  
  
  
  1.13      +9 -2      
xml-fop/src/java/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java
  
  Index: RetrieveMarkerLayoutManager.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/java/org/apache/fop/layoutmgr/RetrieveMarkerLayoutManager.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- RetrieveMarkerLayoutManager.java  20 Oct 2004 13:19:24 -0000      1.12
  +++ RetrieveMarkerLayoutManager.java  20 Oct 2004 21:04:43 -0000      1.13
  @@ -22,6 +22,8 @@
   import java.util.List;
   import java.util.LinkedList;
   
  +import org.xml.sax.SAXParseException;
  +
   import org.apache.fop.area.Area;
   import org.apache.fop.fo.flow.Marker;
   import org.apache.fop.fo.flow.RetrieveMarker;
  @@ -108,15 +110,20 @@
               List list = new ArrayList();
               Marker marker = retrieveMarker(name, position, boundary);
               if (marker != null) {
  +                try {
  +                    marker.rebind(fobj.getPropertyList());
  +                } catch (SAXParseException exc) {
  +                    log.error("fo:retrieve-marker unable to rebind property 
values", exc);
  +                }
                   marker.addLayoutManager(list);
                   if (list.size() > 0) {
                       replaceLM =  (LayoutManager)list.get(0);
                       replaceLM.setParent(this);
                       replaceLM.initialize();
                       log.debug("retrieved: " + replaceLM + ":" + list.size());
  -                } else {
  -                    log.debug("found no marker with name: " + name);
                   }
  +            } else {
  +                log.debug("found no marker with name: " + name);
               }
           }
       }
  
  
  

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

Reply via email to