package org.apache.struts.util;

import java.io.Serializable;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public abstract class MessageResourcesFactory implements Serializable {
  protected boolean returnNull = true;
  
  public boolean getReturnNull() {
    return this.returnNull;
  }
  
  public void setReturnNull(boolean returnNull) {
    this.returnNull = returnNull;
  }
  
  protected static transient Class clazz = null;
  
  private static Log LOG = LogFactory.getLog(MessageResourcesFactory.class);
  
  protected static String factoryClass = "org.apache.struts.util.PropertyMessageResourcesFactory";
  
  public static String getFactoryClass() {
    return factoryClass;
  }
  
  public static void setFactoryClass(String factoryClass) {
    MessageResourcesFactory.factoryClass = factoryClass;
    clazz = null;
  }
  
  public static MessageResourcesFactory createFactory() {
    try {
      if (clazz == null)
        clazz = RequestUtils.applicationClass(factoryClass); 
      MessageResourcesFactory factory = clazz.newInstance();
      return factory;
    } catch (Throwable t) {
      LOG.error("MessageResourcesFactory.createFactory", t);
      return null;
    } 
  }
  
  public abstract MessageResources createResources(String paramString);
}
