GME  13
DOMXPathResultImpl.cpp
Go to the documentation of this file.
00001 /*
00002  * Licensed to the Apache Software Foundation (ASF) under one or more
00003  * contributor license agreements.  See the NOTICE file distributed with
00004  * this work for additional information regarding copyright ownership.
00005  * The ASF licenses this file to You under the Apache License, Version 2.0
00006  * (the "License"); you may not use this file except in compliance with
00007  * the License.  You may obtain a copy of the License at
00008  *
00009  *      http://www.apache.org/licenses/LICENSE-2.0
00010  *
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "DOMXPathResultImpl.hpp"
00019 #include <xercesc/dom/DOMNode.hpp>
00020 #include <xercesc/dom/DOMXPathException.hpp>
00021 
00022 XERCES_CPP_NAMESPACE_BEGIN
00023 
00024 DOMXPathResultImpl::DOMXPathResultImpl(ResultType type,
00025                                        MemoryManager* const manager)
00026     : fType(type),
00027       fMemoryManager(manager),
00028       fIndex (0)
00029 {
00030     fSnapshot = new (fMemoryManager) RefVectorOf<DOMNode>(13, false, fMemoryManager);
00031 }
00032 
00033 DOMXPathResultImpl::~DOMXPathResultImpl()
00034 {
00035     delete fSnapshot;
00036 }
00037 
00038 //
00039 //
00040 DOMXPathResult::ResultType DOMXPathResultImpl::getResultType() const
00041 {
00042     return fType;
00043 }
00044 
00045 const DOMTypeInfo* DOMXPathResultImpl::getTypeInfo() const
00046 {
00047     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00048 }
00049 
00050 bool DOMXPathResultImpl::isNode() const
00051 {
00052     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00053 }
00054 
00055 bool DOMXPathResultImpl::getBooleanValue() const
00056 {
00057     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00058 }
00059 
00060 int DOMXPathResultImpl::getIntegerValue() const
00061 {
00062     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00063 }
00064 
00065 double DOMXPathResultImpl::getNumberValue() const
00066 {
00067     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00068 }
00069 
00070 const XMLCh* DOMXPathResultImpl::getStringValue() const
00071 {
00072     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00073 }
00074 
00075 DOMNode* DOMXPathResultImpl::getNodeValue() const
00076 {
00077   if(fType == ANY_UNORDERED_NODE_TYPE || fType == FIRST_ORDERED_NODE_TYPE)
00078   {
00079     return fSnapshot->size() > 0 ? fSnapshot->elementAt(0) : 0;
00080   }
00081   else if (fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
00082   {
00083     return fIndex < fSnapshot->size() ? fSnapshot->elementAt(fIndex) : 0;
00084   }
00085   else
00086     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00087 }
00088 
00089 bool DOMXPathResultImpl::iterateNext()
00090 {
00091     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00092 }
00093 
00094 bool DOMXPathResultImpl::getInvalidIteratorState() const
00095 {
00096     throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00097 }
00098 
00099 bool DOMXPathResultImpl::snapshotItem(XMLSize_t index)
00100 {
00101     if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
00102     {
00103         fIndex = index;
00104         return fIndex < fSnapshot->size();
00105     }
00106     else
00107       throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00108 }
00109 
00110 XMLSize_t DOMXPathResultImpl::getSnapshotLength() const
00111 {
00112     if(fType==UNORDERED_NODE_SNAPSHOT_TYPE || fType==ORDERED_NODE_SNAPSHOT_TYPE)
00113         return fSnapshot->size();
00114     else
00115         throw DOMXPathException(DOMXPathException::TYPE_ERR, 0, fMemoryManager);
00116 }
00117 
00118 void DOMXPathResultImpl::release()
00119 {
00120     DOMXPathResultImpl* me = this;
00121     delete me;
00122 }
00123 
00124 //
00125 //
00126 void DOMXPathResultImpl::reset(ResultType type)
00127 {
00128     fType = type;
00129     fSnapshot->removeAllElements();
00130     fIndex = 0;
00131 }
00132 
00133 void DOMXPathResultImpl::addResult(DOMNode* node)
00134 {
00135     fSnapshot->addElement(node);
00136 }
00137 
00138 XERCES_CPP_NAMESPACE_END