kward 2002/12/20 22:27:53
Added: java/scratchpad/src/org/apache/xindice/client/xmldb
DatabaseImpl.java
Log:
adding secure XML:DB driver (SSL)
Revision Changes Path
1.1
xml-xindice/java/scratchpad/src/org/apache/xindice/client/xmldb/DatabaseImpl.java
Index: DatabaseImpl.java
===================================================================
package org.apache.xindice.client.xmldb;
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 1999 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 acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Xindice" 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 name, without prior written
* permission of the Apache Software Foundation.
*
* 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 and was
* originally based on software copyright (c) 1999-2001, The dbXML
* Group, L.L.C., http://www.dbxmlgroup.com. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* $Id: DatabaseImpl.java,v 1.1 2002/12/21 06:27:53 kward Exp $
*/
import org.xmldb.api.base.Database;
import org.xmldb.api.base.ErrorCodes;
import org.xmldb.api.base.XMLDBException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
/**
* DatabaseImpl is the XML:DB driver implementation for Xindice. It is the
entry
* point into the Xindice server but is not intended for direct use by users.
* Users access it indirectly through the XML:DB DatabaseManager
implementation.
*
*
* This API is an implementation of the XML:DB API. More information on this
API
* can be found by looking at
* <a
href="http://www.xmldb.org/xapi/index.html">http://www.xmldb.org/xapi/index.html</a>
* <p />
*
* This implementation simply acts as a proxy for the protocol specific API
implementations.
*/
public class DatabaseImpl extends CommonConfigurable
implements Database {
private static Log log =
LogFactory.getLog("org.apache.xindice.client.xmldb");
protected Database driver;
/**
* These are the URI prefixes this proxy impl understands.
*
* XML-RPC is the default.
*/
public static String XMLRPC_URI = "xindice://";
public static String XMLRPCSSL_URI = "xindice-ssl://";
public static String EMBED_URI = "xindice-embed://";
/**
* Name used in the uri for collections associated with this instance.
*/
public static String INSTANCE_NAME = "xindice, xindice-ssl, xindice-embed";
/**
* The XML:DB API Core Level Conformance of this implementation.
*/
public static String CONFORMANCE_LEVEL = "0";
/**
* Constructor for the DatabaseImpl object
*/
public DatabaseImpl() {
super();
}
/**
* Returns the prefix used in XML:DB to denote URI's that this driver can
* handle.
*
* @return the prefix driver name
* @exception XMLDBException with expected error codes.<br />
* <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
* specific errors that occur.<br />
*/
public String getName() throws XMLDBException {
return INSTANCE_NAME;
}
/**
* Creates a Collection instance using the URI to locate the collection in
* the Xindice instance. Applications should not call this method directly.
* Instead they should call
org.xmldb.api.base.DatabaseManager.getCollection().
* <p />
* The URI format accepted by this method:
* xindice:/[Nameservice host]//[Database Instance Name in the CORBA Name
Service]/[collection path]
* <p />
* Nameservice host is optional.
*
* This usually looks something like this:
* xindice:///db/root/ocs. or
* xindice://some.host.com:8309/db/root/ocs
* <p />
* When you pass the URI to DatabaseManager.getCollection(uri) you must
* prepend an xmldb: to the beginning to make it a valid XML:DB URI.
* So to normal users of the API URIs will look like this:
* xmldb:xindice:///db/root/ocs. DatabaseManager will strip the
* xmldb: before handing the URI to this getCollection implementation.
* <p />
* @param uri The URI specifing the location of the collection.
* @return The Collection value
* @exception XMLDBException
*/
public org.xmldb.api.base.Collection getCollection(String uri,
String username, String password) throws XMLDBException {
createDriver(uri);
return driver.getCollection(uri, username, password);
}
/**
* Returns the XML:DB API Conformance level for the implementation. This
can
* be used by client programs to determine what functionality is available
to
* them.
*
* @return the XML:DB API conformance level for this implementation.
* @exception XMLDBException with expected error codes.<br />
* <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
* specific errors that occur.<br />
*/
public String getConformanceLevel() throws XMLDBException {
return CONFORMANCE_LEVEL;
}
/**
* Determines whether this <code>Database</code> implementation can handle
* the URI. It should return true if the Database instance knows how to
* handle the URI and false otherwise. <p />
*
* This method is called by org.xmldb.api.base.DatabaseManager.
*
* @param uri the URI to check for.
* @return true if the URI can be handled, false otherwise.
* @exception XMLDBException with expected error codes.<br />
* <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
* specific errors that occur.<br />
* <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid
format. <br />
* @see #getCollection for a description of the URI's format
*/
public boolean acceptsURI(String uri) throws XMLDBException {
if ( uri == null || uri.equals("") ) {
return false;
}
createDriver(uri);
if ( driver == null ) {
return false;
} else {
return driver.acceptsURI(uri);
}
}
protected void createDriver(String uri) throws XMLDBException {
// Determine which driver was requested.
try {
if ( driver == null ) {
if (uri.startsWith(XMLRPC_URI)) {
driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl").newInstance();
}
if (uri.startsWith(XMLRPCSSL_URI)) {
driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.xmlrpcssl.DatabaseImpl").newInstance();
}
else if (uri.startsWith(EMBED_URI)) {
driver = (Database)
Class.forName("org.apache.xindice.client.xmldb.embed.DatabaseImpl").newInstance();
}
}
}
catch (Exception e) {
if (log.isInfoEnabled()) {
log.info("Exception during creation of the Database", e);
}
throw new XMLDBException(ErrorCodes.INVALID_URI, uri, e);
}
}
}