minchau     2004/10/14 14:22:04

  Modified:    java/src/org/apache/xml/serializer/utils Utils.java
                        Messages.java SerializerMessages.java
  Log:
  Submitted by: Brian Minchau
  Made some fields final or private to make the objects immutable,
  especially the messages.
  
  Revision  Changes    Path
  1.2       +5 -50     
xml-xalan/java/src/org/apache/xml/serializer/utils/Utils.java
  
  Index: Utils.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/utils/Utils.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Utils.java        14 Oct 2004 18:30:53 -0000      1.1
  +++ Utils.java        14 Oct 2004 21:22:04 -0000      1.2
  @@ -30,57 +30,12 @@
    */
   public final class Utils
   {
  -
       /**
  -     * This nested class acts as a way to lazy load the hashtable
  -     * in a thread safe way.
  +     * A singleton Messages object is used to load the 
  +     * given resource bundle just once, it is
  +     * used by multiple transformations as long as the JVM stays up.
        */
  -    static private class CacheHolder
  -    {
  -        static final Hashtable cache;
  -        static {
  -            cache = new Hashtable();
  -        }
  -    }
  -    /**
  -     * Load the class by name.
  -     * 
  -     * This implementation, for performance reasons,
  -     * caches all classes loaded by name and
  -     * returns the cached Class object if it can previously 
  -     * loaded classes that were load by name.  If not previously loaded
  -     * an attempt is made to load with Class.forName(classname)
  -     * @param classname the name of the class to be loaded
  -     * @return the loaded class, never null. If the class could not be
  -     * loaded a ClassNotFound exception is thrown.
  -     * @throws ClassNotFoundException if the class was not loaded
  -     */
  -    static Class ClassForName(String classname) throws ClassNotFoundException
  -    {
  -        Class c;
  -        // the first time the next line runs will reference
  -        // CacheHolder, causing the class to load and create the
  -        // Hashtable.
  -        Object o = CacheHolder.cache.get(classname);
  -        if (o == null)
  -        {
  -            // class was not in the cache, so try to load it
  -            c = Class.forName(classname);
  -            // if the class is not found we will have thrown a
  -            // ClassNotFoundException on the statement above
  -            
  -            // if we get here c is not null
  -            CacheHolder.cache.put(classname, c);
  -        }
  -        else
  -        {
  -            c = (Class)o;
  -        }
  -        return c;
  -    }
  -    
  -    
  -    public static org.apache.xml.serializer.utils.Messages messages= 
  +    public static final org.apache.xml.serializer.utils.Messages messages= 
           new org.apache.xml.serializer.utils.Messages(
               "org.apache.xml.serializer.utils.SerializerMessages");
   }
  
  
  
  1.2       +17 -13    
