it_bus_pdk/qname_persistence_handler.h

00001 #ifndef _IT_BUS_QNAME_PERSISTENCE_HANDLER_H_
00002 #define _IT_BUS_QNAME_PERSISTENCE_HANDLER_H_
00003 
00004 // @Copyright 2005 IONA Technologies, Plc. All Rights Reserved.
00005 //
00006 // This class handles persistence and serialization for QNames.
00007 
00008 #include <it_bus/qname.h>
00009 #include <it_bus/to_string.h>
00010 #include <it_bus/from_string.h>
00011 
00012 namespace IT_Bus
00013 {
00014     class QNamePersistenceHandler       
00015     {
00016       public:
00017 
00018         IT_EXPLICIT QNamePersistenceHandler(
00019             const QName& qname
00020         ) :
00021             m_qname(IT_CONST_CAST(QName&, qname)),
00022             m_buf(0),
00023             m_size(0)
00024         {
00025             qname_to_string();
00026         }
00027 
00028         IT_EXPLICIT QNamePersistenceHandler(
00029             QName& qname
00030         ) :
00031             m_qname(qname),
00032             m_buf(0),
00033             m_size(0)
00034         {
00035             qname_to_string();
00036         }
00037         
00038         ~QNamePersistenceHandler()
00039         {
00040             if (m_buf != 0)
00041             {
00042                 char* p = IT_STATIC_CAST(char*, m_buf);
00043                 delete [] p;
00044             }
00045         }
00046 
00047         void*&
00048         writebuf()
00049         {
00050             return m_buf;
00051         }    
00052 
00053         void*
00054         readbuf()
00055         {
00056             qname_to_string();
00057             const void* p = m_qname_str.c_str();
00058             return IT_CONST_CAST(void*, p);
00059         }    
00060 
00061         IT_ULong&
00062         writebuflen()
00063         {
00064             return m_size;
00065         }
00066 
00067         IT_ULong
00068         readbuflen() const
00069         {
00070             return m_qname_str.length() + 1;
00071         }
00072 
00073         AllocFunc
00074         allocator()
00075         {
00076             return operator new;
00077         }
00078 
00079         void
00080         update_read_buffer_after_write()
00081         {
00082             if (m_buf != 0)
00083             {
00084                 char* p = IT_STATIC_CAST(char*, m_buf);
00085                 m_qname_str = p;                
00086                 qname_from_string();
00087                 operator delete(p);
00088                 m_buf = 0;
00089             }
00090         }
00091 
00092       private:
00093 
00094         void
00095         qname_from_string()
00096         {           
00097             size_t pos      = m_qname_str.find("}");
00098             size_t length   = m_qname_str.length();
00099 
00100             if (pos != -1 && pos > 1 && m_qname_str.find("{") == 0 && pos+1 < length)
00101             {
00102                 String namespace_str = m_qname_str.substr(1, pos-1);
00103                 String localpart_str = m_qname_str.substr(pos+1, length-1); 
00104                 m_qname = QName("", localpart_str, namespace_str);
00105             }       
00106         }
00107 
00108         void
00109         qname_to_string()
00110         {        
00111             m_qname_str =  "{";
00112             m_qname_str += m_qname.get_namespace_uri();
00113             m_qname_str += "}";
00114             m_qname_str += m_qname.get_local_part();        
00115         }
00116 
00117         QName&      m_qname;
00118         String      m_qname_str;
00119         void*       m_buf;
00120         IT_ULong    m_size;
00121     };
00122 }
00123 
00124 #endif  

Generated on Tue Mar 20 15:27:53 2007 for Artix by  doxygen 1.5.1-p1