Back to index

nordugrid-arc-nox  1.1.0~rc6
Public Member Functions | Protected Member Functions | Protected Attributes | Private Attributes
ARex::OptimizedInformationContainer Class Reference

#include <arex.h>

Inheritance diagram for ARex::OptimizedInformationContainer:
Inheritance graph
[legend]
Collaboration diagram for ARex::OptimizedInformationContainer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 OptimizedInformationContainer (void)
 ~OptimizedInformationContainer (void)
int OpenDocument (void)
Arc::MessagePayloadProcess (Arc::SOAPEnvelope &in)
void AssignFile (const std::string &filename)
void Assign (const std::string &xml)
XMLNode Acquire (void)
 Get a lock on contained XML document.
void Release (void)
void Assign (XMLNode doc, bool copy=false)
 Replaces internal XML document with .
SOAPEnvelope * Process (SOAPEnvelope &in)
SOAPEnvelope * Process (SOAPEnvelope &in, const InfoFilter &filter, const InfoFilterPolicies &policies=InfoFilterPolicies(), const NS &ns=NS())

Protected Member Functions

virtual void Get (const std::list< std::string > &path, XMLNodeContainer &result)
 This method is called by this object's Process method.
virtual void Get (XMLNode xpath, XMLNodeContainer &result)

Protected Attributes

Glib::Mutex lock_
 Mutex used to protect access to Get methods in multi-threaded env.
bool to_lock_

Private Attributes

std::string filename_
int handle_
Arc::XMLNode doc_
 Either link or container of XML document.
Glib::Mutex olock_

Detailed Description

Definition at line 34 of file arex.h.


Constructor & Destructor Documentation

Definition at line 230 of file information_collector.cpp.

                                                                 {
  handle_=-1;
}

Definition at line 234 of file information_collector.cpp.

                                                                  {
  if(handle_ != -1) ::close(handle_);
  if(!filename_.empty()) ::unlink(filename_.c_str());
}

Member Function Documentation

XMLNode Arc::InformationContainer::Acquire ( void  ) [inherited]

Get a lock on contained XML document.

To be used in multi-threaded environment. Do not forget to release it with Release()

Definition at line 164 of file InformationInterface.cpp.

                                          {
  lock_.lock();
  return doc_;
}

Here is the caller graph for this function:

void ARex::OptimizedInformationContainer::Assign ( const std::string &  xml)

