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/java/org/apache/commons/periodicity/database PeriodicityDriverService.java
Date Fri, 22 Nov 2002 16:23:21 GMT
prickett    2002/11/22 08:23:21

  Modified:    periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        PeriodicityDriverService.java
  Log:
  Added implementations of the addDriver method and the initDrivers method in
  PeriodicityDriverService.java
  
  Revision  Changes    Path
  1.3       +88 -4     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.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- PeriodicityDriverService.java	25 Oct 2002 22:29:34 -0000	1.2
  +++ PeriodicityDriverService.java	22 Nov 2002 16:23:21 -0000	1.3
  @@ -64,6 +64,13 @@
   
   
   import java.io.File;
  +import java.io.FileInputStream;
  +import java.io.BufferedInputStream;
  +import java.util.Map;
  +import java.util.HashMap;
  +import javax.xml.parsers.SAXParserFactory;
  +import javax.xml.parsers.SAXParser;
  +import org.xml.sax.InputSource;
   import org.apache.velocity.VelocityContext;
   import org.apache.fulcrum.BaseService;
   import org.apache.fulcrum.InitializationException;
  @@ -74,6 +81,8 @@
   
       public static final String DATABASE_META_DATA_FILE_KEY = 
              "periodicity.db.meta.data.file";
  +    
  +    private Map drivers = null;
   
       public void init() throws InitializationException
       {
  @@ -138,12 +147,87 @@
        * uninitialized.
        * @param newDriver The new driver to add to the service.
        */
  -    void addDriver(DriverMetaData newDriver)
  +    void addDriver(DriverMetaData newDriver) 
  +           throws InitializationException
       {
  +        if(newDriver != null && newDriver.getName() != null && isInitialized())
  +        {
  +            if(drivers == null)
  +            {
  +                drivers = new HashMap();
  +            }
  +            drivers.put(newDriver.getName(), newDriver);
  +        }
  +        else if(newDriver == null)
  +        {
  +            throw new InitializationException("newDriver == null");
  +        }
  +        else if(newDriver.getName() == null)
  +        {
  +            throw new InitializationException("newDriver.getName() == null");
  +        }
  +        else if(!isInitialized())
  +        {
  +            throw new InitializationException("Service already initialized.");
  +        }
  +        else
  +        {
  +            throw new InitializationException("UNEXPECTED EXCEPTION");
  +        }    
       }
   
       private void initDrivers(File dbFile) throws InitializationException
       {
  +        if(dbFile != null)
  +        {
  +            SAXParserFactory factory = SAXParserFactory.newInstance();
  +            if(factory != null)
  +            {
  +                try
  +                {
  +                    SAXParser parser = factory.newSAXParser();
  +                    if(parser != null)
  +                    {
  +                        FileInputStream fin = new FileInputStream(
  +                        dbFile.getAbsolutePath());
  +                        BufferedInputStream fbin = new BufferedInputStream(fin);
  +                        InputSource isource = new InputSource(fbin);
  +                        DriverContentHandler dhandler = 
  +                               new DriverContentHandler();
  +                        parser.parse(isource, dhandler);
  +                    }
  +                    else if(parser == null)
  +                    {
  +                        throw new InitializationException("parser == null");
  +                    }
  +                    else
  +                    {
  +                        throw new InitializationException(
  +                               "UNEXPECTED EXCEPTION");
  +                    }
  +                }
  +                catch(Exception e)
  +                {
  +                    throw new InitializationException(e.toString());
  +                }    
  +            }
  +            else if(factory == null)
  +            {
  +                throw new InitializationException("factory == null");
  +            }
  +            else
  +            {
  +                throw new InitializationException("UNEXPECTED EXCEPTION");
  +            }
  +        }
  +        else if(dbFile == null)
  +        {
  +            throw new InitializationException("dbFile == null");
  +        }
  +        else
  +        {
  +            throw new InitializationException("UNEXPECTED EXCEPTION");
  +        }    
       } 
   
       public DriverMetaData getMetaData(String driverName) throws Exception
  
  
  

--
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