You are viewing a plain text version of this content. The canonical link for it is here.
Posted to fop-commits@xmlgraphics.apache.org by ad...@apache.org on 2008/05/08 15:56:14 UTC

svn commit: r654528 - /xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/

Author: adelmelle
Date: Thu May  8 06:56:14 2008
New Revision: 654528

URL: http://svn.apache.org/viewvc?rev=654528&view=rev
Log:
Tweak:
-> add 'runtimeType' member and toString() to PropertyCache to facilitate debugging
-> modify the initial assignment in the related Property types accordingly


Modified:
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/ColorProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonFont.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumNumber.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FixedLength.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/KeepProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
    xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java Thu May  8 06:56:14 2008
@@ -41,7 +41,11 @@
      */
     public static class Maker extends ListProperty.Maker {
 
-        /** {@inheritDoc} */
+        /**
+         * Construct an instance of a Maker for the given property.
+         * 
+         * @param propId The Constant ID of the property to be made.
+         */
         public Maker(int propId) {
             super(propId);
         }
@@ -72,7 +76,7 @@
          * Returns a {@link org.apache.fop.datatypes.PercentBase} whose
          * <code>getDimension()</code> returns 1.
          */
-        public PercentBase getPercentBase() {
+        public PercentBase getPercentBase(PropertyList pl) {
             return new PercentBase() {
                 /** {@inheritDoc} */
                 public int getBaseLength(PercentBaseContext context) throws PropertyException {

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CharacterProperty.java Thu May  8 06:56:14 2008
@@ -48,7 +48,7 @@
     }
 
     /** cache containing all canonical CharacterProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(CharacterProperty.class);
 
     private final char character;
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/ColorProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/ColorProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/ColorProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/ColorProperty.java Thu May  8 06:56:14 2008
@@ -33,7 +33,7 @@
 public final class ColorProperty extends Property  {
     
     /** cache holding canonical ColorProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(ColorProperty.class);
     
     /**
      * The color represented by this property.
@@ -92,6 +92,8 @@
      * 
      * @param foUserAgent FOP user agent
      * @param value RGB value as String to be parsed
+     * @return the canonical ColorProperty instance corresponding 
+     *         to the given value
      * @throws PropertyException if the value can't be parsed
      * @see ColorUtil#parseColorString(FOUserAgent, String)
      */
@@ -99,19 +101,10 @@
         ColorProperty instance = new ColorProperty(
                                        ColorUtil.parseColorString(
                                                foUserAgent, value));
-        return (ColorProperty) cache.fetch(instance);
+        return (ColorProperty)cache.fetch(instance);
     }
 
     /**
-     * Returns an instance of a color property given a color
-     * @param color the color value
-     * @return the color property
-     */
-    public static ColorProperty getInstance(Color color) {
-        return (ColorProperty) cache.fetch(new ColorProperty(color));
-    }
-    
-    /**
      * Create a new ColorProperty with a given color.
      * 
      * @param value the color to use.

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonFont.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonFont.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonFont.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonFont.java Thu May  8 06:56:14 2008
@@ -37,7 +37,7 @@
 
     /** cache holding canonical CommonFont instances (only those with
      *  absolute font-size and font-size-adjust) */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(CommonFont.class);
     
     /**
      * Class holding canonical instances of bundles of the
@@ -47,7 +47,7 @@
     protected static final class CachedCommonFont {
         
         /** cache holding all canonical instances */
-        private static final PropertyCache cache = new PropertyCache();
+        private static final PropertyCache cache = new PropertyCache(CachedCommonFont.class);
         
         private int hash = 0;
         

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/CommonHyphenation.java Thu May  8 06:56:14 2008
@@ -38,7 +38,7 @@
     /** Logger */
     protected static Log log = LogFactory.getLog(CommonHyphenation.class);
     
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(CommonHyphenation.class);
     
     private int hash = 0;
     

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumNumber.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumNumber.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumNumber.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumNumber.java Thu May  8 06:56:14 2008
@@ -29,7 +29,7 @@
 public final class EnumNumber extends Property implements Numeric {
 
     /** cache holding all canonical EnumNumber instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(EnumNumber.class);
 
     private final EnumProperty enumProperty;
     

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/EnumProperty.java Thu May  8 06:56:14 2008
@@ -29,7 +29,7 @@
 public final class EnumProperty extends Property {
     
     /** cache holding all canonical EnumProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(EnumProperty.class);
 
     /**
      * Inner class for creating EnumProperty instances

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FixedLength.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FixedLength.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FixedLength.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FixedLength.java Thu May  8 06:56:14 2008
@@ -45,7 +45,7 @@
     public static final String MPT = "mpt";
 
     /** cache holding all canonical FixedLength instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(FixedLength.class);
     
     /** canonical zero-length instance */
     public static final FixedLength ZERO_FIXED_LENGTH = new FixedLength(0, FixedLength.MPT, 1.0f);

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java Thu May  8 06:56:14 2008
@@ -31,7 +31,7 @@
 public final class FontFamilyProperty extends ListProperty {
 
     /** cache holding all canonical FontFamilyProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(FontFamilyProperty.class);
     
     private int hash = 0;
     

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/KeepProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/KeepProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/KeepProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/KeepProperty.java Thu May  8 06:56:14 2008
@@ -30,7 +30,7 @@
 public final class KeepProperty extends Property implements CompoundDatatype {
     
     /** class holding all canonical KeepProperty instances*/
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(KeepProperty.class);
     
     private boolean isCachedValue = false;
     private Property withinLine;

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/NumberProperty.java Thu May  8 06:56:14 2008
@@ -103,7 +103,7 @@
     }
     
     /** cache holding all canonical NumberProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(NumberProperty.class);
     
     private final Number number;
 

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/PropertyCache.java Thu May  8 06:56:14 2008
@@ -42,7 +42,9 @@
     /** the table of hash-buckets */
     private CacheEntry[] table = new CacheEntry[8];
     
-    boolean[] votesForRehash = new boolean[SEGMENT_MASK + 1];
+    private Class runtimeType;
+    
+    final boolean[] votesForRehash = new boolean[SEGMENT_MASK + 1];
     
     /* same hash function as used by java.util.HashMap */
     private static int hash(Object x) {
@@ -80,10 +82,10 @@
     /* Wrapper objects to synchronize on */
     private final class CacheSegment {
         private int count = 0;
-        private ReferenceQueue staleEntries = new ReferenceQueue();
+        private volatile ReferenceQueue staleEntries = new ReferenceQueue();
     }    
     
-    private final void cleanSegment(int segmentIndex) {
+    private void cleanSegment(int segmentIndex) {
         CacheEntry entry;
         CacheSegment segment = segments[segmentIndex];
         int bucketIndex;
@@ -113,29 +115,26 @@
         }
         synchronized (votesForRehash) {
             if (oldCount > segment.count) {
-                if (votesForRehash[segmentIndex]) {
-                    votesForRehash[segmentIndex] = false;
-                }
+                votesForRehash[segmentIndex] = false;
                 return;
-            } else {
-                /* cleanup had no effect */
-                if (!votesForRehash[segmentIndex]) {
-                    /* first time for this segment */
-                    votesForRehash[segmentIndex] = true;
-                    int voteCount = 0;
-                    for (int i = SEGMENT_MASK + 1; --i >= 0; ) {
-                        if (votesForRehash[i]) {
-                            voteCount++;
-                        }
+            }
+            /* cleanup had no effect */
+            if (!votesForRehash[segmentIndex]) {
+                /* first time for this segment */
+                votesForRehash[segmentIndex] = true;
+                int voteCount = 0;
+                for (int i = SEGMENT_MASK + 1; --i >= 0; ) {
+                    if (votesForRehash[i]) {
+                        voteCount++;
                     }
-                    if (voteCount > SEGMENT_MASK / 4) {
-                        rehash(SEGMENT_MASK);
-                        /* reset votes */
-                        for (int i = SEGMENT_MASK + 1; --i >= 0;) {
-                            votesForRehash[i] = false;
-                        }
-    
+                }
+                if (voteCount > SEGMENT_MASK / 4) {
+                    rehash(SEGMENT_MASK);
+                    /* reset votes */
+                    for (int i = SEGMENT_MASK + 1; --i >= 0;) {
+                        votesForRehash[i] = false;
                     }
+
                 }
             }
         }
@@ -148,7 +147,7 @@
      * cleanup will be performed to try and remove obsolete
      * entries.
      */
-    private final void put(Object o) {
+    private void put(Object o) {
         
         int hash = hash(o);
         CacheSegment segment = segments[hash & SEGMENT_MASK];
@@ -180,7 +179,7 @@
     
 
     /* Gets a cached instance. Returns null if not found */
-    private final Object get(Object o) {
+    private Object get(Object o) {
         
         int hash = hash(o);
         int index = hash & (table.length - 1);
@@ -219,7 +218,7 @@
      * extends the cache and redistributes the entries.
      * 
      */
-    private final void rehash(int index) {
+    private void rehash(int index) {
         
         CacheSegment seg = segments[index];
         synchronized (seg) {
@@ -258,12 +257,15 @@
     }
     
     /**
-     *  Default constructor. 
+     *  Default constructor.
+     *  
+     *  @param c    Runtime type of the objects that will be stored in the cache
      */
-    public PropertyCache() {
+    public PropertyCache(Class c) {
         for (int i = SEGMENT_MASK + 1; --i >= 0;) {
             segments[i] = new CacheSegment();
         }
+        this.runtimeType = c;
     }
     
     /**
@@ -275,7 +277,7 @@
      *  @param obj   the Object to check for
      *  @return  the cached instance
      */
-    private final Object fetch(Object obj) {
+    private Object fetch(Object obj) {
         if (obj == null) {
             return null;
         }
@@ -339,4 +341,11 @@
         
         return (CommonFont) fetch((Object) cf);
     }
+
+    /** {@inheritDoc} */
+    public String toString() {
+        return super.toString() + "[runtimeType=" + this.runtimeType + "]";
+    }
+    
+    
 }

Modified: xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java
URL: http://svn.apache.org/viewvc/xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java?rev=654528&r1=654527&r2=654528&view=diff
==============================================================================
--- xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java (original)
+++ xmlgraphics/fop/trunk/src/java/org/apache/fop/fo/properties/StringProperty.java Thu May  8 06:56:14 2008
@@ -72,13 +72,16 @@
                     value = str;
                 }
             }
-            return new StringProperty(value);
+            return StringProperty.getInstance(value);
         }
 
-    }    // end String.Maker
+    }
 
     /** cache containing all canonical StringProperty instances */
-    private static final PropertyCache cache = new PropertyCache();
+    private static final PropertyCache cache = new PropertyCache(StringProperty.class);
+    
+    /** canonical instance for empty strings */
+    public static final StringProperty EMPTY_STRING_PROPERTY = new StringProperty("");
     
     private final String str;
 
@@ -97,40 +100,38 @@
      * @return  the canonical instance
      */
     public static StringProperty getInstance(String str) {
-        return (StringProperty)cache.fetch(
-                   new StringProperty(str));
+        if ("".equals(str) || str == null) {
+            return EMPTY_STRING_PROPERTY;
+        } else {
+            return (StringProperty)cache.fetch(
+                       new StringProperty(str));
+        }
     }
     
-    /**
-     * @return the Object equivalent of this property
-     */
+    /** @return the Object equivalent of this property */
     public Object getObject() {
         return this.str;
     }
 
-    /**
-     * @return the String equivalent of this property
-     */
+    /** @return the String equivalent of this property */
     public String getString() {
         return this.str;
     }
 
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public boolean equals(Object obj) {
+        if (this == obj) {
+            return true;
+        }
         if (obj instanceof StringProperty) {
             StringProperty sp = (StringProperty)obj;
             return (sp.str == this.str
                     || sp.str.equals(this.str));
-        } else {
-            return false;
         }
+        return false;
     }
     
-    /**
-     * {@inheritDoc}
-     */
+    /** {@inheritDoc} */
     public int hashCode() {
         return str.hashCode();
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: fop-commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: fop-commits-help@xmlgraphics.apache.org