Clover coverage report -
Coverage timestamp: Sun Nov 1 2009 23:08:24 UTC
file stats: LOC: 217   Methods: 8
NCLOC: 67   Classes: 1
 
 Source file Conditionals Statements Methods TOTAL
DatabaseImpl.java 57.1% 69.6% 87.5% 68.9%
coverage coverage
 1    /*
 2    * Licensed to the Apache Software Foundation (ASF) under one or more
 3    * contributor license agreements. See the NOTICE file distributed with
 4    * this work for additional information regarding copyright ownership.
 5    * The ASF licenses this file to You under the Apache License, Version 2.0
 6    * (the "License"); you may not use this file except in compliance with
 7    * the License. You may obtain a copy of the License at
 8    *
 9    * http://www.apache.org/licenses/LICENSE-2.0
 10    *
 11    * Unless required by applicable law or agreed to in writing, software
 12    * distributed under the License is distributed on an "AS IS" BASIS,
 13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14    * See the License for the specific language governing permissions and
 15    * limitations under the License.
 16    *
 17    * $Id: DatabaseImpl.java 541508 2007-05-25 01:54:12Z vgritsenko $
 18    */
 19   
 20    package org.apache.xindice.client.xmldb;
 21   
 22    import org.apache.commons.logging.Log;
 23    import org.apache.commons.logging.LogFactory;
 24    import org.apache.xindice.core.FaultCodes;
 25   
 26    import org.xmldb.api.base.Collection;
 27    import org.xmldb.api.base.Database;
 28    import org.xmldb.api.base.ErrorCodes;
 29    import org.xmldb.api.base.XMLDBException;
 30   
 31    /**
 32    * DatabaseImpl is the XML:DB driver implementation for Xindice. It is the entry
 33    * point into the Xindice server but is not intended for direct use by users.
 34    * Users access it indirectly through the XML:DB DatabaseManager implementation.
 35    *
 36    * <p>
 37    * This API is an implementation of the XML:DB API. More information on this API
 38    * can be found by looking at
 39    * <a href="http://xmldb-org.sourceforge.net/xapi/index.html">http://xmldb-org.sourceforge.net/xapi/index.html</a>
 40    *
 41    * <p>
 42    * This implementation simply acts as a proxy for the protocol specific API implementations.
 43    *
 44    * @version $Revision: 541508 $, $Date: 2007-05-24 18:54:12 -0700 (Thu, 24 May 2007) $
 45    */
 46    public class DatabaseImpl extends CommonConfigurable implements Database {
 47   
 48    private static final Log log = LogFactory.getLog(DatabaseImpl.class);
 49   
 50    protected Database driver;
 51   
 52    /**
 53    * These are the URI prefixes this proxy impl understands.
 54    *
 55    * XML-RPC is the default.
 56    */
 57    public static final String XMLRPC_URI = "xindice://";
 58    public static final String EMBED_URI = "xindice-embed://";
 59    public static final String MANAGED_URI = "xindice-managed://";
 60   
 61    /**
 62    * Name used in the uri for collections associated with this instance.
 63    */
 64    public static final String INSTANCE_NAME = "xindice, xindice-embed, xindice-managed";
 65   
 66    /**
 67    * Name used in the uri for collections associated with this instance.
 68    */
 69    private static final String[] INSTANCE_NAMES = {"xindice", "xindice-embed", "xindice-managed"};
 70   
 71    /**
 72    * The XML:DB API Core Level Conformance of this implementation.
 73    */
 74    public static final String CONFORMANCE_LEVEL = "0";
 75   
 76   
 77    /**
 78    * Constructor for the DatabaseImpl object
 79    */
 80  8 public DatabaseImpl() {
 81  8 super();
 82    }
 83   
 84    /**
 85    * Returns the prefix used in XML:DB to denote URI's that this driver can
 86    * handle.
 87    *
 88    * @return the prefix driver name
 89    * @exception XMLDBException with expected error codes.<br />
 90    * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
 91    * specific errors that occur.<br />
 92    */
 93  5 public String getName() throws XMLDBException {
 94  5 return INSTANCE_NAME;
 95    }
 96   
 97    /**
 98    * Returns an array of names associated with the Database instance.
 99    *
 100    * @return the array of name of the object.
 101    * @exception XMLDBException with expected error codes.<br />
 102    * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
 103    * specific errors that occur.<br />
 104    */
 105  4 public String[] getNames() throws XMLDBException {
 106  4 return INSTANCE_NAMES;
 107    }
 108   
 109    /**
 110    * Creates a Collection instance using the URI to locate the collection in
 111    * the Xindice instance. Applications should not call this method directly.
 112    * Instead they should call {@link org.xmldb.api.DatabaseManager#getCollection(String, String, String)}.
 113    *
 114    * <p>
 115    * The URI format accepted by this method:
 116    * <code>xindice://[Database Host]/[Database Instance Name]/[Collection Path]</code>
 117    *
 118    * <p>
 119    * Database host is optional.
 120    *
 121    * This usually looks something like this:
 122    * <code>xindice:///db/root/ocs</code> or
 123    * <code>xindice://some.host.com:8309/db/root/ocs</code>
 124    *
 125    * <p>
 126    * When you pass the URI to DatabaseManager.getCollection(uri) you must
 127    * prepend an <code>xmldb:</code> to the beginning to make it a valid XML:DB URI.
 128    * So to normal users of the API URIs will look like this:
 129    * <code>xmldb:xindice:///db/root/ocs</code>. DatabaseManager will strip the
 130    * <code>xmldb:</code> before handing the URI to this getCollection implementation.
 131    *
 132    * @param uri The URI specifing the location of the collection.
 133    * @return The Collection value
 134    * @exception XMLDBException
 135    */
 136  2020 public Collection getCollection(String uri, String username, String password) throws XMLDBException {
 137  2020 createDriver(uri);
 138  2020 return driver.getCollection(uri, username, password);
 139    }
 140   
 141    /**
 142    * Returns the XML:DB API Conformance level for the implementation. This can
 143    * be used by client programs to determine what functionality is available to
 144    * them.
 145    *
 146    * @return the XML:DB API conformance level for this implementation.
 147    * @exception XMLDBException with expected error codes.<br />
 148    * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
 149    * specific errors that occur.<br />
 150    */
 151  0 public String getConformanceLevel() throws XMLDBException {
 152  0 return CONFORMANCE_LEVEL;
 153    }
 154   
 155    /**
 156    * Determines whether this <code>Database</code> implementation can handle
 157    * the URI. It should return true if the Database instance knows how to
 158    * handle the URI and false otherwise. <p />
 159    *
 160    * This method is called by org.xmldb.api.base.DatabaseManager.
 161    *
 162    * @param uri the URI to check for.
 163    * @return true if the URI can be handled, false otherwise.
 164    * @exception XMLDBException with expected error codes.<br />
 165    * <code>ErrorCodes.VENDOR_ERROR</code> for any vendor
 166    * specific errors that occur.<br />
 167    * <code>ErrroCodes.INVALID_URI</code> If the URI is not in a valid format. <br />
 168    * @see #getCollection for a description of the URI's format
 169    */
 170  24 public boolean acceptsURI(String uri) throws XMLDBException {
 171  24 if (uri != null && uri.length() > 0 && knownPrefix(uri)) {
 172    // Ensure the driver is initialised
 173  6 createDriver(uri);
 174  6 return driver.acceptsURI(uri);
 175    }
 176   
 177  18 return false;
 178    }
 179   
 180  2026 protected void createDriver(String uri) throws XMLDBException {
 181    // Determine which driver was requested.
 182  2026 if (driver == null) {
 183  4 if (uri == null) {
 184  0 throw new XMLDBException(ErrorCodes.INVALID_URI,
 185    FaultCodes.URI_NULL,
 186    "The URI is null");
 187    }
 188   
 189  4 if (uri.startsWith(XMLRPC_URI)) {
 190    /*
 191    * The only way that a particular instance of xmlrpc.DatabaseImpl
 192    * can be informed of the path to the XML-RPC service in the
 193    * web server is by setting a property on the DatabaseImpl object
 194    * which is in turn passed to the CollectionImpl object. Whew!
 195    * Since the user never sees the actual xmlrpc.DatabaseImpl object,
 196    * this is the only way to make sure that they can set that property.
 197    */
 198  1 driver = new org.apache.xindice.client.xmldb.xmlrpc.DatabaseImpl(this);
 199  3 } else if (uri.startsWith(EMBED_URI)) {
 200  3 driver = new org.apache.xindice.client.xmldb.embed.DatabaseImpl(this);
 201  0 } else if (uri.startsWith(MANAGED_URI)) {
 202  0 driver = new org.apache.xindice.client.xmldb.managed.DatabaseImpl(this);
 203    } else {
 204  0 if (log.isInfoEnabled()) {
 205  0 log.info("The URI '" + uri + "' is not handled by Xindice");
 206    }
 207  0 throw new XMLDBException(ErrorCodes.INVALID_URI,
 208    FaultCodes.URI,
 209    "The URI '" + uri + "' is not handled by Xindice");
 210    }
 211    }
 212    }
 213   
 214  12 protected boolean knownPrefix(String uri) {
 215  12 return (uri.startsWith(XMLRPC_URI) || (uri.startsWith(EMBED_URI)) || uri.startsWith(MANAGED_URI));
 216    }
 217    }