#ifndef __ORG_XMLDB_API_HPP
#define __ORG_XMLDB_API_HPP
/*
 *  The XML:DB Initiative Software License, Version 1.0
 *
 *
 * Copyright (c) 2000-2001 The XML:DB Initiative.  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
 *        XML:DB Initiative (http://www.xmldb.org/)."
 *    Alternately, this acknowledgment may appear in the software itself,
 *    if and wherever such third-party acknowledgments normally appear.
 *
 * 4. The name "XML:DB Initiative" must not be used to endorse or
 *    promote products derived from this software without prior written
 *    permission. For written permission, please contact info@xmldb.org.
 *
 * 5. Products derived from this software may not be called "XML:DB",
 *    nor may "XML:DB" appear in their name, without prior written
 *    permission of the XML:DB Initiative.
 *
 * 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 XML:DB Initiative. For more information
 * on the XML:DB Initiative, please see <http://www.xmldb.org/>.
 */

// C++ Binding for XML:DB API from Working Draft, Sept. 24, 2001.
// John Merrells, (JCM), Dec 1st 2001.

#include <string>
#include <vector>
 
// Stub SAX ContentHandler to enable IDL to compile, this is not part of the API.
class ContentHandler;
// Stub DOM Node to enable IDL to compile, this is not part of the API.
class DOM_Node; // JCM - Changed from Node

namespace org_xmldb_api
{
	// Forward Declarations
	class Configurable;
	class Resource;
	class Collection;
	class Service;
	class Database;
	class ResourceIterator;
	class ResourceSet;
	class BinaryResource;
	class XMLResource;
	class CollectionManagementService;
	class TransactionService;
	class XPathQueryService;
	class XUpdateQueryService;

	typedef enum ErrorCodes
	{
		// Error Codes are broken into categories      

		// General API Errors
		UNKNOWN_ERROR = 0,
		VENDOR_ERROR = 1,
		NOT_IMPLEMENTED = 2,
		WRONG_CONTENT_TYPE = 3,
		PERMISSION_DENIED = 4,
		INVALID_URI = 5,

		// Service errors
		NO_SUCH_SERVICE = 100,      

		// Collection errors
		NO_SUCH_COLLECTION = 200,
		INVALID_COLLECTION = 201,
		COLLECTION_CLOSED = 202,

		// Resource errors
		NO_SUCH_RESOURCE = 300,
		INVALID_RESOURCE = 301,
		UNKNOWN_RESOURCE_TYPE = 302,

		// Database errors
		NO_SUCH_DATABASE = 400,
		INVALID_DATABASE = 401,
	} ErrorCodes;

	class XMLDBException // JCM - Inherit from a standard base class?
	{
	public:
		std::string message;
		ErrorCodes errorCode;
		long vendorErrorCode;
	};      

	typedef std::vector<Service> ServiceList;
//	typedef std::vector<Collection> CollectionList; // JCM - not used
//	typedef std::vector<std::string> VersionList; // JCM - not used
//	typedef std::vector<Database> DatabaseList; // JCM - not used
	typedef std::vector<std::string> NameList;
	typedef std::string ID;

	class Configurable 
	{
	public:
		virtual std::string getProperty(const std::string &name) const = 0; // raises (XMLDBException);
		virtual void setProperty(const std::string &name, const std::string &value) = 0; // raises (XMLDBException);
	};

	class Resource 
	{
	public:
		virtual Collection &getParentCollection() = 0; // raises (XMLDBException);
		virtual const ID &getId() const = 0; // raises (XMLDBException);
		virtual const char * const getResourceType() const = 0; // raises (XMLDBException);
		// JCM - Well we have no Object. Perhaps (void *) or (void*,size_t) or std::string?!?
		virtual std::string getContent() = 0; // raises (XMLDBException);
		virtual void setContent( const std::string &value ) = 0; // raises (XMLDBException);      
	};

	class Collection : public Configurable
	{  
	public:
		virtual const char * const getName() const = 0; // raises (XMLDBException);

		virtual ServiceList *getServices() = 0; // raises (XMLDBException);
		virtual Service *getService( const std::string &name, const std::string &version ) = 0; // raises (XMLDBException);      

		virtual Collection *getParentCollection() = 0; // raises (XMLDBException);

		virtual long getChildCollectionCount() = 0; // raises (XMLDBException);      
		virtual NameList *listChildCollections() = 0; // raises (XMLDBException);
		virtual Collection *getChildCollection(const std::string &name) = 0; // raises (XMLDBException);

