uri_resolvers.h

Go to the documentation of this file.
00001 /*
00002  * Copyright 2006-2008 The FLWOR Foundation.
00003  *
00004  * Licensed under the Apache License, Version 2.0 (the "License");
00005  * you may not use this file except in compliance with the License.
00006  * You may obtain a copy of the License at
00007  * 
00008  * http://www.apache.org/licenses/LICENSE-2.0
00009  *
00010  * Unless required by applicable law or agreed to in writing, software
00011  * distributed under the License is distributed on an "AS IS" BASIS,
00012  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00013  * See the License for the specific language governing permissions and
00014  * limitations under the License.
00015  */
00016 #ifndef ZORBA_URI_RESOLVERS_API_H
00017 #define ZORBA_URI_RESOLVERS_API_H
00018 
00019 #include <istream>
00020 #include <vector>
00021 #include <memory>
00022 
00023 #include <zorba/config.h>
00024 #include <zorba/api_shared_types.h>
00025 #include <zorba/item.h>
00026 #include <zorba/zorbastring.h>
00027 
00028 namespace zorba {
00029 
00030   class URIResolverResult
00031   {
00032     public:
00033       enum ErrorCode
00034       {
00035         UR_NOERROR,
00036         // documents and collections
00037         UR_FODC0002,
00038         UR_FODC0003,
00039         UR_FODC0004,
00040         UR_FODC0005,
00041         // modules
00042         UR_XQST0088,
00043         UR_XQST0046
00044       };
00045 
00046       URIResolverResult()
00047         : theErrorCode(UR_NOERROR) {}
00048 
00049       virtual ~URIResolverResult() {}
00050 
00051       ErrorCode
00052       getError() const { return theErrorCode; }
00053 
00054       void
00055       setError(const ErrorCode& aErrorCode) { theErrorCode = aErrorCode; }
00056 
00057       void
00058       setErrorDescription(const String& aDescription) { theDescription = aDescription; }
00059 
00060       String
00061       getErrorDescription() { return theDescription; }
00062 
00063     protected:
00064       ErrorCode theErrorCode;
00065       String    theDescription;
00066   };
00067 
00068   class DocumentURIResolverResult : public URIResolverResult
00069   {
00070     public:
00071       virtual ~DocumentURIResolverResult() {}
00072 
00073       // TODO make this function throw()
00074       virtual Item
00075       getDocument() const = 0;
00076   };
00077 
00078   class DocumentURIResolver 
00079   {
00080     public:
00081       virtual ~DocumentURIResolver() {}
00082 
00083       virtual std::auto_ptr<DocumentURIResolverResult>
00084       resolve(const Item& aURI,
00085               StaticContext* aStaticContext,
00086               XmlDataManager* aXmlDataManager) = 0;
00087 
00088   };
00089 
00090   class CollectionURIResolverResult : public URIResolverResult
00091   {
00092     public:
00093       virtual ~CollectionURIResolverResult() {}
00094 
00095       virtual Collection_t
00096       getCollection() const = 0;
00097   };
00098 
00099   class CollectionURIResolver
00100   {
00101     public:
00102       virtual ~CollectionURIResolver() {}
00103 
00104       virtual std::auto_ptr<CollectionURIResolverResult>
00105       resolve(const Item& aURI,
00106               StaticContext* aStaticContext,
00107               XmlDataManager* aXmlDataManager) = 0;
00108   };
00109 
00110   class SchemaURIResolverResult : public URIResolverResult 
00111   {
00112     public:
00113       virtual ~SchemaURIResolverResult() {}
00114 
00115       virtual std::istream*
00116       getSchema() const = 0;
00117   };
00118 
00119   class SchemaURIResolver
00120   {
00121     public:
00122       virtual ~SchemaURIResolver() {}
00123       
00124       virtual std::auto_ptr<SchemaURIResolverResult>
00125       resolve(const Item& aURI,
00126               const std::vector<Item>& aLocationHints,
00127               StaticContext* aStaticContext) = 0;
00128   };
00129 
00130   class ModuleURIResolverResult : public URIResolverResult
00131   {
00132     public:
00133       virtual ~ModuleURIResolverResult() {}
00134 
00135       virtual std::istream*
00136       getModule() const = 0;
00137   };
00138 
00139   class ModuleURIResolver
00140   {
00141     public:
00142       virtual ~ModuleURIResolver() {}
00143 
00144       virtual std::auto_ptr<ModuleURIResolverResult>
00145       resolve(const Item& aURI,
00146               StaticContext* aStaticContext) = 0;
00147   };
00148 
00149 } /* namespace zorba */
00150 
00151 #endif