xml-xalan/java/src/org/apache/xml/serializer/utils/Messages.java
  
  Index: Messages.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/utils/Messages.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- Messages.java     14 Oct 2004 18:30:53 -0000      1.1
  +++ Messages.java     14 Oct 2004 21:22:04 -0000      1.2
  @@ -95,10 +95,10 @@
   public final class Messages
   {
       /** The local object to use.  */
  -    private Locale m_locale = Locale.getDefault();
  +    private final Locale m_locale = Locale.getDefault();
   
       /** The language specific resource object for messages.  */
  -    private ListResourceBundle m_resourceBundle = null;
  +    private ListResourceBundle m_resourceBundle;
   
       /** The class name of the error message string table with no language 
suffix. */
       private String m_resourceBundleName;
  @@ -128,13 +128,17 @@
        * 
        * @xsl.usage internal
        */
  -    public Messages(String resourceBundle)
  +    Messages(String resourceBundle)
       {
   
           m_resourceBundleName = resourceBundle;
       }
       
  -    /**
  +    // This method is dropped because it makes the singleton messages object
  +    // mutable, and this messages object is used as long as the JVM stays up,
  +    // potentially by different users in a server situation.
  +    // This method was also never called anywhere in the serializer... so 
it's gone.
  +    /*
        * Set the Locale object to use. If this method is not called the
        * default locale is used. This method needs to be called before
        * loadResourceBundle().
  @@ -142,10 +146,10 @@
        * @param locale non-null reference to Locale object.
        * @xsl.usage internal
        */
  -    public void setLocale(Locale locale)
  -    {
  -        m_locale = locale;
  -    }
  +//    public void setLocale(Locale locale)
  +//    {
  +//        m_locale = locale;
  +//    }
   
       /**
        * Get the Locale object that is being used.
  @@ -153,7 +157,7 @@
        * @return non-null reference to Locale object.
        * @xsl.usage internal
        */
  -    public Locale getLocale()
  +    private Locale getLocale()
       {
           return m_locale;
       }
  @@ -163,7 +167,7 @@
        * previously set by a call to loadResourceBundle(className)
        * @xsl.usage internal
        */
  -    public ListResourceBundle getResourceBundle()
  +    private ListResourceBundle getResourceBundle()
       {
           return m_resourceBundle;
       }
  @@ -206,7 +210,7 @@
        * @return The formatted message string.
        * @xsl.usage internal
        */
  -    public final String createMsg(
  +    private final String createMsg(
           ListResourceBundle fResourceBundle,
           String msgKey,
           Object args[]) //throws Exception
  @@ -311,7 +315,7 @@
        * @throws MissingResourceException
        * @xsl.usage internal
        */
  -    public ListResourceBundle loadResourceBundle(String resourceBundle)
  +    private ListResourceBundle loadResourceBundle(String resourceBundle)
           throws MissingResourceException
       {
           m_resourceBundleName = resourceBundle;
  
  
  
  1.2       +22 -22    
xml-xalan/java/src/org/apache/xml/serializer/utils/SerializerMessages.java
  
  Index: SerializerMessages.java
  ===================================================================
  RCS file: 
/home/cvs/xml-xalan/java/src/org/apache/xml/serializer/utils/SerializerMessages.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- SerializerMessages.java   14 Oct 2004 18:30:53 -0000      1.1
  +++ SerializerMessages.java   14 Oct 2004 21:22:04 -0000      1.2
  @@ -75,10 +75,10 @@
   
       // Message keys required by the message utility class (in case it has 
problems
     // with messages in this class)
  -  public static String BAD_MSGKEY = "BAD_CODE";
  +  public static final String BAD_MSGKEY = "BAD_CODE";
   
     /** String to use if the message format operation failed.  */
  -  public static String BAD_MSGFORMAT = "FORMAT_FAILED";
  +  public static final String BAD_MSGFORMAT = "FORMAT_FAILED";
     
     // Message keys used by the serializer
     public static final String ER_RESOURCE_COULD_NOT_FIND = 
"ER_RESOURCE_COULD_NOT_FIND";
  @@ -96,24 +96,24 @@
     public static final String ER_ILLEGAL_CHARACTER = "ER_ILLEGAL_CHARACTER";
     
   
  -  public static String ER_INVALID_PORT = "ER_INVALID_PORT";
  -  public static String ER_PORT_WHEN_HOST_NULL = "ER_PORT_WHEN_HOST_NULL";
  -  public static String ER_HOST_ADDRESS_NOT_WELLFORMED = 
"ER_HOST_ADDRESS_NOT_WELLFORMED";
  -  public static String ER_SCHEME_NOT_CONFORMANT = "ER_SCHEME_NOT_CONFORMANT";
  -  public static String ER_SCHEME_FROM_NULL_STRING = 
"ER_SCHEME_FROM_NULL_STRING";
  -  public static String ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE = 
"ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE";
  -  public static String ER_PATH_INVALID_CHAR = "ER_PATH_INVALID_CHAR";
  -  public static String ER_NO_SCHEME_INURI = "ER_NO_SCHEME_INURI";
  -  public static String ER_FRAG_INVALID_CHAR = "ER_FRAG_INVALID_CHAR";
  -  public static String ER_FRAG_WHEN_PATH_NULL = "ER_FRAG_WHEN_PATH_NULL";
  -  public static String ER_FRAG_FOR_GENERIC_URI = "ER_FRAG_FOR_GENERIC_URI";
  -  public static String ER_NO_SCHEME_IN_URI = "ER_NO_SCHEME_IN_URI";
  -  public static String ER_CANNOT_INIT_URI_EMPTY_PARMS = 
"ER_CANNOT_INIT_URI_EMPTY_PARMS";
  -  public static String ER_NO_FRAGMENT_STRING_IN_PATH = 
"ER_NO_FRAGMENT_STRING_IN_PATH";
  -  public static String ER_NO_QUERY_STRING_IN_PATH = 
"ER_NO_QUERY_STRING_IN_PATH";
  -  public static String ER_NO_PORT_IF_NO_HOST = "ER_NO_PORT_IF_NO_HOST";
  -  public static String ER_NO_USERINFO_IF_NO_HOST = 
"ER_NO_USERINFO_IF_NO_HOST";
  -  public static String ER_SCHEME_REQUIRED = "ER_SCHEME_REQUIRED";
  +  public static final String ER_INVALID_PORT = "ER_INVALID_PORT";
  +  public static final String ER_PORT_WHEN_HOST_NULL = 
"ER_PORT_WHEN_HOST_NULL";
  +  public static final String ER_HOST_ADDRESS_NOT_WELLFORMED = 
"ER_HOST_ADDRESS_NOT_WELLFORMED";
  +  public static final String ER_SCHEME_NOT_CONFORMANT = 
"ER_SCHEME_NOT_CONFORMANT";
  +  public static final String ER_SCHEME_FROM_NULL_STRING = 
"ER_SCHEME_FROM_NULL_STRING";
  +  public static final String ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE = 
"ER_PATH_CONTAINS_INVALID_ESCAPE_SEQUENCE";
  +  public static final String ER_PATH_INVALID_CHAR = "ER_PATH_INVALID_CHAR";
  +  public static final String ER_NO_SCHEME_INURI = "ER_NO_SCHEME_INURI";
  +  public static final String ER_FRAG_INVALID_CHAR = "ER_FRAG_INVALID_CHAR";
  +  public static final String ER_FRAG_WHEN_PATH_NULL = 
"ER_FRAG_WHEN_PATH_NULL";
  +  public static final String ER_FRAG_FOR_GENERIC_URI = 
"ER_FRAG_FOR_GENERIC_URI";
  +  public static final String ER_NO_SCHEME_IN_URI = "ER_NO_SCHEME_IN_URI";
  +  public static final String ER_CANNOT_INIT_URI_EMPTY_PARMS = 
"ER_CANNOT_INIT_URI_EMPTY_PARMS";
  +  public static final String ER_NO_FRAGMENT_STRING_IN_PATH = 
"ER_NO_FRAGMENT_STRING_IN_PATH";
  +  public static final String ER_NO_QUERY_STRING_IN_PATH = 
"ER_NO_QUERY_STRING_IN_PATH";
  +  public static final String ER_NO_PORT_IF_NO_HOST = "ER_NO_PORT_IF_NO_HOST";
  +  public static final String ER_NO_USERINFO_IF_NO_HOST = 
"ER_NO_USERINFO_IF_NO_HOST";
  +  public static final String ER_SCHEME_REQUIRED = "ER_SCHEME_REQUIRED";
   
     /*
      * Now fill in the message text.
  @@ -124,7 +124,7 @@
     // Error messages...
   
     /** The lookup table for error messages.   */
  -  public static final Object[][] contents = {        
  +  private static final Object[][] contents = {        
       {BAD_MSGKEY, 
         "The message key ''{0}'' is not in the message class ''{1}''"},
       
  
  
  

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

Reply via email to