prickett    2002/11/30 10:57:02

  Modified:    
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DatabaseMetaDataImpl.java
                        PeriodicityDriverService.java
  Added:       
periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
                        DbMetaDataService.java
                        PeriodicityDbMetaService.java
  Log:
  Added the following fields to DatabaseMetaDataImpl
  driver, protocol, datbaseHost, databasePort, adminPath, databasePath
  
  Changed the PeriodicityDriverService to implement DriverMetaDataService.
  
  Added a two new classes DbMetaDataService and PeriodicityDbMetaService.
  
  Revision  Changes    Path
  1.6       +143 -4    
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaDataImpl.java
  
  Index: DatabaseMetaDataImpl.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseMetaDataImpl.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- DatabaseMetaDataImpl.java 29 Nov 2002 04:34:01 -0000      1.5
  +++ DatabaseMetaDataImpl.java 30 Nov 2002 18:57:02 -0000      1.6
  @@ -83,6 +83,24 @@
   
       /** A variable to hold the web url of the database */
       private String webUrl = null;
  +
  +    /** A variable to hold the name of the driver */
  +    private String driverName = null;
  +
  +    /** A variable to hold the name of the protocol */
  +    private String protocolName = null;
  +
  +    /** A variable to hold the database host name or IP address */
  +    private String databaseHost;
  +
  +    /** A variable to hold the database port number */
  +    private int databasePort = -1;
  +
  +    /** A variable to hold the administration path */
  +    private String adminPath = null;
  +
  +    /** A variable to hold the database path */
  +    private String databasePath = null;
       
   
       /**
  @@ -255,4 +273,125 @@
       {
           webUrl = newval;
       }    
  -}    
  +
  +    /**
  +     * The purpose of this method is to return the name of the driver we
  +     * are currently using with this database.
  +     * @return The name of the driver as a string.
  +     */
  +    public String getDriver()
  +    {
  +        return driverName;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the name of the driver we are 
  +     * currently using with this database.
  +     * @param newval The name of the driver as a string.
  +     */
  +    void setDriver(String newval)
  +    {
  +        driverName = newval;
  +    }    
  +
  +    /**
  +     * The purpose of this method is to return the protocol of the driver
  +     * we are currently using with this database.
  +     * @return The protocol of this database as a string.
  +     */
  +    public String getProtocol()
  +    {
  +        return protocolName;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the protocol of the driver
  +     * @param newval The new value for the protocol.
  +     */
  +    void setProtocol(String newval)
  +    {
  +        protocolName = newval;
  +    }
  +
  +    /**
  +     * The purpose of this method is to return the database host
  +     * where the database is located.
  +     * @return The database host as a string.
  +     */
  +    public String getDatabaseHost()
  +    {
  +        return databaseHost;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the database host.
  +     * @param newval The new value of the database host as a string.
  +     */
  +    public void setDatabaseHost(String newval)
  +    {
  +        databaseHost = newval;
  +    }    
  +
  +    /**
  +     * The purpose of this method is to return the database port.
  +     * @return The port number where the database is listening -1 for default
  +     */
  +    public int getDatabasePort()
  +    {
  +        return databasePort;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the database port.
  +     * @param newval The new value for the port number as an integer.
  +     */
  +    public void setDatabasePort(int newval) throws Exception
  +    {
  +        if(newval > -2)
  +        {
  +            databasePort = newval;
  +        }
  +        else
  +        {
  +            throw new Exception("Invalid database port number");
  +        }
  +    }
  +
  +    /**
  +     * The purpose of this method is to return the administration path as
  +     * a string.
  +     * @return The administration path as a string.
  +     */
  +    public String getAdminPath()
  +    {
  +        return adminPath;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the adminstration path
  +     * @param newval The new value for the administration path as a string.
  +     */
  +    public void setAdminPath(String newval)
  +    {
  +        adminPath = newval;
  +    }
  +
  +    /**
  +     * The purpose of this method is to return the database path as a string.
  +     * @return The database path as a string.
  +     */
  +    public String getDatabasePath()
  +    {
  +        return databasePath;
  +    }
  +
  +    /**
  +     * The purpose of this method is to set the database path.
  +     * @param newval The new value for the database path as a string.
  +     */
  +    public void setDatabasePath(String newval)
  +    {
  +        databasePath = newval;
  +    }    
  +
  +}
  
  
  
  1.8       +5 -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.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- PeriodicityDriverService.java     29 Nov 2002 03:32:28 -0000      1.7
  +++ PeriodicityDriverService.java     30 Nov 2002 18:57:02 -0000      1.8
  @@ -80,7 +80,8 @@
   import org.apache.commons.configuration.Configuration;
   import org.apache.commons.periodicity.util.JUnitUtils;
   
  -public class PeriodicityDriverService extends BaseService
  +public class PeriodicityDriverService extends BaseService implements
  +       DriverMetaDataService
   {
   
       public static final String SERVICE_NAME = "PeriodicityDriverService";
  
  
  
  1.1                  
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DbMetaDataService.java
  
  Index: DbMetaDataService.java
  ===================================================================
  package org.apache.commons.periodicity.database;
  
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DbMetaDataService.java,v
 1.1 2002/11/30 18:57:02 prickett Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/30 18:57:02 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2000-2002 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  import java.util.Iterator;
  import org.apache.fulcrum.Service;
  
  public interface DbMetaDataService extends Service
  {
      /** The name used by fulcrum for this service */
      public static final String SERVICE_NAME = "DbMetaDataService";
  
      /** The role */
      public static final String ROLE = DbMetaDataService.class.getName();
  
      /**
       * The purpose of this method is to return the database meta data
       * object that corresponds to the database name supplied by the calling
       * procedure.
       * @param databaseType The name of the database that we need meta data
       *        for.
       * @param driverName The name of the driver to use.
       * @param protocolName The name of the protocol to use.
       * @return The database meta data object that corresponds to the database
       */
      public DatabaseMetaData getMetaData(String databaseType, String driverName,
             String protocolName);
             
      /**
       * The purpose of this method is to return the database meta data
       * object that corresponds to the database name supplied by the calling
       * procedure.
       * @param databaseType The name of the database that we need meta data
       *        for.
       * @param driverName The name of the driver to use.
       * @return The database meta data object that corresponds to the database
       */
      public DatabaseMetaData getMetaData(String databaseType, 
             String driverName);
  
      /**
       * The purpose of this method is to return the database meta data
       * object that corresponds to the database name supplied by the calling
       * procedure.
       * @param databaseType The name of the database that we need meta data
       *        for.
       * @return The database meta data object that corresponds to the database
       */
      public DatabaseMetaData getMetaData(String databaseType); 
      
      /**
       * The purpose of this method is to return all the databases in an Iterator
       * @return All the databases supported by this service as an Iterator.
       *         It returns them set to using the default protocols and drivers.
       */
      public Iterator getDatabases(); 
  }
  
  
  
  
  1.1                  
jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDbMetaService.java
  
  Index: PeriodicityDbMetaService.java
  ===================================================================
  
  package org.apache.commons.periodicity.database;
  
  /*
   * $Header: 
/home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/PeriodicityDbMetaService.java,v
 1.1 2002/11/30 18:57:02 prickett Exp $
   * $Revision: 1.1 $
   * $Date: 2002/11/30 18:57:02 $
   *
   * ====================================================================
   * 
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer. 
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution, if
   *    any, must include the following acknowlegement:  
   *       "This product includes software developed by the 
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Commons", and "Apache Software
   *    Foundation" must not be used to endorse or promote products derived
   *    from this software without prior written permission. For written 
   *    permission, please contact [EMAIL PROTECTED]
   *
   * 5. Products derived from this software may not be called "Apache"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation.  For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   *
   */ 
  
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.BufferedInputStream;
  import java.util.Map;
  import java.util.HashMap;
  import java.util.Iterator;
  import java.util.Set;
  import java.util.Collection;
  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;
  import org.apache.commons.configuration.Configuration;
  import org.apache.commons.periodicity.util.JUnitUtils;
  
  public class PeriodicityDbMetaService extends BaseService
  {
  
      public static final String SERVICE_NAME = "PeriodicityDriverService";
      
      public static final String DATABASE_META_DATA_FILE_KEY = 
             "db.meta.data.file";
      
      private Map databases = null;
  
      public PeriodicityDbMetaService()
      {
      }
  
      public void init() throws InitializationException
      {
          if(getConfiguration() != null)
          {
              String databaseFileName = getRealPath(getConfiguration()
                     .getString(DATABASE_META_DATA_FILE_KEY, null));
              if(databaseFileName != null)
              {
                  File dbFile = new File(databaseFileName);
                  if(dbFile.exists() && dbFile.isFile() && dbFile.canRead())
                  {
                      initDatabases(dbFile);
                      setInit(true);
                  }
                  else if(!dbFile.exists())
                  {
                      throw new InitializationException(
                             "Database Meta Data File, \"" +
                             databaseFileName + "\", does not exist.");
                  }
                  else if(!dbFile.isFile())
                  {
                      throw new InitializationException(
                             "Database Meta Data File, \"" +
                             databaseFileName + "\", is not a file.");
                  }
                  else if(!dbFile.canRead())
                  {
                      throw new InitializationException(
                             "Database Meta Data File, \"" +
                             databaseFileName + "\", is not readable.");
                  }
                  else
                  {
                      throw new InitializationException(
                             "UNEXPECTED EXCEPTION");
                  }
              }    
              else if(databaseFileName == null)
              {
                  throw new InitializationException("databaseFileName == null");
              }
              else
              {
                  throw new InitializationException("UNEXPECTED EXCEPTION");
              }    
          }        
          else if(getConfiguration() == null)
          {
              throw new InitializationException("getConfiguration() == null");
          }
          else
          {
              throw new InitializationException("UNEXPECTED EXCEPTION");
          }
      }    
  
      /**
       * The purpose of this method is to add a database to the service.
       * This method will add a database if and only if the service is 
       * uninitialized.
       * @param newDatabase The new database to add to the service.
       */
      private void addDatabase(DatabaseMetaData newDatabase) 
             throws InitializationException
      {
          if(newDatabase != null && newDatabase.getName() != null)
          {
              if(databases == null)
              {
                  databases = new HashMap();
              }
              databases.put(newDatabase.getName(), newDatabase);
          }
          else if(newDatabase == null)
          {
              throw new InitializationException("newDatabase == null");
          }
          else if(newDatabase.getName() == null)
          {
              throw new InitializationException("newDatabase.getName() == null");
          }
          else
          {
              throw new InitializationException("UNEXPECTED EXCEPTION");
          }    
      }
  
      private void addDatabases(Set databases) throws InitializationException
      {
          if(databases != null)
          {
              Iterator iter = databases.iterator();
              if(iter != null)
              {
                  while(iter.hasNext())
                  {
                      Object drvr = iter.next();
                      if(drvr instanceof DatabaseMetaData)
                      {
                          addDatabase((DatabaseMetaData) drvr);
                      }
                      else
                      {
                          throw new InitializationException(
                                 "drvr not a DatabaseMetaData object.");
                      }
                  }    
              }
              else
              {
                  throw new InitializationException("iter == null");
              }
          }
          else
          {
              throw new InitializationException("databases == null");
          }
      }    
  
      private void initDatabases(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);
                          Set databases = dhandler.getDrivers();
                          if(databases != null)
                          {
                              addDatabases(databases);
                          }    
                          else
                          {
                              throw new InitializationException(
                                     "No Drivers Found.");
                          }           
                      }
                      else if(parser == null)
                      {
                          throw new InitializationException("parser == null");
                      }
                      else
                      {
                          throw new InitializationException(
                                 "UNEXPECTED EXCEPTION");
                      }
                  }
                  catch(Exception e)
                  {
                      throw new InitializationException(
                             JUnitUtils.getStackTraceAsString(e));
                  }    
              }
              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 DatabaseMetaData getMetaData(String databaseName)
      {
          if(databases != null)
          {
              return (DatabaseMetaData) databases.get(databaseName);
          }
          else
          {
              return null;
          }
      }
  
      public Iterator getDatabases()
      {
          if(databases != null)
          {
              Collection values = databases.values();
              if(values != null)
              {
                  return values.iterator();
              }
              else
              {
                  return null;
              }
          }
          else
          {
              return null;
          }
      }    
  }    
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to