commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From prick...@apache.org
Subject cvs commit: jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database DriverServiceGetInitTest.java
Date Thu, 28 Nov 2002 22:42:36 GMT
prickett    2002/11/28 14:42:36

  Modified:    periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DriverContentHandler.java
                        DriverMetaDataService.java
                        PeriodicityDriverService.java
               periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database
                        DriverServiceGetInitTest.java
  Log:
  Removed dependency on the DriverMetaDataService in the DriverContentHandler
  because it caused infinite recursion.
  
  Added a role file to the DriverMetaDataService so it would be conformant
  to the new fulcrum paradigm
  
  Added an addDrivers method to the PeriodicityDriverService
  
  Fixed the GetInit Test to correctly initialize the Driver Service
  
  Revision  Changes    Path
  1.6       +16 -17    jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverContentHandler.java
  
  Index: DriverContentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverContentHandler.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DriverContentHandler.java	22 Nov 2002 23:37:26 -0000	1.5
  +++ DriverContentHandler.java	28 Nov 2002 22:42:36 -0000	1.6
  @@ -65,6 +65,8 @@
   
   import java.util.Map;
   import java.util.Hashtable;
  +import java.util.Set;
  +import java.util.HashSet;
   import org.xml.sax.Attributes;
   import org.xml.sax.SAXException;
   import org.xml.sax.helpers.DefaultHandler;
  @@ -127,6 +129,8 @@
           is stored in its respective variable */
       private StringBuffer buffy = null;
   
  +    private Set drivers = null;
  +
   
       public void startElement(String uri, String localName, String qName,
              Attributes attributes) throws SAXException
  @@ -203,23 +207,13 @@
               else if(lookForDrivers && !processProtocol && qName != null
&& 
                      qName.equals(DRIVER_ELEMENT_QNAME))
               {
  -                DriverMetaDataService service = 
  -                       PeriodicityDrivers.getService();
  -                if(service != null && driverMeta != null)
  -                {
  -                    service.addDriver(driverMeta);
  -                }    
  -                else if(service == null)
  +                if(drivers == null)
                   {
  -                    throw new Exception("service == null");
  +                    drivers = new HashSet();
                   }
  -                else if(driverMeta == null)
  -                {
  -                    throw new Exception("driverMeta == null");
  -                }    
  -                else
  +                if(driverMeta != null)
                   {
  -                    throw new Exception("UNEXPECTED EXCEPTION 4");
  +                    drivers.add(driverMeta);
                   }    
               }
               else if(lookForDrivers && !processProtocol && qName != null
&& 
  @@ -270,5 +264,10 @@
           {
               buffy.append(ch, start, length);
           }
  +    }    
  +
  +    public Set getDrivers()
  +    {
  +        return drivers;
       }    
   }    
  
  
  
  1.4       +7 -4      jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataService.java
  
  Index: DriverMetaDataService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataService.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- DriverMetaDataService.java	25 Oct 2002 22:29:34 -0000	1.3
  +++ DriverMetaDataService.java	28 Nov 2002 22:42:36 -0000	1.4
  @@ -68,7 +68,10 @@
   {
   
       /** The name used by fulcrum for this service */
  -    public static final String SERVICE_NAME = "periodicity.drivers";
  +    public static final String SERVICE_NAME = "PeriodicityDriverService";
  +
  +    /** The role */
  +    public static final String ROLE = DriverMetaDataService.class.getName();
   
       
       /**
  
  
  
  1.5       +46 -6     jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDriverService.java
  
  Index: PeriodicityDriverService.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDriverService.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- PeriodicityDriverService.java	22 Nov 2002 23:37:26 -0000	1.4
  +++ PeriodicityDriverService.java	28 Nov 2002 22:42:36 -0000	1.5
  @@ -77,14 +77,20 @@
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.periodicity.util.JUnitUtils;
   
  -class PeriodicityDriverService extends BaseService
  +public class PeriodicityDriverService extends BaseService
   {
   
  +    public static final String SERVICE_NAME = "PeriodicityDriverService";
  +    
       public static final String DATABASE_META_DATA_FILE_KEY = 
  -           "periodicity.db.meta.data.file";
  +           "db.meta.data.file";
       
       private Map drivers = null;
   
  +    public PeriodicityDriverService()
  +    {
  +    }
  +
       public void init() throws InitializationException
       {
           if(getConfiguration() != null)
  @@ -148,7 +154,7 @@
        * uninitialized.
        * @param newDriver The new driver to add to the service.
        */
  -    void addDriver(DriverMetaData newDriver) 
  +    private void addDriver(DriverMetaData newDriver) 
              throws InitializationException
       {
           if(newDriver != null && newDriver.getName() != null && isInitialized())
  @@ -177,6 +183,35 @@
           }    
       }
   
  +    private void addDrivers(Set drivers) throws InitializationException
  +    {
  +        if(drivers != null)
  +        {
  +            Iterator iter = drivers.iterator();
  +            if(iter != null)
  +            {
  +                Object drvr = iter.next();
  +                if(drvr instanceof DriverMetaData)
  +                {
  +                    addDriver((DriverMetaData) drvr);
  +                }
  +                else
  +                {
  +                    throw new InitializationException(
  +                           "drvr not a DriverMetaData object.");
  +                }
  +            }
  +            else
  +            {
  +                throw new InitializationException("iter == null");
  +            }
  +        }
  +        else
  +        {
  +            throw new InitializationException("drivers == null");
  +        }
  +    }    
  +
       private void initDrivers(File dbFile) throws InitializationException
       {
           if(dbFile != null)
  @@ -196,6 +231,11 @@
                           DriverContentHandler dhandler = 
                                  new DriverContentHandler();
                           parser.parse(isource, dhandler);
  +                        Set drivers = dhandler.getDrivers();
  +                        if(drivers != null)
  +                        {
  +                            addDrivers(drivers);
  +                        }    
                       }
                       else if(parser == null)
                       {
  
  
  
  1.5       +23 -15    jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DriverServiceGetInitTest.java
  
  Index: DriverServiceGetInitTest.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/test/org/apache/commons/periodicity/database/DriverServiceGetInitTest.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- DriverServiceGetInitTest.java	22 Nov 2002 23:37:26 -0000	1.4
  +++ DriverServiceGetInitTest.java	28 Nov 2002 22:42:36 -0000	1.5
  @@ -68,10 +68,12 @@
   import org.apache.commons.configuration.BaseConfiguration;
   import org.apache.fulcrum.TurbineServices;
   import org.apache.fulcrum.ServiceManager;
  +import org.apache.fulcrum.BaseServiceBroker;
  +import org.apache.commons.periodicity.junit.TestWithMavenLogging;
   import org.apache.commons.periodicity.util.JUnitUtils;
   
   
  -public class DriverServiceGetInitTest extends TestCase
  +public class DriverServiceGetInitTest extends TestWithMavenLogging
   {
   
       public static final String TEST_NAME = 
  @@ -105,18 +107,26 @@
                   turbineConfig.addProperty(
                          PERIODICITY_DRIVER_SERVICE_CLASS_NAME_KEY,
                          PERIODICITY_DRIVER_SERVICE_CLASS_NAME);
  +                turbineConfig.addProperty(
  +                       BaseServiceBroker.SERVICE_PREFIX +
  +                       PeriodicityDriverService.SERVICE_NAME + "." +
  +                       PeriodicityDriverService.DATABASE_META_DATA_FILE_KEY,
  +                       FILE_NAME);
                   turbineServices.setConfiguration(turbineConfig);       
  +                turbineServices.setApplicationRoot(".");
                   turbineServices.init();
  -                turbineServices.initService(
  -                       PERIODICITY_DRIVER_SERVICE_NAME);
                   BaseConfiguration config = new BaseConfiguration();
  -                config.addProperty(
  -                       PeriodicityDriverService.DATABASE_META_DATA_FILE_KEY,
  -                       FILE_NAME);
  -                TestDriverService driverService = new TestDriverService(
  -                       DriverMetaDataService.SERVICE_NAME,
  -                       config);
  -                driverService.init();
  +                if(getLogger() != null)
  +                {
  +                    getLogger().info("Getting Driver Service");
  +                }    
  +                PeriodicityDriverService driverService = 
  +                       (PeriodicityDriverService) turbineServices.getService(
  +                       PERIODICITY_DRIVER_SERVICE_NAME);
  +                if(getLogger() != null)
  +                {
  +                    getLogger().info("Got driver service");
  +                }    
                   assertTrue("Service should have been initialized.", 
                          driverService.isInitialized());
               }
  @@ -136,5 +146,3 @@
           return new DriverServiceGetInitTest(TEST_NAME);
       }
   }    
  -
  -
  
  
  

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


Mime
View raw message