prickett 2002/11/29 08:53:29 Added: periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database DatabaseContentHandler.java DriverProtocol.java Log: Added a first cut of the Database Content Handler java file Added a first cut of the Driver Protocol java file Revision Changes Path 1.1 jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DatabaseContentHandler.java Index: DatabaseContentHandler.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/DatabaseContentHandler.java,v 1.1 2002/11/29 16:53:28 prickett Exp $ * $Revision: 1.1 $ * $Date: 2002/11/29 16:53:28 $ * * ==================================================================== * * 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.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; import org.apache.log4j.Logger; import org.apache.log4j.LogManager; import org.apache.commons.periodicity.util.JUnitUtils; public class DatabaseContentHandler extends DefaultHandler { /** The qualified name of the databases element */ public static final String DATABASES_ELEMENT_QNAME = "databases"; /** The qualified name of the driver element */ public static final String DATABASE_ELEMENT_QNAME = "database"; /** The qualified name of the short description element */ public static final String SHORT_DESC_QNAME = "short-description"; /** The qualified name of the description element */ public static final String DESCRIPTION_QNAME = "description"; /** The qualified name of the web url element */ public static final String WEB_URL_QNAME = "web-url"; /** The qualified name of the name attribute for databases and protocols */ public static final String NAME_QNAME_ATTRIBUTE = "name"; /** The qualified name of the administration path element */ public static final String ADMIN_PATH_QNAME = "admin-path"; /** A flag to tell us whether we should be looking to add new databases */ private boolean lookForDatabases = false; /** A variable to hold the short description */ private String shortDescription = null; /** A variable to hold the description */ private String description = null; /** A variable to hold the web url */ private String webUrl = null; /** A variable to hold the administration path */ private String adminPath = null; /** A buffer to hold the current character information until it is stored in its respective variable */ private StringBuffer buffy = null; private Set databases = null; private String dbtype = null; private static Logger logger = null; public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { if(!lookForDatabases && qName != null && qName.equals(DATABASES_ELEMENT_QNAME)) { lookForDatabases = true; if(getLogger() != null) { getLogger().debug("Looking for databases..."); } } else if(lookForDatabases && qName != null && qName.equals(DATABASE_ELEMENT_QNAME)) { if(attributes != null) { dbtype = attributes.getValue(NAME_QNAME_ATTRIBUTE); if(dbtype == null) { throw new SAXException( "The name attribute in the database element is null."); } else { throw new SAXException("UNEXPECTED EXCEPTION 1"); } } else if(attributes == null) { throw new SAXException( "The attributes of the driver element are null."); } else { throw new SAXException("UNEXPECTED EXCEPTION 2"); } } else if(lookForDatabases && qName != null) { buffy = new StringBuffer(); } else if(qName == null) { throw new SAXException("qName == null"); } } public void endElement(String uri, String localName, String qName) throws SAXException { try { if(lookForDatabases && qName != null && qName.equals(DATABASE_ELEMENT_QNAME)) { if(databases == null) { databases = new HashSet(); } } else if(lookForDatabases && qName != null && qName.equals(SHORT_DESC_QNAME)) { shortDescription = buffy.toString(); } else if(lookForDatabases && qName != null && qName.equals(DESCRIPTION_QNAME)) { description = buffy.toString(); } else if(lookForDatabases && qName != null && qName.equals(WEB_URL_QNAME)) { webUrl = buffy.toString(); } else if(lookForDatabases && qName != null && qName.equals(ADMIN_PATH_QNAME)) { adminPath = buffy.toString(); } else if(qName == null) { throw new SAXException("qName == null"); } } catch(Exception e) { throw new SAXException( JUnitUtils.getStackTraceAsString(e)); } finally { buffy = null; } } public void characters(char[] ch, int start, int length) { if(buffy != null) { buffy.append(ch, start, length); } } public Set getDatabases() { return databases; } private Logger getLogger() { if(logger == null) { logger = LogManager.getRootLogger(); } return logger; } } 1.1 jakarta-commons-sandbox/periodicity/src/plugins-build/database/src/java/org/apache/commons/periodicity/database/DriverProtocol.java Index: DriverProtocol.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/DriverProtocol.java,v 1.1 2002/11/29 16:53:28 prickett Exp $ * $Revision: 1.1 $ * $Date: 2002/11/29 16:53:28 $ * * ==================================================================== * * 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/>. * */ public class DriverProtocol extends Object { /** A variable to hold the name of the protocol */ private String name = null; /** A variable to hold the scheme of the protocol */ private String scheme = null; /** A variable to hold the url of the protocol */ private String url = null; /** A variable to hold the administration url of the protocol */ private String adminUrl = null; /** * The purpose of this method is to create a new Driver Protocol. * @param newName The name of the new driver protocol. * @param newScheme The scheme of the new driver protocol. * @param newUrl The url of the new driver protocol. */ DriverProtocol(String newName, String newScheme) throws Exception { if(newName != null && newScheme != null) { setName(newName); setScheme(newScheme); } else if(newName == null) { throw new Exception("newName == null"); } else if(newScheme == null) { throw new Exception("newScheme == null"); } else { throw new Exception("UNEXPECTED EXCEPTION"); } } /** * The purpose of this method is to return the name of this protocol. * @return The name of the protocol as a string. */ public String getName() { return name; } /** * The purpose of this method is to set the name of the protocol. * @param newval The new value for the name as a string. */ private void setName(String newval) throws Exception { if(newval != null) { name = newval; } else { throw new Exception("newval == null"); } } /** * The purpose of this method is to return the scheme of this protocol. * @return The scheme of the protocol a string. */ public String getScheme() { return scheme; } /** * The purpose of this method is to set the scheme of this protocol. * @param newval The new value for the scheme as a string. */ private void setScheme(String newval) throws Exception { if(newval != null) { scheme = newval; } else { throw new Exception("newval == null"); } } /** * The purpose of this method is to return the url of this protocol. * @return The url of the protocol as a string. */ public String getUrl() { return url; } /** * The purpose of this method is to set the url of this protocol. * @param newval The new value for the url as a string. */ void setUrl(String newval) { url = newval; } /** * The purpose of this method is to get the administration url of this * protocol. * @return The administration url as a string. */ public String getAdminUrl() { return adminUrl; } /** * The purpose of this method is to set the administration url of this * protocol. * @param newval The new value for the administration url as a string. */ void setAdminUrl(String newval) { adminUrl = newval; } }
-- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>