You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by pr...@apache.org on 2002/10/27 13:22:39 UTC
cvs commit: jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database DriverContentHandler.java DriverMetaData.java DriverMetaDataImpl.java
prickett 2002/10/27 04:22:39
Modified: periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database
DriverContentHandler.java DriverMetaData.java
DriverMetaDataImpl.java
Log:
Removed shortDescription, description, webUrl from DriverContentHandler
and replaced them with a driverMeta variable which is a DriverMetaDataImpl
object.
Changed DriverContentHandler to add driver protocols via a new method on the
DriverMetaDataImpl object. This replaces the addProtocol() method in
DriverContentHandler.
Changed DriverContentHandler to add Drivers to the service via a new
method on the service DriverMetaDataService interface. This replaces the
addDriverToDriverService method
Changed getVelocityContext() to java.util.Map getDriverMap() in
DriverMetaDataImpl
Added the following methods to DriverMetaDataImpl
getShortDescription
getDescription
getWebUrl
getClassName
setDescription
addProtocol
addProtocols
setProtocols
removeProtocols
removeProtocol
removeAllProtocols
getProtocols
getUrlScheme
setDriverMap
Added a couple of routines to build descriptive exception error messages.
Revision Changes Path
1.4 +32 -109 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.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- DriverContentHandler.java 26 Oct 2002 00:29:37 -0000 1.3
+++ DriverContentHandler.java 27 Oct 2002 12:22:39 -0000 1.4
@@ -109,21 +109,9 @@
/** A flag to tell us whether we should process protocols */
private boolean processProtocol = false;
- /** A variable to hold the current jdbc driver's name */
+ /** A variable to hold the name of the current jdbc driver */
private String name = null;
- /** A variable to hold the short description for the current jdbc driver */
- private String shortDescription = null;
-
- /** A variable to hold the description for the current jdbc driver */
- private String description = null;
-
- /** A variable to hold the name of the current jdbc class */
- private String driverClassName = null;
-
- /** A variable to hold the url to the current driver's website */
- private String webUrl = null;
-
/** A variable to hold the url scheme for the current jdbc protocol */
private String scheme = null;
@@ -135,7 +123,7 @@
/** A variable to hold the Meta Data Object to be added to the Driver
Service */
- private DriverMetaData driverMeta = null;
+ private DriverMetaDataImpl driverMeta = null;
/** A buffer to hold the current character information until it
is stored in its respective variable */
@@ -202,7 +190,7 @@
if(lookForDrivers && processProtocol && qName != null &&
qName.equals(PROTOCOL_ELEMENT_QNAME))
{
- addProtocol();
+ driverMeta.addProtocol(protocolName, scheme);
processProtocol = false;
}
else if(lookForDrivers && processProtocol && qName != null &&
@@ -213,27 +201,44 @@
else if(lookForDrivers && !processProtocol && qName != null &&
qName.equals(DRIVER_ELEMENT_QNAME))
{
- addDriverToDriverService();
+ DriverMetaDataService service =
+ PeriodicityDrivers.getService();
+ if(service != null && driverMeta != null)
+ {
+ service.addDriver(driverMeta);
+ }
+ else if(service == null)
+ {
+ throw new Exception("service == null");
+ }
+ else if(driverMeta == null)
+ {
+ throw new Exception("driverMeta == null");
+ }
+ else
+ {
+ throw new Exception("UNEXPECTED EXCEPTION");
+ }
}
else if(lookForDrivers && !processProtocol && qName != null &&
qName.equals(SHORT_DESC_QNAME))
{
- shortDescription = buffy.toString();
+ driverMeta.setShortDescription(buffy.toString());
}
else if(lookForDrivers && !processProtocol && qName != null &&
qName.equals(DESCRIPTION_QNAME))
{
- description = buffy.toString();
+ driverMeta.setDescription(buffy.toString());
}
else if(lookForDrivers && !processProtocol && qName != null &&
qName.equals(WEB_URL_QNAME))
{
- webUrl = buffy.toString();
+ driverMeta.setWebUrl(buffy.toString());
}
else if(lookForDrivers && !processProtocol && qName != null &&
qName.equals(DRIVER_CLASS_QNAME))
{
- driverClassName = buffy.toString();
+ driverMeta.setClassName(buffy.toString());
}
else if(!lookForDrivers && processProtocol)
{
@@ -251,6 +256,10 @@
"qName = \"" + qName + "\".");
}
}
+ catch(Exception e)
+ {
+ throw new SAXException(e.getMessage());
+ }
finally
{
buffy = null;
@@ -263,91 +272,5 @@
{
buffy.append(ch, start, length);
}
- }
-
- private void addProtocol() throws SAXException
- {
- if(scheme != null && protocolName != null)
- {
- if(protocols == null)
- {
- protocols = new Hashtable();
- }
- if(!protocols.containsKey(protocolName))
- {
- protocols.put(protocolName, scheme);
- }
- else if(protocols.containsKey(protocolName))
- {
- throw new SAXException(
- "duplicate protocol named, \"" + protocolName + "\".");
- }
- else
- {
- throw new SAXException("UNEXPECTED EXCEPTION");
- }
- }
- else if(scheme != null && protocolName == null)
- {
- protocolName = DEFAULT_PROTOCOL;
- addProtocol();
- }
- else if(scheme == null)
- {
- throw new SAXException("scheme == null");
- }
- else
- {
- throw new SAXException("UNEXPECTED EXCEPTION");
- }
- }
-
- private void addDriverToDriverService() throws SAXException
- {
- try
- {
- if(name != null && driverClassName != null && protocols != null &&
- !protocols.isEmpty())
- {
- DriverMetaDataService driversService =
- PeriodicityDrivers.getService();
- if(driversService != null)
- {
- driversService.addDriver(driverMeta);
- }
- else if(driversService == null)
- {
- throw new SAXException("driversService == null");
- }
- else
- {
- throw new SAXException("UNEXPECTED EXCEPTION");
- }
- }
- else if(name == null)
- {
- throw new SAXException("name == null");
- }
- else if(driverClassName == null)
- {
- throw new SAXException("driverClassName == null");
- }
- else if(protocols == null)
- {
- throw new SAXException("protocols == null");
- }
- else if(protocols.isEmpty())
- {
- throw new SAXException("Driver has no protocols.");
- }
- else
- {
- throw new SAXException("UNEXPECTED EXCEPTION");
- }
- }
- catch(Exception e)
- {
- throw new SAXException(e);
- }
}
}
1.3 +37 -6 jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaData.java
Index: DriverMetaData.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaData.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- DriverMetaData.java 21 Oct 2002 03:57:12 -0000 1.2
+++ DriverMetaData.java 27 Oct 2002 12:22:39 -0000 1.3
@@ -64,7 +64,7 @@
-import org.apache.velocity.context.Context;
+import java.util.Map;
public interface DriverMetaData
{
@@ -74,15 +74,46 @@
* meta data object.
* @return The name of the Driver Meta Data object as a string.
*/
+
public String getName();
/**
* The purpose of this method is to return the properties that are
* associated with this database driver meta data object.
* @return The properties that are associated with this database driver
- * meta data object.
+ * meta data object as a java.util.Map.
*/
- public Context getVelocityContext();
+
+ public Map getDriverMap();
+
+ /**
+ * The purpose of this method is to return the short description of this
+ * jdbc driver.
+ * @return The short description of this jdbc driver.
+ */
+ public String getShortDescription();
+
+ /**
+ * The purpose of this method is to get the description of this jdbc
+ * driver.
+ * @return The description of this jdbc driver.
+ */
+
+ public String getDescription();
+
+ /**
+ * The purpose of this method is to get the web url of this jdbc driver.
+ * @return The web url of the jdbc driver as a string.
+ */
+
+ public String getWebUrl();
+
+ /**
+ * The purpose of this method is to get the class name of this jdbc driver.
+ * @return The class name of this jdbc driver as a string.
+ */
+
+ public String getClassName();
}
1.6 +188 -18 jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataImpl.java
Index: DriverMetaDataImpl.java
===================================================================
RCS file: /home/cvs/jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverMetaDataImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- DriverMetaDataImpl.java 26 Oct 2002 00:29:37 -0000 1.5
+++ DriverMetaDataImpl.java 27 Oct 2002 12:22:39 -0000 1.6
@@ -66,8 +66,8 @@
import java.util.Map;
import java.util.Hashtable;
-import org.apache.velocity.VelocityContext;
-import org.apache.velocity.context.Context;
+import java.util.Set;
+import java.util.Iterator;
public class DriverMetaDataImpl implements DriverMetaData
{
@@ -93,7 +93,7 @@
private Map protocols = null;
/** A variable to store the properties of the driver */
- private Context context = null;
+ private Map driverMap = null;
/**
* The purpose of this method is to create a new driver meta data
@@ -162,6 +162,26 @@
{
shortDescription = newval;
}
+
+ /**
+ * The purpose of this method is to get the description of this jdbc
+ * driver.
+ * @return The description of the jdbc driver as a string.
+ */
+ public String getDescription()
+ {
+ return description;
+ }
+
+ /**
+ * The purpose of this method is to set the description of this jdbc
+ * driver.
+ * @param newval The new value for the description as a string.
+ */
+ public void setDescription(String newval)
+ {
+ description = newval;
+ }
/**
* The purpose of this method is to return the url of the website for this
@@ -218,7 +238,7 @@
* @param newName The name of the new protocol as a string
* @param newScheme The url scheme for the new protocol
*/
- public void addProtocol(String newName, String newScheme) throws Exception
+ void addProtocol(String newName, String newScheme) throws Exception
{
if(newName == null && newScheme != null)
{
@@ -240,8 +260,124 @@
{
throw new Exception("UNEXPECTED EXCEPTION");
}
+ }
+
+ void addProtocols(Map newProtocols) throws Exception
+ {
+ if(newProtocols != null)
+ {
+ Set keys = newProtocols.keySet();
+ if(keys != null)
+ {
+ Iterator iter = keys.iterator();
+ if(iter != null)
+ {
+ while(iter.hasNext())
+ {
+ Object rawName = iter.next();
+ if(rawName != null && rawName instanceof String)
+ {
+ Object rawScheme = newProtocols.get(rawName);
+ if(rawScheme != null &&
+ rawScheme instanceof String)
+ {
+ protocols.put(rawName, rawScheme);
+ }
+ else if(rawScheme == null)
+ {
+ throw new Exception(
+ "The scheme for protocol, \"" +
+ rawName.toString() + "\", was null.");
+ }
+ else if(!(rawScheme instanceof String))
+ {
+ throw new Exception("scheme wrong type");
+ }
+ else
+ {
+ throw new Exception("UNEXPECTED EXCEPTION");
+ }
+ }
+ else if(rawName == null)
+ {
+ throw new Exception(
+ "A protocol name cannot be null.");
+ }
+ else if(!(rawName instanceof String))
+ {
+ throw new Exception(
+ getProtocolNameWrongTypeErrorMessage(
+ rawName));
+ }
+ else
+ {
+ throw new Exception("UNEXPECTED EXCEPTION");
+ }
+ }
+ }
+ }
+ }
}
+ void setProtocols(Map newProtocols) throws Exception
+ {
+ protocols = new Hashtable();
+ addProtocols(newProtocols);
+ }
+
+ void removeProtocol(String protocolName)
+ {
+ if(protocolName != null && protocols.containsKey(protocolName))
+ {
+ protocols.remove(protocolName);
+ }
+ }
+
+ void removeProtocols(Map oldProtocols)
+ {
+ if(oldProtocols != null)
+ {
+ Set keys = oldProtocols.keySet();
+ if(keys != null)
+ {
+ Iterator iter = keys.iterator();
+ if(iter != null)
+ {
+ while(iter.hasNext())
+ {
+ Object aKey = iter.next();
+ if(aKey != null && aKey instanceof String)
+ {
+ removeProtocol((String) aKey);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ void removeAllProtocols()
+ {
+ protocols = null;
+ }
+
+ Map getProtocols()
+ {
+ return protocols;
+ }
+
+ String getUrlScheme(String protocolName)
+ {
+ if(protocols != null && protocolName != null &&
+ protocols.containsKey(protocolName))
+ {
+ return (String) protocols.get(protocolName);
+ }
+ else
+ {
+ return null;
+ }
+ }
/**
* The purpose of this method is to return the properties that are
@@ -249,9 +385,13 @@
* @return The properties that are associated with this database driver
* meta data object.
*/
- public Context getVelocityContext()
+ public Map getDriverMap()
{
- return context;
+ if(driverMap == null)
+ {
+ setDriverMap();
+ }
+ return driverMap;
}
/**
@@ -260,17 +400,47 @@
* @param newval newval The new value for the properties of this database
* object.
*/
- private void setVelocityContext(Context newval) throws Exception
+ private void setDriverMap()
{
- if(newval != null)
- {
- context = newval;
- }
- else
- {
- throw new Exception("newContext == null");
- }
+ driverMap = new Hashtable();
+ }
+
+ /**
+ * The purpose of this method is to build a descriptive error message
+ * for the case when the scheme in a protocol map is not the right
+ * type.
+ * @param protocolName The name of the protocol for which the error occured
+ * @param scheme The scheme that caused the error.
+ * @return The error
+ private static String getSchemeWrongTypeErrorMessage(String protocolName,
+ Object scheme)
+ {
+ StringBuffer buffy = new StringBuffer();
+ buffy.append("The scheme for protocol, \"");
+ buffy.append(protocolName);
+ buffy.append("\", was not the right type. It was \"");
+ buffy.append(scheme.getClass().getName());
+ buffy.append("\". It should have been java.lang.String.");
+ return buffy.toString();
+ }
+
+ /**
+ * The purpose of this method is to build a descriptive error message
+ * for the case when the protocol name is of the wrong type.
+ * @param protocolName The name of the protocol as an Object.
+ */
+ private static String getProtocolNameWrongTypeErrorMessage(
+ Object protocolName)
+ {
+ StringBuffer buffy = new StringBuffer();
+ buffy.append("The protocol name was not the right type.");
+ buffy.append("It was \"");
+ buffy.append(protocolName.getClass().getName());
+ buffy.append("\". It should be java.lang.String.");
+ return buffy.toString();
}
+
+
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>