#include "../config/pathan_config.h" /* * Copyright (c) 2001, DecisionSoft Limited All rights reserved. * Please see LICENSE.TXT for more information. */ #include #include "VarStoreImpl.hpp" #include #include #include #include // defines X() #include VarStoreImpl::VarStoreImpl(XPath2MemoryManager* memMgr) : _store(memMgr) { } VarStoreImpl::~VarStoreImpl() { /* nothing to do */ } void VarStoreImpl::clear() { _store.clear(); } void VarStoreImpl::addLocalScope() { _store.addScope(Scope::LOCAL_SCOPE); } void VarStoreImpl::addLogicalBlockScope() { _store.addScope(Scope::LOGICAL_BLOCK_SCOPE); } void VarStoreImpl::removeScope() { _store.removeScope(); } void VarStoreImpl::setGlobalVar(const XMLCh* ident, const Sequence& value, const StaticContext* context) { _store.setGlobalVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident), value); } void VarStoreImpl::setGlobalVar(const XMLCh* namespaceURI, const XMLCh* name, const Sequence &value, const StaticContext* context) { _store.setGlobalVar(namespaceURI, name, value); } void VarStoreImpl::setVar(const XMLCh* ident, const Sequence &value, const StaticContext* context) { _store.setVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident), value); } void VarStoreImpl::setVar(const XMLCh* namespaceURI, const XMLCh* name, const Sequence &value, const StaticContext* context) { _store.setVar(namespaceURI, name, value); } void VarStoreImpl::declareVar(const XMLCh* ident, const Sequence &value, const StaticContext* context) { _store.declareVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident), value); } void VarStoreImpl::declareVar(const XMLCh* namespaceURI, const XMLCh* name, const Sequence &value, const StaticContext* context) { _store.declareVar(namespaceURI, name, value); } const std::pair VarStoreImpl::getVar(const XMLCh* ident, const StaticContext* context) const { return getVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident), context); } const std::pair VarStoreImpl::getVar(const XMLCh* namespaceURI, const XMLCh* name, const StaticContext* context) const { VariableStore::Entry* result = _store.getVar(namespaceURI, name); if(result) return std::pair(true, result->getValue()); return std::pair(false, Sequence(context->getMemoryManager())); } VariableStore::Entry* VarStoreImpl::getReferenceVar(const XMLCh* ident, const StaticContext* context) const { return _store.getVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident)); } /** Returns a null VarHashEntry if unsuccessful */ VariableStore::Entry* VarStoreImpl::getReferenceVar(const XMLCh* namespaceURI, const XMLCh* name, const StaticContext* context) const { return _store.getVar(namespaceURI, name); } /** Change getGlobalVar to return a null Sequence, rather than a pair with sucess boolean... */ const std::pair VarStoreImpl::getGlobalVar(const XMLCh* ident, const StaticContext* context) const { return getGlobalVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident), context); } const std::pair VarStoreImpl::getGlobalVar(const XMLCh* namespaceURI, const XMLCh* name, const StaticContext* context) const { VariableStore::Entry* result = _store.getGlobalVar(namespaceURI, name); if(result) return std::pair(true, result->getValue()); return std::pair(false, Sequence(context->getMemoryManager())); } void VarStoreImpl::delVar(const XMLCh* ident, const StaticContext* context) { _store.delVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident)); } void VarStoreImpl::delVar( const XMLCh* namespaceURI, const XMLCh* name, const StaticContext* context ) { _store.delVar(namespaceURI, name); } void VarStoreImpl::delGlobalVar(const XMLCh* ident, const StaticContext* context) { _store.delGlobalVar(context->getUriBoundToPrefix(XPath2NSUtils::getPrefix(ident, context->getMemoryManager())), XPath2NSUtils::getLocalName(ident)); } void VarStoreImpl::delGlobalVar( const XMLCh* namespaceURI, const XMLCh* name, const StaticContext* context ) { _store.delGlobalVar(namespaceURI, name); } XMLCh* VarStoreImpl::print(XPath2MemoryManager* memMgr) const { XERCES_CPP_NAMESPACE_QUALIFIER XMLBuffer buf(1023, memMgr); buf.set(X("\n")); const Scope* index=_store.getCurrentScope(); DynamicContext* xp2c = memMgr->createContext(0); while(index) { buf.append(X("getType()) { case Scope::GLOBAL_SCOPE: { buf.append(X("global")); break; } case Scope::LOCAL_SCOPE: { buf.append(X("local")); break; } case Scope::LOGICAL_BLOCK_SCOPE: { buf.append(X("logical_block")); break; } } buf.append(X("\">\n")); std::vector< std::pair > vars = index->getVars(); for(std::vector< std::pair >::iterator it=vars.begin();it!=vars.end();it++) { buf.append(X("first)); buf.append(X("\" name=\"")); buf.append(it->second); buf.append(X("\">")); VarHashEntry* pEntry=const_cast*>(index)->get(it->first,it->second); buf.append(pEntry->getValue().castAsSingleString(xp2c)); buf.append(X("\n")); } buf.append(X("\n")); if(index==_store.getGlobalScope()) break; else { index=const_cast*>(index)->getNext(); if(index==NULL) index=_store.getGlobalScope(); } } buf.append(X("\n")); XMLCh* result = XERCES_CPP_NAMESPACE_QUALIFIER XMLString::replicate(buf.getRawBuffer()); return result; } std::vector< std::pair > VarStoreImpl::getVars() const { std::vector< std::pair > result; // List the local scopes const Scope* index=_store.getCurrentScope(); while(index) { std::vector< std::pair > tmp=index->getVars(); for(std::vector< std::pair >::iterator it=tmp.begin();it!=tmp.end();it++) result.push_back(std::pair(_store.lookUpNamespace(it->first),it->second)); // stop the search when we are going out of scope if(index->getType() == Scope::LOCAL_SCOPE) break; index=const_cast*>(index)->getNext(); } // Check the global scope std::vector< std::pair > tmp=_store.getGlobalScope()->getVars(); for(std::vector< std::pair >::iterator it=tmp.begin();it!=tmp.end();it++) result.push_back(std::pair(_store.lookUpNamespace(it->first),it->second)); return result; }