From: Peter Bernard West Date: Sat, 8 May 2004 13:02:43 +0000 (+0000) Subject: Methods in FObjects made static. X-Git-Tag: Defoe_export~187 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=67bb4f16f0195e6faa43a8fabe2a1a97b8300ce9;p=xmlgraphics-fop.git Methods in FObjects made static. Unused functionality removed. git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/branches/FOP_0-20-0_Alt-Design@197567 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/fop/fo/FObjects.java b/src/java/org/apache/fop/fo/FObjects.java index ef1354f52..15a34d74c 100644 --- a/src/java/org/apache/fop/fo/FObjects.java +++ b/src/java/org/apache/fop/fo/FObjects.java @@ -20,13 +20,13 @@ package org.apache.fop.fo; -import java.lang.reflect.Constructor; -import java.util.HashMap; -import java.util.StringTokenizer; +//import java.lang.reflect.Constructor; +//import java.util.HashMap; +//import java.util.StringTokenizer; import org.apache.fop.apps.FOPException; import org.apache.fop.apps.Fop; -import org.apache.fop.datatypes.Ints; +//import org.apache.fop.datatypes.Ints; import org.apache.fop.fo.flow.*; import org.apache.fop.xml.FoXmlEvent; import org.apache.fop.xml.XmlEvent; @@ -45,161 +45,11 @@ public class FObjects { public static final String packageNamePrefix = Fop.fopPackage; - /** - * Create a singleton FObjects object - */ - public static final FObjects fobjects; - static { - fobjects = new FObjects(); - } - - /** - * @return the singleton - */ - public static final FObjects getFObjects() { - return fobjects; - } - /** * FObjects cannot be instantiated */ private FObjects() {} - /** - * A String[] array of the fo class names. This array is - * effectively 1-based, with the first element being unused. - * The array is initialized in a static initializer by converting the - * fo names from the array FObjectNames.foLocalNames into class names by - * converting the first character of every component word to upper case, - * removing all punctuation characters and prepending the prefix 'Fo'. - * It can be indexed by the fo name constants defined in the - * FObjectNames class. - */ - private static final String[] foClassNames; - - /** - * A String[] array of the fo class package names. This array is - * effectively 1-based, with the first element being unused. - * The array is initialized in a static initializer by constructing - * the package name from the common package prefix set in the field - * packageNamePrefix, the package name suffix associated with - * the fo local names in the FObjectNames.foLocalNames array, - * the the class name which has been constructed in the - * foClassNames array here. - * It can be indexed by the fo name constants defined in the - * FObjectNames class. - */ - private static final String[] foPkgClassNames; - - /** - * An Class[] array containing Class objects corresponding to each of the - * class names in the foClassNames array. It is initialized in a static - * initializer in parallel with the creation of the class names in the - * foClassNames array. It can be indexed by the class name constants - * defined in this file. - * - * It is not guaranteed that there exists a class corresponding to each of - * the FlowObjects defined in this file. - */ - private final Constructor[] foConstructors - = new Constructor[FObjectNames.foLocalNamesLength]; - - /** - * The default constructor arguments for an FObject. N.B. not - * all subclasses of FONode use this constructor; e.g. - * FoRoot, FoPageSequence & FoFlow. - * Generally these FObjects are not invoked through reflection. If such - * invocation becomes necessary for a particular class, a contructor of - * this kind must be added to the class. - *

