pbwest      2002/10/30 05:09:11

  Modified:    src/org/apache/fop/fo/pagination Tag: FOP_0-20-0_Alt-Design
                        FoPageSequenceMaster.java
  Log:
  Added sparsePropsSet support. Untabified.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.12  +228 -107  
xml-fop/src/org/apache/fop/fo/pagination/Attic/FoPageSequenceMaster.java
  
  Index: FoPageSequenceMaster.java
  ===================================================================
  RCS file: 
/home/cvs/xml-fop/src/org/apache/fop/fo/pagination/Attic/FoPageSequenceMaster.java,v
  retrieving revision 1.1.2.11
  retrieving revision 1.1.2.12
  diff -u -r1.1.2.11 -r1.1.2.12
  --- FoPageSequenceMaster.java 28 Oct 2002 00:08:11 -0000      1.1.2.11
  +++ FoPageSequenceMaster.java 30 Oct 2002 13:09:11 -0000      1.1.2.12
  @@ -9,8 +9,8 @@
   
   package org.apache.fop.fo.pagination;
   
  -import java.util.ArrayList;
  -import java.util.LinkedList;
  +import java.util.HashMap;
  +import java.util.BitSet;
   import java.util.NoSuchElementException;
   
   // FOP
  @@ -30,6 +30,7 @@
   import org.apache.fop.datastructs.Tree;
   import org.apache.fop.datatypes.PropertyValue;
   import org.apache.fop.datatypes.NCName;
  +import org.apache.fop.datatypes.Ints;
   
   /**
    * Implements the fo:page-sequence-master flow object.  These Fos are
  @@ -42,6 +43,138 @@
       private static final String tag = "$Name$";
       private static final String revision = "$Revision$";
   
  +    /** Map of <tt>Integer</tt> indices of <i>sparsePropsSet</i> array.
  +        It is indexed by the FO index of the FO associated with a given
  +        position in the <i>sparsePropsSet</i> array.  See
  +        {@link org.apache.fop.fo.FONode#sparsePropsSet FONode.sparsePropsSet}.
  +     */
  +    private static final HashMap sparsePropsMap;
  +
  +    /** An <tt>int</tt> array of of the applicable property indices, in
  +        property index order. */
  +    private static final int[] sparseIndices;
  +
  +    /** The number of applicable properties.  This is the size of the
  +        <i>sparsePropsSet</i> array. */
  +    private static final int numProps;
  +
  +    static {
  +        // applicableProps is a HashMap containing the indicies of the
  +        // sparsePropsSet array, indexed by the FO index of the FO slot
  +        // in sparsePropsSet.
  +        sparsePropsMap = new HashMap(1);
  +        numProps = 1;
  +        sparseIndices = new int[] { PropNames.MASTER_NAME };
  +        sparsePropsMap.put
  +            (Ints.consts.get(PropNames.MASTER_NAME), Ints.consts.get(0));
  +    }
  +
  +    /** Constant values for FoSinglePageMasterReference.
  +        See {@link #sparsePropsMap sparsePropsMap}. */
  +    private static final HashMap s_p_m_r_PropsMap;
  +
  +    /** See {@link #sparseIndices sparseIndices}. */
  +    private static final int[] s_p_m_r_Indices;
  +
  +    /** See {@link #numProps numProps}. */
  +    private static final int s_p_m_r_numProps;
  +
  +    static {
  +        // applicableProps is a HashMap containing the indicies of the
  +        // sparsePropsSet array, indexed by the FO index of the FO slot
  +        // in sparsePropsSet.
  +        s_p_m_r_PropsMap = new HashMap(1);
  +        s_p_m_r_numProps = 1;
  +        s_p_m_r_Indices = new int[] { PropNames.MASTER_REFERENCE };
  +        s_p_m_r_PropsMap.put
  +            (Ints.consts.get(PropNames.MASTER_REFERENCE),
  +                                                Ints.consts.get(0));
  +    }
  +
  +    /** See {@link #sparsePropsMap sparsePropsMap}. */
  +    private static final HashMap r_p_m_r_PropsMap;
  +
  +    /** See {@link #sparseIndices sparseIndices}. */
  +    private static final int[] r_p_m_r_Indices;
  +
  +    /** See {@link #numProps numProps}. */
  +    private static final int r_p_m_r_numProps;
  +
  +    static {
  +        // Collect the sets of properties that apply
  +        BitSet propsets = new BitSet();
  +        propsets.set(PropNames.MASTER_REFERENCE);
  +        propsets.set(PropNames.MAXIMUM_REPEATS);
  +
  +        // Map these properties into sparsePropsSet
  +        // sparsePropsSet is a HashMap containing the indicies of the
  +        // sparsePropsSet array, indexed by the FO index of the FO slot
  +        // in sparsePropsSet.
  +        r_p_m_r_PropsMap = new HashMap();
  +        r_p_m_r_numProps = propsets.cardinality();
  +        r_p_m_r_Indices = new int[r_p_m_r_numProps];
  +        int propx = 0;
  +        for (int next = propsets.nextSetBit(0);
  +                next >= 0;
  +                next = propsets.nextSetBit(next + 1)) {
  +            r_p_m_r_Indices[propx] = next;
  +            r_p_m_r_PropsMap.put
  +                        (Ints.consts.get(next), Ints.consts.get(propx++));
  +        }
  +    }
  +
  +    /** See {@link #sparsePropsMap sparsePropsMap}.  */
  +    private static final HashMap r_p_m_a_PropsMap;
  +
  +    /** See {@link #sparseIndices sparseIndices}.  */
  +    private static final int[] r_p_m_a_Indices;
  +
  +    /** See {@link #numProps numProps}.  */
  +    private static final int r_p_m_a_numProps;
  +
  +    static {
  +        r_p_m_a_PropsMap = new HashMap(1);
  +        r_p_m_a_numProps = 1;
  +        r_p_m_a_Indices = new int[] { PropNames.MAXIMUM_REPEATS };
  +        r_p_m_a_PropsMap.put
  +            (Ints.consts.get(PropNames.MAXIMUM_REPEATS),
  +                                                Ints.consts.get(0));
  +    }
  +
  +    /** See {@link #sparsePropsMap sparsePropsMap}. */
  +    private static final HashMap c_p_m_r_PropsMap;
  +
  +    /** See {@link #sparseIndices sparseIndices}. */
  +    private static final int[] c_p_m_r_Indices;
  +
  +    /** See {@link #numProps numProps}. */
  +    private static final int c_p_m_r_numProps;
  +
  +    static {
  +        // Collect the sets of properties that apply
  +        BitSet propsets = new BitSet();
  +        propsets.set(PropNames.MASTER_REFERENCE);
  +        propsets.set(PropNames.PAGE_POSITION);
  +        propsets.set(PropNames.ODD_OR_EVEN);
  +        propsets.set(PropNames.BLANK_OR_NOT_BLANK);
  +
  +        // Map these properties into sparsePropsSet
  +        // sparsePropsSet is a HashMap containing the indicies of the
  +        // sparsePropsSet array, indexed by the FO index of the FO slot
  +        // in sparsePropsSet.
  +        c_p_m_r_PropsMap = new HashMap();
  +        c_p_m_r_numProps = propsets.cardinality();
  +        c_p_m_r_Indices = new int[c_p_m_r_numProps];
  +        int propx = 0;
  +        for (int next = propsets.nextSetBit(0);
  +                next >= 0;
  +                next = propsets.nextSetBit(next + 1)) {
  +            c_p_m_r_Indices[propx] = next;
  +            c_p_m_r_PropsMap.put
  +                    (Ints.consts.get(next), Ints.consts.get(propx++));
  +        }
  +    }
  +
       /**
        * An array with <tt>int</tt>s identifying
        * <tt>single-page-master-reference</tt>,
  @@ -54,15 +187,12 @@
           FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES
       };
   
  -    private String masterName;
  -
  -    //private ArrayList subSequenceList = new ArrayList(1);
  -
       public FoPageSequenceMaster(FOTree foTree, FONode parent, FoXMLEvent event)
           throws Tree.TreeException, FOPException, PropertyException
       {
           super(foTree, FObjectNames.PAGE_SEQUENCE_MASTER, parent, event,
  -                                              FOPropertySets.SEQ_MASTER_SET);
  +              FOPropertySets.SEQ_MASTER_SET, sparsePropsMap, sparseIndices,
  +              numProps);
           // Process sequence members here
           try {
               do {
  @@ -72,49 +202,35 @@
                   int foType = ev.getFoType();
                   if (foType == FObjectNames.SINGLE_PAGE_MASTER_REFERENCE) {
                       //System.out.println("Found single-page-master-reference");
  -                 //subSequenceList.add(new FoSinglePageMasterReference
  -                                                     //(foTree, this, ev));
  -                 new FoSinglePageMasterReference(foTree, this, ev);
  +                    new FoSinglePageMasterReference(foTree, this, ev);
                   } else if (foType ==
                               FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE) {
                       //System.out.println
                       //        ("Found repeatable-page-master-reference");
  -                 //subSequenceList.add(new FoRepeatablePageMasterReference
  -                                                     //(foTree, this, ev));
  -                 new FoRepeatablePageMasterReference(foTree, this, ev);
  +                    new FoRepeatablePageMasterReference(foTree, this, ev);
                   } else if (foType ==
                           FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES) {
                       //System.out.println
                       //        ("Found repeatable-page-master-alternatives");
  -                 //subSequenceList.add(new FoRepeatablePageMasterAlternatives
  -                                                     //(foTree, this, ev));
  -                 new FoRepeatablePageMasterAlternatives(foTree, this, ev);
  +                    new FoRepeatablePageMasterAlternatives(foTree, this, ev);
                   } else
                       throw new FOPException
                               ("Aargh! expectStartElement(events, list)");
  +                xmlevents.getEndElement(ev);
               } while (true);
           } catch (NoSuchElementException e) {
               throw new FOPException("Unexpected EOF in page-sequence-master.");
           }
           if (this.numChildren() == 0)
               throw new FOPException("No children of page-sequence-master.");
  -        XMLEvent ev = xmlevents.getEndElement(event);
  +        makeSparsePropsSet();
       }
   
       /**
        * @return a <tt>String</tt> with the "master-name" attribute value.
        */
       public String getMasterName() throws PropertyException {
  -     if (masterName == null) {
  -         PropertyValue name = propertySet[PropNames.MASTER_NAME];
  -         if (name == null)
  -             throw new PropertyException("master-name property not set");
  -         if (name.getType() != PropertyValue.NCNAME)
  -             throw new PropertyException
  -                                 ("master-name property not an NCName.");
  -         masterName = ((NCName)name).getNCName();
  -     }
  -     return masterName;
  +        return ((NCName)getPropertyValue(PropNames.MASTER_NAME)).getNCName();
       }
   
       /**
  @@ -123,18 +239,19 @@
        */
       public class FoSinglePageMasterReference extends FONode {
   
  -     public FoSinglePageMasterReference
  -                         (FOTree foTree, FONode parent, FoXMLEvent event)
  -         throws Tree.TreeException, FOPException, PropertyException
  -     {
  -         super(foTree, FObjectNames.SINGLE_PAGE_MASTER_REFERENCE, parent,
  -                                     event, FOPropertySets.SEQ_MASTER_SET);
  -         this.xmlevents.getEndElement(event);
  -     }
  -
  -     public PropertyValue getMasterReference() throws PropertyException {
  -         return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  -     }
  +        public FoSinglePageMasterReference
  +                            (FOTree foTree, FONode parent, FoXMLEvent event)
  +            throws Tree.TreeException, FOPException, PropertyException
  +        {
  +            super(foTree, FObjectNames.SINGLE_PAGE_MASTER_REFERENCE, parent,
  +                    event, FOPropertySets.SEQ_MASTER_SET, s_p_m_r_PropsMap,
  +                    s_p_m_r_Indices, s_p_m_r_numProps);
  +            this.makeSparsePropsSet();
  +        }
  +
  +        public PropertyValue getMasterReference() throws PropertyException {
  +            return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  +        }
   
       }// FoSinglePageMasterReference
   
  @@ -144,22 +261,23 @@
        */
       public class FoRepeatablePageMasterReference extends FONode {
   
  -     public FoRepeatablePageMasterReference
  -                         (FOTree foTree, FONode parent, FoXMLEvent event)
  -         throws Tree.TreeException, FOPException, PropertyException
  -     {
  -         super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE,
  -                             parent, event, FOPropertySets.SEQ_MASTER_SET);
  -         this.xmlevents.getEndElement(event);
  -     }
  -
  -     public PropertyValue getMasterReference() throws PropertyException {
  -         return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  -     }
  -
  -     public PropertyValue getMaximumRepeats() throws PropertyException {
  -         return this.getPropertyValue(PropNames.MAXIMUM_REPEATS);
  -     }
  +        public FoRepeatablePageMasterReference
  +                            (FOTree foTree, FONode parent, FoXMLEvent event)
  +            throws Tree.TreeException, FOPException, PropertyException
  +        {
  +            super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_REFERENCE,
  +                    parent, event, FOPropertySets.SEQ_MASTER_SET,
  +                    r_p_m_r_PropsMap, r_p_m_r_Indices, r_p_m_r_numProps);
  +            this.makeSparsePropsSet();
  +        }
  +
  +        public PropertyValue getMasterReference() throws PropertyException {
  +            return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  +        }
  +
  +        public PropertyValue getMaximumRepeats() throws PropertyException {
  +            return this.getPropertyValue(PropNames.MAXIMUM_REPEATS);
  +        }
   
       }// FoRepeatablePageMasterReference
   
  @@ -169,17 +287,18 @@
        */
       public class FoRepeatablePageMasterAlternatives extends FONode {
   
  -     public FoRepeatablePageMasterAlternatives
  -                         (FOTree foTree, FONode parent, FoXMLEvent event)
  -         throws Tree.TreeException, FOPException, PropertyException
  -     {
  -         super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES,
  -                             parent, event, FOPropertySets.SEQ_MASTER_SET);
  -
  -         // Process conditional-page-master-references here
  -         try {
  -             do {
  -                 FoXMLEvent ev = this.xmlevents.expectStartElement
  +        public FoRepeatablePageMasterAlternatives
  +                            (FOTree foTree, FONode parent, FoXMLEvent event)
  +            throws Tree.TreeException, FOPException, PropertyException
  +        {
  +            super(foTree, FObjectNames.REPEATABLE_PAGE_MASTER_ALTERNATIVES,
  +                    parent, event, FOPropertySets.SEQ_MASTER_SET,
  +                    r_p_m_a_PropsMap, r_p_m_a_Indices, r_p_m_a_numProps);
  +
  +            // Process conditional-page-master-references here
  +            try {
  +                do {
  +                    FoXMLEvent ev = this.xmlevents.expectStartElement
                               (FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE,
                                                       XMLEvent.DISCARD_W_SPACE);
                       if (ev == null) break; // Sub-sequences exhausted
  @@ -187,47 +306,49 @@
                       //    ("Found conditional-page-master-reference");
                       new FoConditionalPageMasterReference(foTree, this, ev);
                       this.xmlevents.getEndElement(ev);
  -             } while (true);
  -         } catch (NoSuchElementException e) {
  -             // End of file reached
  +                } while (true);
  +            } catch (NoSuchElementException e) {
  +                // End of file reached
                   throw new FOPException("EOF in repeatable-page-masters.");
  -         }
  -         XMLEvent ev = this.xmlevents.getEndElement(event);
  -     }
  -
  -     public PropertyValue getMaximumRepeats() throws PropertyException {
  -         return this.getPropertyValue(PropNames.MAXIMUM_REPEATS);
  -     }
  -
  -     public class FoConditionalPageMasterReference extends FONode {
  -
  -         public FoConditionalPageMasterReference
  -                         (FOTree foTree, FONode parent, FoXMLEvent event)
  -         throws Tree.TreeException, FOPException, PropertyException
  -         {
  -             super(foTree, FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE,
  -                             parent, event, FOPropertySets.SEQ_MASTER_SET);
  -         }
  -
  -         public PropertyValue getMasterReference() throws PropertyException
  -         {
  -             return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  -         }
  -
  -         public PropertyValue getPagePosition() throws PropertyException {
  -             return this.getPropertyValue(PropNames.PAGE_POSITION);
  -         }
  -
  -         public PropertyValue getOddOrEven() throws PropertyException {
  -             return this.getPropertyValue(PropNames.ODD_OR_EVEN);
  -         }
  -
  -         public PropertyValue getBlankOrNotBlank() throws PropertyException
  -         {
  -             return this.getPropertyValue(PropNames.BLANK_OR_NOT_BLANK);
  -         }
  +            }
  +            this.makeSparsePropsSet();
  +        }
  +
  +        public PropertyValue getMaximumRepeats() throws PropertyException {
  +            return this.getPropertyValue(PropNames.MAXIMUM_REPEATS);
  +        }
  +
  +        public class FoConditionalPageMasterReference extends FONode {
  +
  +            public FoConditionalPageMasterReference
  +                            (FOTree foTree, FONode parent, FoXMLEvent event)
  +            throws Tree.TreeException, FOPException, PropertyException
  +            {
  +                super(foTree, FObjectNames.CONDITIONAL_PAGE_MASTER_REFERENCE,
  +                        parent, event, FOPropertySets.SEQ_MASTER_SET,
  +                        c_p_m_r_PropsMap, c_p_m_r_Indices, c_p_m_r_numProps);
  +                this.makeSparsePropsSet();
  +            }
  +
  +            public PropertyValue getMasterReference() throws PropertyException
  +            {
  +                return this.getPropertyValue(PropNames.MASTER_REFERENCE);
  +            }
  +
  +            public PropertyValue getPagePosition() throws PropertyException {
  +                return this.getPropertyValue(PropNames.PAGE_POSITION);
  +            }
  +
  +            public PropertyValue getOddOrEven() throws PropertyException {
  +                return this.getPropertyValue(PropNames.ODD_OR_EVEN);
  +            }
  +
  +            public PropertyValue getBlankOrNotBlank() throws PropertyException
  +            {
  +                return this.getPropertyValue(PropNames.BLANK_OR_NOT_BLANK);
  +            }
   
  -     } // FoConditionalPageMasterReference
  +        } // FoConditionalPageMasterReference
   
       }// FoRepeatablePageMasterAlternatives
   
  
  
  

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

Reply via email to