tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Donie Kelly <donie.ke...@tecnomen.ie>
Subject Static class not working under multiple webapps deployment
Date Tue, 15 Oct 2002 10:11:52 GMT
Hi
I have written a static class which is populated with data on startup of my
servlets and is suppose to be use in the context of the request. However,
the static class seems to return the same information for all webapps and
holds the configuration of the last servlet run on startup. Here is the
code... As you can see I want to use something that looks like the
System.Properties but System.Properties is gloabal so it's no use to me. I
want to be able to set the webapp name here so it's used during processing
but at the moment it's only returning the last name configured for the last
webapp.

Any ideas why this is happening. What have I done wrong to make this class
appear global?
Thanks
Donie


import org.apache.log4j.Category;
import java.util.Hashtable;
import java.util.Properties;
import java.io.InputStream;

public class vMmsc
{
static Category log = Category.getInstance(vMmsc.class.getName());
public final static String version = "$Revision:   1.3  $$Date:   10 Oct
2002 11:57:48  $";
public static String getVersion() { return version; }
private static Properties props=new Properties();

    // Defeats instantiation
    private vMmsc(){}
    
    public static void load(InputStream is)
    {
        try
        {
            props.load(is);       
        }
        catch(Exception ex)
        {
            log.error("Problem loading property file: " + ex.getMessage());

        }
    }
    
    public static void setProperty(String Name, String Value)
    {
        props.setProperty(Name, Value);
    }
    
    public static String getProperty(String Name)
    {
        String Value = props.getProperty(Name);
        if(Value==null || Value.equalsIgnoreCase(""))
            log.debug("The property value " + Name + " is not defined");
        return Value;
    }
    
    public static String getProperty(String Name, String defaultValue)
    {
        String Value = props.getProperty(Name);
        if(Value==null || Value.equalsIgnoreCase(""))
        {
            log.debug("The property value " + Name + " is returning it's
default value");
            return defaultValue;
        }
        return Value;
    }
    
    public static Integer getInteger(String Name)
    {
        String Value = getProperty(Name);
        if(Value==null || Value.equalsIgnoreCase(""))
            log.debug("The property value " + Name + " is not defined");
            
        return new Integer(Value);
    }
    
    public static Integer getInteger(String Name, int defaultValue)
    {
        String Value = getProperty(Name);
        if(Value==null || Value.equalsIgnoreCase(""))
        {
            log.debug("The property value " + Name + " is returning it's
default value");
            return new Integer(defaultValue);
        }    
        return new Integer(Value);
    }

    // Return true if property is enabled/yes/true
    public static boolean isEnabled(String Name)
    {
        String Value = getProperty(Name);
        
        if(Value!=null)
            if(Value.equalsIgnoreCase("yes") || 
                Value.equalsIgnoreCase("true") || 
                Value.equalsIgnoreCase("enabled") ||
                Value.equalsIgnoreCase("1"))
                return true;
        return false;    
    }
}

--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message