Clover coverage report - Common - 1.0.0
Coverage timestamp: sam. déc. 27 2003 15:13:46 CET
file stats: LOC: 170   Methods: 8
NCLOC: 90   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
ProfileServiceProvider.java 0% 0% 0% 0%
coverage
 1   
 /*
 2   
  * EJTools, the Enterprise Java Tools
 3   
  *
 4   
  * Distributable under LGPL license.
 5   
  * See terms of license at www.gnu.org.
 6   
  */
 7   
 package org.ejtools.util.service;
 8   
 
 9   
 import java.beans.beancontext.BeanContextServices;
 10   
 import java.io.IOException;
 11   
 import java.io.InputStream;
 12   
 import java.util.Arrays;
 13   
 import java.util.Enumeration;
 14   
 import java.util.Iterator;
 15   
 import java.util.Properties;
 16   
 import java.util.Vector;
 17   
 
 18   
 import org.apache.log4j.Logger;
 19   
 import org.ejtools.beans.beancontext.CustomBeanContextServiceProvider;
 20   
 
 21   
 /**
 22   
  * @author    Laurent Etiemble
 23   
  * @version   $Revision: 1.6 $
 24   
  */
 25   
 public class ProfileServiceProvider extends CustomBeanContextServiceProvider implements ProfileService
 26   
 {
 27   
    /** Description of the Field */
 28   
    protected ProfileMetaData metadata = null;
 29   
    /** Description of the Field */
 30   
    protected Profile[] profiles = null;
 31   
    /** Description of the Field */
 32   
    protected ProfileService service = null;
 33   
    /** Description of the Field */
 34   
    private static Logger logger = Logger.getLogger(ProfileServiceProvider.class);
 35   
 
 36   
 
 37   
    /**
 38   
     * Constructor for the FactoryServiceProvider object
 39   
     *
 40   
     * @param metadata  Description of the Parameter
 41   
     */
 42  0
    public ProfileServiceProvider(ProfileMetaData metadata)
 43   
    {
 44  0
       service = this;
 45  0
       this.metadata = metadata;
 46  0
       this.load();
 47   
    }
 48   
 
 49   
 
 50   
    /**
 51   
     * Getter for the currentServiceSelectors attribute
 52   
     *
 53   
     * @param bcs           Description of the Parameter
 54   
     * @param serviceClass  Description of the Parameter
 55   
     * @return              The currentServiceSelectors value
 56   
     */
 57  0
    public Iterator getCurrentServiceSelectors(BeanContextServices bcs, java.lang.Class serviceClass)
 58   
    {
 59  0
       return (new Vector()).iterator();
 60   
    }
 61   
 
 62   
 
 63   
    /**
 64   
     * @param index  Description of the Parameter
 65   
     * @return       The metaData value
 66   
     */
 67  0
    public Profile getProfile(int index)
 68   
    {
 69  0
       Profile profile = this.profiles[index];
 70  0
       return (Profile) profile.clone();
 71   
    }
 72   
 
 73   
 
 74   
    /**
 75   
     * @return   The metaDatas value
 76   
     */
 77  0
    public Profile[] getProfiles()
 78   
    {
 79  0
       return this.profiles;
 80   
    }
 81   
 
 82   
 
 83   
    /**
 84   
     * Getter for the service attribute
 85   
     *
 86   
     * @param bcs              Description of the Parameter
 87   
     * @param requestor        Description of the Parameter
 88   
     * @param serviceClass     Description of the Parameter
 89   
     * @param serviceSelector  Description of the Parameter
 90   
     * @return                 The service value
 91   
     */
 92  0
    public Object getService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Class serviceClass, java.lang.Object serviceSelector)
 93   
    {
 94  0
       return this.service;
 95   
    }
 96   
 
 97   
 
 98   
    /**
 99   
     * Description of the Method
 100   
     *
 101   
     * @param bcs        Description of the Parameter
 102   
     * @param requestor  Description of the Parameter
 103   
     * @param service    Description of the Parameter
 104   
     */
 105  0
    public void releaseService(BeanContextServices bcs, java.lang.Object requestor, java.lang.Object service) { }
 106   
 
 107   
 
 108   
    /**
 109   
     * @return   The serviceClass value
 110   
     */
 111  0
    protected Class[] getServiceClass()
 112   
    {
 113  0
       return new Class[]{ProfileService.class};
 114   
    }
 115   
 
 116   
 
 117   
    /** */
 118  0
    private void load()
 119   
    {
 120  0
       this.profiles = new Profile[0];
 121   
 
 122  0
       try
 123   
       {
 124  0
          String prefix = this.metadata.getPrefix();
 125  0
          InputStream in = ProfileServiceProvider.class.getResourceAsStream(this.metadata.getFileName());
 126  0
          if (in != null)
 127   
          {
 128  0
             Properties props = new Properties();
 129  0
             props.load(in);
 130  0
             in.close();
 131   
 
 132  0
             Vector keys = new Vector();
 133  0
             Enumeration enum = props.keys();
 134  0
             while (enum.hasMoreElements())
 135   
             {
 136  0
                String key = (String) enum.nextElement();
 137  0
                if ((key.startsWith(prefix + ".")) && (key.endsWith(".name")))
 138   
                {
 139  0
                   keys.add(key.substring((prefix + ".").length(), key.indexOf(".name")));
 140   
                }
 141   
             }
 142   
 
 143  0
             this.profiles = new Profile[keys.size()];
 144  0
             String[] orderedKeys = (String[]) keys.toArray(new String[0]);
 145  0
             Arrays.sort(orderedKeys);
 146   
 
 147  0
             for (int i = 0; i < orderedKeys.length; i++)
 148   
             {
 149  0
                String key = orderedKeys[i];
 150  0
                logger.debug("Loading key " + key);
 151   
 
 152  0
                Profile data = new Profile();
 153  0
                data.setName(props.getProperty(prefix + "." + key + ".name"));
 154   
 
 155  0
                for (int j = 0; j < this.metadata.getKeys().length; j++)
 156   
                {
 157  0
                   data.setProperty(this.metadata.getKey(j), props.getProperty(prefix + "." + key + "." + this.metadata.getKey(j), ""));
 158   
                }
 159   
 
 160  0
                this.profiles[i] = data;
 161   
             }
 162   
          }
 163   
       }
 164   
       catch (IOException e)
 165   
       {
 166  0
          logger.error("Error while loading profiles", e);
 167   
       }
 168   
    }
 169   
 }
 170