aboutsummaryrefslogtreecommitdiffstats
path: root/src/java/org/apache/fop/fo/properties
diff options
context:
space:
mode:
Diffstat (limited to 'src/java/org/apache/fop/fo/properties')
-rw-r--r--src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java8
-rw-r--r--src/java/org/apache/fop/fo/properties/CharacterProperty.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/ColorProperty.java15
-rwxr-xr-xsrc/java/org/apache/fop/fo/properties/CommonFont.java4
-rw-r--r--src/java/org/apache/fop/fo/properties/CommonHyphenation.java2
-rwxr-xr-xsrc/java/org/apache/fop/fo/properties/EnumNumber.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/EnumProperty.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/FixedLength.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/FontFamilyProperty.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/KeepProperty.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/NumberProperty.java2
-rw-r--r--src/java/org/apache/fop/fo/properties/PropertyCache.java67
-rw-r--r--src/java/org/apache/fop/fo/properties/StringProperty.java39
13 files changed, 78 insertions, 71 deletions
diff --git a/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java b/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java
index de74d4be6..6307ad1c5 100644
--- a/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java
+++ b/src/java/org/apache/fop/fo/properties/BackgroundPositionShorthand.java
@@ -41,7 +41,11 @@ public class BackgroundPositionShorthand extends ListProperty {
*/
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 @@ public class BackgroundPositionShorthand extends ListProperty {
* 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 {
diff --git a/src/java/org/apache/fop/fo/properties/CharacterProperty.java b/src/java/org/apache/fop/fo/properties/CharacterProperty.java
index 1496f5f86..f42591fe8 100644
--- a/src/java/org/apache/fop/fo/properties/CharacterProperty.java
+++ b/src/java/org/apache/fop/fo/properties/CharacterProperty.java
@@ -48,7 +48,7 @@ public final class CharacterProperty extends Property {
}
/** 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;
diff --git a/src/java/org/apache/fop/fo/properties/ColorProperty.java b/src/java/org/apache/fop/fo/properties/ColorProperty.java
index de648420b..a2a3d2150 100644
--- a/src/java/org/apache/fop/fo/properties/ColorProperty.java
+++ b/src/java/org/apache/fop/fo/properties/ColorProperty.java
@@ -33,7 +33,7 @@ import org.apache.fop.util.ColorUtil;
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 @@ public final class ColorProperty extends Property {
*
* @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 @@ public final class ColorProperty extends Property {
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.
diff --git a/src/java/org/apache/fop/fo/properties/CommonFont.java b/src/java/org/apache/fop/fo/properties/CommonFont.java
index a2d01ffa3..1e3f8d43d 100755
--- a/src/java/org/apache/fop/fo/properties/CommonFont.java
+++ b/src/java/org/apache/fop/fo/properties/CommonFont.java
@@ -37,7 +37,7 @@ public final class CommonFont {
/** 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 @@ public final class CommonFont {
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;
diff --git a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
index dfafa3b16..a294b2bbd 100644
--- a/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
+++ b/src/java/org/apache/fop/fo/properties/CommonHyphenation.java
@@ -38,7 +38,7 @@ public final class CommonHyphenation {
/** 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;
diff --git a/src/java/org/apache/fop/fo/properties/EnumNumber.java b/src/java/org/apache/fop/fo/properties/EnumNumber.java
index 2cfc67f27..5e60b4e35 100755
--- a/src/java/org/apache/fop/fo/properties/EnumNumber.java
+++ b/src/java/org/apache/fop/fo/properties/EnumNumber.java
@@ -29,7 +29,7 @@ import org.apache.fop.fo.expr.PropertyException;
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;
diff --git a/src/java/org/apache/fop/fo/properties/EnumProperty.java b/src/java/org/apache/fop/fo/properties/EnumProperty.java
index 328ed85a9..d3043c5c3 100644
--- a/src/java/org/apache/fop/fo/properties/EnumProperty.java
+++ b/src/java/org/apache/fop/fo/properties/EnumProperty.java
@@ -29,7 +29,7 @@ import org.apache.fop.fo.expr.PropertyException;
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
diff --git a/src/java/org/apache/fop/fo/properties/FixedLength.java b/src/java/org/apache/fop/fo/properties/FixedLength.java
index 6debdd145..5636a4225 100644
--- a/src/java/org/apache/fop/fo/properties/FixedLength.java
+++ b/src/java/org/apache/fop/fo/properties/FixedLength.java
@@ -45,7 +45,7 @@ public final class FixedLength extends LengthProperty {
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);
diff --git a/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java b/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java
index 610882aa4..7404dbe9b 100644
--- a/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java
+++ b/src/java/org/apache/fop/fo/properties/FontFamilyProperty.java
@@ -31,7 +31,7 @@ import org.apache.fop.fo.expr.PropertyException;
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;
diff --git a/src/java/org/apache/fop/fo/properties/KeepProperty.java b/src/java/org/apache/fop/fo/properties/KeepProperty.java
index 2701c3f59..67961b6e5 100644
--- a/src/java/org/apache/fop/fo/properties/KeepProperty.java
+++ b/src/java/org/apache/fop/fo/properties/KeepProperty.java
@@ -30,7 +30,7 @@ import org.apache.fop.fo.expr.PropertyException;
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;
diff --git a/src/java/org/apache/fop/fo/properties/NumberProperty.java b/src/java/org/apache/fop/fo/properties/NumberProperty.java
index 58400d76e..0ba5300ae 100644
--- a/src/java/org/apache/fop/fo/properties/NumberProperty.java
+++ b/src/java/org/apache/fop/fo/properties/NumberProperty.java
@@ -103,7 +103,7 @@ public final class NumberProperty extends Property implements Numeric {
}
/** 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;
diff --git a/src/java/org/apache/fop/fo/properties/PropertyCache.java b/src/java/org/apache/fop/fo/properties/PropertyCache.java
index 26ec2e611..2c51bc081 100644
--- a/src/java/org/apache/fop/fo/properties/PropertyCache.java
+++ b/src/java/org/apache/fop/fo/properties/PropertyCache.java
@@ -42,7 +42,9 @@ public final class PropertyCache {
/** 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 @@ public final class PropertyCache {
/* 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 @@ public final class PropertyCache {
}
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 @@ public final class PropertyCache {
* 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 @@ public final class PropertyCache {
/* 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 @@ public final class PropertyCache {
* 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 @@ public final class PropertyCache {
}
/**
- * 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 @@ public final class PropertyCache {
* @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 @@ public final class PropertyCache {
return (CommonFont) fetch((Object) cf);
}
+
+ /** {@inheritDoc} */
+ public String toString() {
+ return super.toString() + "[runtimeType=" + this.runtimeType + "]";
+ }
+
+
}
diff --git a/src/java/org/apache/fop/fo/properties/StringProperty.java b/src/java/org/apache/fop/fo/properties/StringProperty.java
index f84a76c83..194170fec 100644
--- a/src/java/org/apache/fop/fo/properties/StringProperty.java
+++ b/src/java/org/apache/fop/fo/properties/StringProperty.java
@@ -72,13 +72,16 @@ public final class StringProperty extends Property {
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 @@ public final class StringProperty extends Property {
* @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();
}