Definition at line 293 of file information_collector.cpp.

                                                               {
  std::string filename;
  int h = Glib::file_open_tmp(filename);
  if(h == -1) {
    Arc::Logger::getRootLogger().msg(Arc::ERROR,"OptimizedInformationContainer failed to create temporary file");
    return;
  };
  Arc::Logger::getRootLogger().msg(Arc::VERBOSE,"OptimizedInformationContainer created temporary file: %s",filename);
  for(std::string::size_type p = 0;p<xml.length();++p) {
    ssize_t l = ::write(h,xml.c_str()+p,xml.length()-p);
    if(l == -1) {
      ::unlink(filename.c_str());
      ::close(h);
      Arc::Logger::getRootLogger().msg(Arc::ERROR,"OptimizedInformationContainer failed to store XML document to temporary file");
      return;
    };
    p+=l;
  };
  Arc::XMLNode newxml(xml);
  if(!newxml) {
    ::unlink(filename.c_str());
    ::close(h);
    Arc::Logger::getRootLogger().msg(Arc::ERROR,"OptimizedInformationContainer failed to parse XML");
    return;
  };
  // Here we have XML stored in file and parsed
  olock_.lock();
  if(!filename_.empty()) ::unlink(filename_.c_str());
  if(handle_ != -1) ::close(handle_);
  filename_ = filename;
  handle_ = h;
  lock_.lock();
  doc_.Swap(newxml);
  lock_.unlock();
  Arc::InformationContainer::Assign(doc_,false);
  olock_.unlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::InformationContainer::Assign ( XMLNode  doc,
bool  copy = false 
) [inherited]

Replaces internal XML document with .

If is true this method makes a copy of for internal use.

Definition at line 173 of file InformationInterface.cpp.

                                                       {
  lock_.lock();
  if(copy) {
    doc.New(doc_);
  } else {
    doc_=doc;
  };
  lock_.unlock();
}

Here is the call graph for this function:

Here is the caller graph for this function:

void ARex::OptimizedInformationContainer::AssignFile ( const std::string &  filename)

Definition at line 277 of file information_collector.cpp.

                                                                        {
  olock_.lock();
  if(!filename_.empty()) ::unlink(filename_.c_str());
  if(handle_ != -1) ::close(handle_);
  filename_ = filename;
  handle_ = -1;
  if(!filename_.empty()) {
    handle_ = ::open(filename_.c_str(),O_RDONLY);
    lock_.lock();
    doc_.ReadFromFile(filename_);
    lock_.unlock();
    Arc::InformationContainer::Assign(doc_,false);
  };
  olock_.unlock();
}

Here is the call graph for this function:

void Arc::InformationContainer::Get ( const std::list< std::string > &  path,
XMLNodeContainer result 
) [protected, virtual, inherited]

This method is called by this object's Process method.

Real implementation of this class should return (sub)tree of XML document. This method may be called multiple times per single Process call. Here is a set on XML element names specifying how to reach requested node(s).

Reimplemented from Arc::InformationInterface.

Definition at line 184 of file InformationInterface.cpp.

                                                                                      {
  std::list<XMLNode> cur_list;
  std::list<std::string>::const_iterator cur_name = path.begin();
  cur_list.push_back(doc_);
  for(;cur_name != path.end(); ++cur_name) {
    std::list<XMLNode> new_list;
    for(std::list<XMLNode>::iterator cur_node = cur_list.begin();
                       cur_node != cur_list.end(); ++cur_node) {
      // TODO: namespaces
      std::string name = *cur_name;
      std::string::size_type p = name.find(':');
      if(p != std::string::npos) name=name.substr(p+1);
      XMLNode new_node = (*cur_node)[name];
      for(;;new_node=new_node[1]) {
        if(!new_node) break;
        new_list.push_back(new_node);
      };
    };
    cur_list=new_list;
  };
  result.Add(cur_list);
  return;
}

Here is the call graph for this function:

void Arc::InformationContainer::Get ( XMLNode  xpath,
XMLNodeContainer result 
) [protected, virtual, inherited]

Reimplemented from Arc::InformationInterface.

Definition at line 208 of file InformationInterface.cpp.

                                                                     {
  std::string q = query;
  NS ns = query.Namespaces();
  result.Add(doc_.XPathLookup(q,ns));
  return;
}

Here is the call graph for this function:

Definition at line 239 of file information_collector.cpp.

                                                    {
  int h = -1;
  olock_.lock();
  if(handle_ != -1) h = ::dup(handle_);
  olock_.unlock();
  return h;
}

Here is the caller graph for this function:

SOAPEnvelope * Arc::InformationInterface::Process ( SOAPEnvelope &  in) [inherited]

Definition at line 39 of file InformationInterface.cpp.

                                                            {
  // Try to extract WSRP object from message
  WSRF& wsrp = CreateWSRP(in);
  if(!wsrp) { delete &wsrp; return NULL; };
  // Check if operation is supported
  MutexSLock(lock_,to_lock_);
  try {
    WSRPGetResourcePropertyDocumentRequest* req = 
         dynamic_cast<WSRPGetResourcePropertyDocumentRequest*>(&wsrp);
    if(!req) throw std::exception();
    if(!(*req)) throw std::exception();
    // Requesting whole document
    XMLNodeContainer presp; Get(std::list<std::string>(),presp);
    XMLNode xresp; if(presp.Size() > 0) xresp=presp[0];
    WSRPGetResourcePropertyDocumentResponse resp(xresp);
    SOAPEnvelope* out = NULL;
    if(resp) {
      NS ns;
      (out = new SOAPEnvelope(ns))->Swap(resp.SOAP());
    };
    delete &wsrp;
    return out;
  } catch(std::exception& e) { };
  try {
    WSRPGetResourcePropertyRequest* req = 
         dynamic_cast<WSRPGetResourcePropertyRequest*>(&wsrp);
    if(!req) throw std::exception();
    if(!(*req)) throw std::exception();
    std::list<std::string> name; name.push_back(req->Name());
    XMLNodeContainer presp; Get(name,presp); // Requesting sub-element
    WSRPGetResourcePropertyResponse resp;
    for(int n = 0;n<presp.Size();++n) {
      XMLNode xresp = presp[n];
      // TODO: avoid copy
      resp.Property(xresp);
    };
    SOAPEnvelope* out = NULL;
    if(resp) {
      NS ns;
      (out = new SOAPEnvelope(ns))->Swap(resp.SOAP());
    };
    delete &wsrp;
    return out;
  } catch(std::exception& e) { };
  try {
    WSRPGetMultipleResourcePropertiesRequest* req = 
         dynamic_cast<WSRPGetMultipleResourcePropertiesRequest*>(&wsrp);
    if(!req) throw std::exception();
    if(!(*req)) throw std::exception();
    WSRPGetMultipleResourcePropertiesResponse resp;
    std::vector<std::string> names = req->Names();
    for(std::vector<std::string>::iterator iname = names.begin();
                              iname != names.end(); ++iname) {
      std::list<std::string> name; name.push_back(*iname);
      XMLNodeContainer presp; Get(name,presp); // Requesting sub-element
      for(int n = 0;n<presp.Size();++n) {
        XMLNode xresp = presp[n];
        resp.Property(xresp);
      };
    };
    SOAPEnvelope* out = NULL;
    if(resp) {
      NS ns;
      (out = new SOAPEnvelope(ns))->Swap(resp.SOAP());
    };
    delete &wsrp;
    return out;
  } catch(std::exception& e) { };
  try {
    WSRPQueryResourcePropertiesRequest* req = 
         dynamic_cast<WSRPQueryResourcePropertiesRequest*>(&wsrp);
    if(!req) throw std::exception();
    if(!(*req)) throw std::exception();
    if(req->Dialect() != XPATH_1_0_URI) {
      // TODO: generate proper fault
      delete &wsrp;
      return SOAPFault::MakeSOAPFault(SOAPFault::Sender,"Query dialect not supported");
    }
    XMLNodeContainer presp; Get(req->Query(),presp);
    WSRPQueryResourcePropertiesResponse resp;
    for(int n = 0;n<presp.Size();++n) {
      XMLNode xresp = presp[n];
      resp.Properties().NewChild(xresp);
    };
    SOAPEnvelope* out = NULL;
    if(resp) {
      NS ns;
      (out = new SOAPEnvelope(ns))->Swap(resp.SOAP());
    };
    delete &wsrp;
    return out;
  } catch(std::exception& e) { };
  if(to_lock_) lock_.unlock();
  delete &wsrp;
  return SOAPFault::MakeSOAPFault(SOAPFault::Sender,"Operation not supported");
}

Here is the call graph for this function:

Here is the caller graph for this function:

SOAPEnvelope * Arc::InformationInterface::Process ( SOAPEnvelope &  in,
const InfoFilter filter,
const InfoFilterPolicies policies = InfoFilterPolicies(),
const NS ns = NS() 
) [inherited]

Definition at line 136 of file InformationInterface.cpp.

                                                                                                                                     {
  SOAPEnvelope* out = Process(in);
  // If error or fault - leave
  if(!out) return out;
  if(!(*out)) return out;
  if(out->IsFault()) return out;
  // Otherwise filter body of result
  if(filter.Filter(out->Body(),policies,ns)) return out;
  // If filtering failed it is safer to return SOAP fault
  delete out;
  return SOAPFault::MakeSOAPFault(SOAPFault::Sender,"Operation not supported");
}

Here is the call graph for this function:

Definition at line 247 of file information_collector.cpp.

                                                                             {
  Arc::WSRF& wsrp = Arc::CreateWSRP(in);
  if(!wsrp) { delete &wsrp; return NULL; };
  try {
    Arc::WSRPGetResourcePropertyDocumentRequest* req =
         dynamic_cast<Arc::WSRPGetResourcePropertyDocumentRequest*>(&wsrp);
    if(!req) throw std::exception();
    if(!(*req)) throw std::exception();
    // Request for whole document
    std::string fake_str("<fake>fake</fake>");
    Arc::XMLNode xresp(fake_str);
    Arc::WSRPGetResourcePropertyDocumentResponse resp(xresp);
    std::string rest_str;
    resp.SOAP().GetDoc(rest_str);
    std::string::size_type p = rest_str.find(fake_str);
    if(p == std::string::npos) throw std::exception();
    PrefixedFilePayload* outpayload = new PrefixedFilePayload(rest_str.substr(0,p),rest_str.substr(p+fake_str.length()),OpenDocument());
    delete &wsrp;
    return outpayload;
  } catch(std::exception& e) { };
  delete &wsrp;
  Arc::NS ns;
  Arc::SOAPEnvelope* out = InformationContainer::Process(in);
  if(!out) return NULL;
  Arc::PayloadSOAP* outpayload = new Arc::PayloadSOAP(ns);
  out->Swap(*outpayload);
  delete out;
  return outpayload;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void Arc::InformationContainer::Release ( void  ) [inherited]

Definition at line 169 of file InformationInterface.cpp.

                                       {
  lock_.unlock();
}

Here is the caller graph for this function:


Member Data Documentation

Either link or container of XML document.

Reimplemented from Arc::InformationContainer.

Definition at line 38 of file arex.h.

Definition at line 36 of file arex.h.

Definition at line 37 of file arex.h.

Glib::Mutex Arc::InformationInterface::lock_ [protected, inherited]

Mutex used to protect access to Get methods in multi-threaded env.

Definition at line 21 of file InformationInterface.h.

Definition at line 39 of file arex.h.

bool Arc::InformationInterface::to_lock_ [protected, inherited]

Definition at line 22 of file InformationInterface.h.


The documentation for this class was generated from the following files: