Subversion Repositories bacoAlunos

Rev

Rev 1306 | Blame | Compare with Previous | Last modification | View Log | RSS feed

package openldap;

import jomm.utils.StringComparator;
import org.apache.log4j.Logger;

import java.util.*;


/**
 * Created by IntelliJ IDEA.
 * User: User
 * Date: 25/Jan/2005
 * Time: 12:43:54
 * To change this template use File | Settings | File Templates.
 */


public class LdapProperties{

    private static final 1.5.0/docs/api/java/util/logging/Logger.html">Logger logger = 1.5.0/docs/api/java/util/logging/Logger.html">Logger.getLogger(LdapProperties.class);
    private static 1.5.0/docs/api/java/util/Properties.html">Properties properties = new 1.5.0/docs/api/java/util/Properties.html">Properties();

    static {

        try {
            properties.load(LdapProperties.class.getResourceAsStream("/ldap.properties"));
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
            throw new 1.5.0/docs/api/java/lang/ExceptionInInitializerError.html">ExceptionInInitializerError(ex);
        }
    }

    public static 5+0%2Fdocs%2Fapi+Object">Object getPlugin(1.5.0/docs/api/java/lang/Class.html">Class iface) {

        1.5.0/docs/api/java/lang/String.html">String implName = properties.getProperty(iface.getName());
        if (implName == null) {
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("implementation not specified for " +
                    iface.getName() + " in AuthenticationPluginFactory propeties.");
        }
        try {
            return 1.5.0/docs/api/java/lang/Class.html">Class.forName(implName).newInstance();
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("factory unable to construct instance of " +
                    iface.getName());
        }
    }

    public static 5+0%2Fdocs%2Fapi+Object">Object getPlugin(1.5.0/docs/api/java/lang/String.html">String plugin) {

        1.5.0/docs/api/java/lang/String.html">String implName = properties.getProperty(plugin);
        if (implName == null) {
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("implementation not specified for " +
                    plugin + " in AuthenticationPluginFactory propeties.");
        }
        try {
            return 1.5.0/docs/api/java/lang/Class.html">Class.forName(implName).newInstance();
        } catch (1.5.0/docs/api/java/lang/Exception.html">Exception ex) {
            throw new 1.5.0/docs/api/java/lang/RuntimeException.html">RuntimeException("factory unable to construct instance of " +
                    plugin);
        }
    }

    public static 1.5.0/docs/api/java/lang/String.html">String getProperty(1.5.0/docs/api/java/lang/String.html">String key){return properties.getProperty(key);}
   
    public static int getIntProperty(1.5.0/docs/api/java/lang/String.html">String property)
    {

        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
        int intValue = 0;

        if (stringValue != null)
        {
            try
            {
                intValue = new 1.5.0/docs/api/java/lang/Integer.html">Integer(stringValue).intValue();
            }
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
            {
                logger.warn("Warning: Number format exception in property: " + property);
            }
        }

        return intValue;
    }
    public static long getLongProperty(1.5.0/docs/api/java/lang/String.html">String property)
    {

        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
        long longValue = 0;

        if (stringValue != null)
        {
            try
            {
                longValue = new 1.5.0/docs/api/java/lang/Long.html">Long(stringValue).intValue();
            }
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
            {
                logger.warn("Warning: Number format exception in property: " + property);
            }
        }

        return longValue;
    }

    public static float getFloatProperty(1.5.0/docs/api/java/lang/String.html">String property)
    {

        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
        float floatValue = 0;

        if (stringValue != null)
        {
            try
            {
                floatValue = new 1.5.0/docs/api/java/lang/Float.html">Float(stringValue).floatValue();
            }
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
            {
                logger.warn("Warning: Number format exception in property: " + property);
            }
        }

        return floatValue;
    }

    public static double getDoubleProperty(1.5.0/docs/api/java/lang/String.html">String property)
    {

        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
        double doubleValue = 0;

        if (stringValue != null)
        {
            try
            {
                doubleValue = new 1.5.0/docs/api/java/lang/Float.html">Float(stringValue).doubleValue();
            }
            catch (1.5.0/docs/api/java/lang/NumberFormatException.html">NumberFormatException e)
            {
                logger.warn("Warning: Number format exception in property: " + property);
            }
        }

        return doubleValue;
    }
    public static boolean getBooleanProperty(1.5.0/docs/api/java/lang/String.html">String property)
    {

        1.5.0/docs/api/java/lang/String.html">String stringValue = properties.getProperty(property);
        boolean boolValue = false;

        if (stringValue != null)
        {
            if (stringValue.equalsIgnoreCase("true"))
            {
                boolValue = true;
            }
            else if (stringValue.equalsIgnoreCase("yes"))
            {
                boolValue = true;
            }
        }

        return boolValue;
    }


       /***********************************************************
      * Returns a list of all property names hat starts with the given
      * prefix
      *
      ************************************************************/

     public static 5+0%2Fdocs%2Fapi+List">List getListProperties(1.5.0/docs/api/java/lang/String.html">String propertyPrefix){

        5+0%2Fdocs%2Fapi+List">List props = new 1.5.0/docs/api/java/util/ArrayList.html">ArrayList();
         1.5.0/docs/api/java/util/Enumeration.html">Enumeration enumE;
         try{
             enumE = properties.propertyNames();
         }
         catch(1.5.0/docs/api/java/lang/Exception.html">Exception e){
             logger.fatal("cant load properties");
             return null;
         }

         while (enumE.hasMoreElements()) {
            1.5.0/docs/api/java/lang/String.html">String propertyName = (1.5.0/docs/api/java/lang/String.html">String)enumE.nextElement();
            if (propertyName.startsWith(propertyPrefix)) {
                props.add(propertyName);
            }
         }
         1.5.0/docs/api/java/util/Collections.html">Collections.sort(props,StringComparator.getInstance());
         return props;
     }

     public static 5+0%2Fdocs%2Fapi+List">List getListValuesProperties(1.5.0/docs/api/java/lang/String.html">String propertyPrefix){

        5+0%2Fdocs%2Fapi+List">List props = new 1.5.0/docs/api/java/util/ArrayList.html">ArrayList();
         1.5.0/docs/api/java/util/Enumeration.html">Enumeration enumE;
         try{
             enumE = properties.propertyNames();
         }
         catch(1.5.0/docs/api/java/lang/Exception.html">Exception e){
             logger.fatal("cant load properties");
             return null;
         }
         while (enumE.hasMoreElements()) {
            1.5.0/docs/api/java/lang/String.html">String propertyName = (1.5.0/docs/api/java/lang/String.html">String)enumE.nextElement();
            if (propertyName.startsWith(propertyPrefix)) {
                props.add(getProperty(propertyName));
            }
         }
         1.5.0/docs/api/java/util/Collections.html">Collections.sort(props,StringComparator.getInstance());
         return props;
     }

}