At present, the only difference is in the addition of the - * int.class constructor argument. - */ - protected static final Class[] defaultConstructorArgs = - new Class[] { - FOTree.class - ,FONode.class - ,FOPageSeqNode.class - ,FoXmlEvent.class - ,int.class - }; - - /** - * A HashMap whose elements are an integer index value keyed by an - * fo local name. The index value is the index of the fo local name in - * the FObjectNames.foLocalNames[] array. - * It is initialized in a static initializer. - */ - private static final HashMap foToIndex; - - /** - * A HashMap whose elements are an integer index value keyed by the name - * of a fo class. The index value is the index of the fo - * class name in the foClassNames[] array. It is initialized in a - * static initializer. - */ - private static final HashMap foClassToIndex; - - static { - String prefix = packageNamePrefix + "."; - String foPrefix = "Fo"; - int namei = 0; // Index of localName in FObjectNames.foLocalNames - int pkgi = 1; // Index of package suffix in foLocalNames - - foClassNames = new String[FObjectNames.foLocalNamesLength]; - foPkgClassNames = new String[FObjectNames.foLocalNamesLength]; - foToIndex = new HashMap( - (int)(FObjectNames.foLocalNamesLength / 0.75) + 1); - foClassToIndex = new HashMap( - (int)(FObjectNames.foLocalNamesLength / 0.75) + 1); - - for (int i = 1; i < FObjectNames.foLocalNamesLength; i++) { - String cname = foPrefix; - String foName; - String pkgname; - try { - foName = FObjectNames.getFOName(i); - pkgname = FObjectNames.getFOPkg(i); - } catch (FOPException fex) { - throw new RuntimeException(fex.getMessage()); - } - StringTokenizer stoke = - new StringTokenizer(foName, "-"); - while (stoke.hasMoreTokens()) { - String token = stoke.nextToken(); - String pname = new Character( - Character.toUpperCase(token.charAt(0)) - ).toString() + token.substring(1); - cname = cname + pname; - } - foClassNames[i] = cname; - - // Set up the array of class package names - // Set up the array of Class objects, indexed by the fo - // constants. - String name = prefix + pkgname + "." + cname; - foPkgClassNames[i] = name; - - // Set up the foToIndex Hashmap with the name of the - // flow object as a key, and the integer index as a value - if (foToIndex.put(foName, - Ints.consts.get(i)) != null) { - throw new RuntimeException( - "Duplicate values in propertyToIndex for key " + - foName); - } - - // Set up the foClassToIndex Hashmap with the name of the - // fo class as a key, and the integer index as a value - - if (foClassToIndex.put(foClassNames[i], - Ints.consts.get(i)) != null) { - throw new RuntimeException( - "Duplicate values in foClassToIndex for key " + - foClassNames[i]); - } - - } - } /** * This method generates generates new FO objects, except for FoPcdata @@ -216,7 +66,7 @@ public class FObjects { * @return the new FO node * @throws FOPException */ - public Object makePageSeqFOChild( + public static Object makePageSeqFOChild( FOTree foTree, FONode pageSequence, FOPageSeqNode parent, FoXmlEvent event, int stateFlags) throws FOPException @@ -319,7 +169,7 @@ public class FObjects { * @return * @throws FOPException */ - public Object makePageSeqFOChild(FOTree foTree, FONode pageSequence, + public static Object makePageSeqFOChild(FOTree foTree, FONode pageSequence, FOPageSeqNode parent, XmlEvent event, int stateFlags) throws FOPException { @@ -335,41 +185,5 @@ public class FObjects { return new FoPcdata(foTree, pageSequence, parent, event, stateFlags); } - /** - * Get the index of an unqualified FO class name - * @param name of the FO - * @return the index - */ - public static int getFoIndex(String name) { - return ((Integer)(foToIndex.get(name))).intValue(); - } - - /** - * Get the unqualified class name of the indicated FO - * @param foIndex of the rwquired FO - * @return the unqualified class name - */ - public static String getClassName(int foIndex) { - return foClassNames[foIndex]; - } - - /** - * Get the fully-qualified class name of the indicated FO - * @param foIndex of the required FO - * @return the fully-qualified class name - */ - public static String getPkgClassName(int foIndex) { - return foPkgClassNames[foIndex]; - } - - /** - * Get the Constructor object for a given FO - * @param foIndex of the FO - * @return the Constructor - */ - public Constructor getConstructor(int foIndex) { - return foConstructors[foIndex]; - } - }