		virtual long getResourceCount() = 0; // raises (XMLDBException);      
		virtual NameList *listResources() = 0; // raises (XMLDBException);
		virtual Resource *createResource( const ID &id, const char * const type ) = 0; // raises (XMLDBException);
		virtual void removeResource( const Resource &res ) = 0; // raises (XMLDBException);
		virtual void storeResource( const Resource &res ) = 0; // raises (XMLDBException);
		virtual Resource *getResource( const ID &id ) = 0; // raises (XMLDBException);

		virtual ID createId() = 0; // raises (XMLDBException);
		virtual bool isOpen() = 0; // raises (XMLDBException);
		virtual void close() = 0; // raises (XMLDBException);
	};

	class Service : public Configurable
	{
	public:
		virtual const char * const getName() const = 0; // raises (XMLDBException);
		virtual const char * const getVersion() const = 0; // raises (XMLDBException);
		virtual void setCollection( const Collection &col ) = 0; // raises (XMLDBException);
	};

	class Database : public Configurable
	{      
	public:
		virtual const char * const getName() const = 0; // raises (XMLDBException);
		virtual Collection *getCollection( const std::string &uri, const std::string &username, const std::string &password ) = 0; // raises (XMLDBException);        
		virtual bool acceptsURI( const std::string &uri ) = 0; // raises (XMLDBException);     
		virtual const char * const getConformanceLevel() const = 0; // raises (XMLDBException);
	};  

	class ResourceIterator
	{
	public:
		virtual bool hasMoreResources() = 0; // raises (XMLDBException);
		virtual Resource &nextResource() = 0; // raises (XMLDBException);
	};

	class ResourceSet
	{      
	public:
		virtual Resource &getResource( long index ) = 0; // raises (XMLDBException);
		virtual void addResource( const Resource &res ) = 0; // raises (XMLDBException);
		virtual void removeResource( long index ) = 0; // raises (XMLDBException);
		virtual ResourceIterator &getIterator() = 0; // raises (XMLDBException);
		virtual Resource *getMembersAsResource() = 0; // raises (XMLDBException);
		virtual long getSize() const = 0; // raises (XMLDBException);      
		virtual void clear() = 0; // raises (XMLDBException);            
	};

	class BinaryResource : public Resource 
	{
	public:
		static const char * const RESOURCE_TYPE; // = "BinaryResource";
		virtual const char * const getResourceType() const { return RESOURCE_TYPE; }
	};

	class XMLResource : public Resource 
	{
	public:
		static const char * const RESOURCE_TYPE; // = "XMLResource";
		virtual const char * const getResourceType() const { return RESOURCE_TYPE; }
		virtual const ID &getDocumentId() const { return getId(); } // raises (XMLDBException);
		virtual DOM_Node *getContentAsDOM() = 0; // raises (base::XMLDBException);
		virtual void setContentAsDOM( const DOM_Node &content) = 0; // raises (base::XMLDBException);
		virtual void getContentAsSAX( const ContentHandler &handler ) = 0; // raises (base::XMLDBException);
		virtual ContentHandler *setContentAsSAX() = 0; // raises (base::XMLDBException);
	};

	class CollectionManagementService : public Service 
	{
	public:
		static const char * const serviceName; // = "XPathQueryService";
		static const char * const version; // = "1.0";

		virtual Collection *createCollection( const std::string &name ) = 0; // raises (base::XMLDBException);
		virtual void removeCollection( const std::string &name ) = 0; // raises (base::XMLDBException);
	};

	class TransactionService : public Service 
	{
	public:
		static const char * const serviceName; // = "TransactionService";
		static const char * const version; // = "1.0";

		virtual void begin() = 0; // raises (base::XMLDBException);
		virtual void commit() = 0; // raises (base::XMLDBException);
		virtual void rollback() = 0; // raises (base::XMLDBException); 
	};

	class XPathQueryService : public Service 
	{
	public:
		static const char * const serviceName; // = "XPathQueryService";
		static const char * const version; // = "1.0";

		virtual void setNamespace( const std::string &prefix, const std::string &uri ) = 0; // raises (base::XMLDBException); 
		virtual std::string getNamespace( const std::string &prefix ) const = 0; // raises (base::XMLDBException); 
		virtual void removeNamespace( const std::string &prefix ) = 0; // raises (base::XMLDBException);
		virtual void clearNamespaces() = 0; // raises (base::XMLDBException);
		virtual ResourceSet *query( const std::string &query ) = 0; // raises (base::XMLDBException);
		virtual ResourceSet *queryResource( const ID &id, const std::string &query ) = 0; // raises (base::XMLDBException);
	};

	class XUpdateQueryService : public Service
	{
	public:
		static const char * const serviceName; // = "XUpdateQueryService";
		static const char * const version; // = "1.0";

		virtual long update(const std::string &commands) = 0; // raises (base::XMLDBException);
		virtual long updateResource(const ID &id, const std::string &commands) = 0; // raises (base::XMLDBException);
	};
}
#endif
