1 /* 2 * Copyright 2006-2010 The FLWOR Foundation. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 #include "stdafx.h" 17 18 #include <zorba/uri_resolvers.h> 19 #include "uriresolverimpl.h" 20 21 namespace zorba { 22 23 /************* 24 * Implementation of the Resource class hierarchy. 25 *************/ 26 ~Resource()27 Resource::~Resource() 28 {} 29 ~StreamResource()30 StreamResource::~StreamResource() 31 {} 32 ~StreamResourceImpl()33 StreamResourceImpl::~StreamResourceImpl() 34 { 35 if (theStreamReleaser) { 36 theStreamReleaser(theStream); 37 } 38 } 39 destroy() const40 void StreamResourceImpl::destroy() const 41 { 42 delete this; 43 } 44 create(std::istream * aStream,StreamReleaser aStreamReleaser,bool aIsStreamSeekable)45 StreamResource* StreamResource::create(std::istream* aStream, 46 StreamReleaser aStreamReleaser, 47 bool aIsStreamSeekable) 48 { 49 return new StreamResourceImpl(aStream, aStreamReleaser, aIsStreamSeekable); 50 } 51 StreamResourceImpl(std::istream * aStream,StreamReleaser aStreamReleaser,bool aIsStreamSeekable)52 StreamResourceImpl::StreamResourceImpl(std::istream* aStream, 53 StreamReleaser aStreamReleaser, 54 bool aIsStreamSeekable) 55 : theStream(aStream), 56 theStreamReleaser(aStreamReleaser), 57 theIsStreamSeekable(aIsStreamSeekable) 58 { 59 } 60 61 std::istream* getStream()62 StreamResourceImpl::getStream() 63 { 64 return theStream; 65 } 66 67 StreamReleaser getStreamReleaser()68 StreamResourceImpl::getStreamReleaser() 69 { 70 return theStreamReleaser; 71 } 72 73 void setStreamReleaser(StreamReleaser aStreamReleaser)74 StreamResourceImpl::setStreamReleaser(StreamReleaser aStreamReleaser) 75 { 76 theStreamReleaser = aStreamReleaser; 77 } 78 79 /************* 80 * URIMapper is an abstract class, but we have to define its vtbl, 81 * base destructor and default functions somewhere. 82 *************/ 83 URIMapper()84 URIMapper::URIMapper() 85 {} 86 ~URIMapper()87 URIMapper::~URIMapper() 88 {} 89 90 URIMapper::Kind mapperKind()91 URIMapper::mapperKind() 92 { 93 return CANDIDATE; 94 } 95 96 /************* 97 * URIResolver is an abstract class, but we have to define its vtbl 98 * and base destructor somewhere. 99 *************/ 100 URLResolver()101 URLResolver::URLResolver() 102 {} 103 ~URLResolver()104 URLResolver::~URLResolver() 105 {} 106 107 /************* 108 * EntityData is an abstract class, but we have to define its vtbl 109 * and base destructor somewhere. 110 *************/ 111 ~EntityData()112 EntityData::~EntityData() 113 {} 114 115 /************ 116 * Implementation of OneToOneURIMapper. 117 ************/ OneToOneURIMapper(EntityData::Kind aEntityKind,URIMapper::Kind aMapperKind)118 OneToOneURIMapper::OneToOneURIMapper(EntityData::Kind aEntityKind, 119 URIMapper::Kind aMapperKind) 120 : theEntityKind(aEntityKind), 121 theMapperKind(aMapperKind) 122 { 123 } 124 125 void mapURI(const String aURI,EntityData const * aEntityData,std::vector<String> & oUris)126 OneToOneURIMapper::mapURI( 127 const String aURI, 128 EntityData const* aEntityData, 129 std::vector<String>& oUris) 130 { 131 if (aEntityData->getKind() != theEntityKind) { 132 return; 133 } 134 MappingIter_t lIter = theMappings.find(aURI); 135 if (lIter != theMappings.end()) { 136 oUris.push_back(lIter->second); 137 } 138 } 139 140 URIMapper::Kind mapperKind()141 OneToOneURIMapper::mapperKind() 142 { 143 return theMapperKind; 144 } 145 146 void addMapping(const String & aURI,const String & aValue)147 OneToOneURIMapper::addMapping( 148 const String& aURI, const String& aValue) 149 { 150 theMappings[aURI] = aValue; 151 } 152 } /* namespace zorba */ 153 /* vim:set et sw=2 ts=2: */ 154