OWBI1_CIMNameSpace.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #include "OWBI1_config.h"
00037 #include "OWBI1_CIMNameSpace.hpp"
00038 #include "OWBI1_CIMUrl.hpp"
00039 #include "OW_StrictWeakOrdering.hpp"
00040 #include "OWBI1_COWIntrusiveCountableBase.hpp"
00041 #include <cctype>
00042 
00043 namespace OWBI1
00044 {
00045 
00046 using namespace OpenWBEM;
00047 using std::ostream;
00048 using std::istream;
00050 struct CIMNameSpace::NSData : public COWIntrusiveCountableBase
00051 {
00052    String m_nameSpace;
00053    CIMUrl m_url;
00054    NSData* clone() const { return new NSData(*this); }
00055 };
00057 bool operator<(const CIMNameSpace::NSData& x, const CIMNameSpace::NSData& y)
00058 {
00059    return StrictWeakOrdering(
00060       x.m_nameSpace, y.m_nameSpace,
00061       x.m_url, y.m_url);
00062 }
00064 CIMNameSpace::CIMNameSpace() :
00065    CIMBase(), m_pdata(new NSData)
00066 {
00067    //m_pdata->m_nameSpace = CIM_OWBI1_DEFAULT_NS;
00068 }
00070 CIMNameSpace::CIMNameSpace(CIMNULL_t) :
00071    CIMBase(), m_pdata(0)
00072 {
00073 }
00075 CIMNameSpace::CIMNameSpace(const CIMUrl& hostUrl,
00076    const String& nameSpace) :
00077    CIMBase(), m_pdata(new NSData)
00078 {
00079    m_pdata->m_url = hostUrl;
00080    if (nameSpace.empty())
00081    {
00082       //m_pdata->m_nameSpace = String(CIM_OWBI1_DEFAULT_NS);
00083    }
00084    else
00085    {
00086       setNameSpace(nameSpace);
00087    }
00088 }
00090 CIMNameSpace::CIMNameSpace(const String& nameSpace) :
00091    CIMBase(), m_pdata(new NSData)
00092 {
00093    if (nameSpace.empty())
00094    {
00095       //m_pdata->m_nameSpace = String(CIM_OWBI1_DEFAULT_NS);
00096    }
00097    else
00098    {
00099       setNameSpace(nameSpace);
00100    }
00101 }
00103 CIMNameSpace::CIMNameSpace(const char* nameSpace) :
00104    CIMBase(), m_pdata(new NSData)
00105 {
00106    if (nameSpace == 0 || nameSpace[0] == '\0')
00107    {
00108       //m_pdata->m_nameSpace = String(CIM_OWBI1_DEFAULT_NS);
00109    }
00110    else
00111    {
00112       setNameSpace(nameSpace);
00113    }
00114 }
00116 CIMNameSpace::CIMNameSpace(const CIMNameSpace& arg) :
00117    CIMBase(), m_pdata(arg.m_pdata)
00118 {
00119 }
00121 CIMNameSpace::~CIMNameSpace()
00122 {
00123 }
00125 void
00126 CIMNameSpace::setNull()
00127 {
00128    m_pdata = 0;
00129 }
00131 CIMNameSpace&
00132 CIMNameSpace::operator= (const CIMNameSpace& arg)
00133 {
00134    m_pdata = arg.m_pdata;
00135    return *this;
00136 }
00138 String
00139 CIMNameSpace::getNameSpace() const
00140 {
00141    return m_pdata->m_nameSpace;
00142 }
00144 String
00145 CIMNameSpace::getHost() const
00146 {
00147    return m_pdata->m_url.getHost();
00148 }
00150 CIMUrl
00151 CIMNameSpace::getHostUrl() const
00152 {
00153    return m_pdata->m_url;
00154 }
00156 Int32
00157 CIMNameSpace::getPortNumber() const
00158 {
00159    return m_pdata->m_url.getPort();
00160 }
00162 String
00163 CIMNameSpace::getProtocol() const
00164 {
00165    return m_pdata->m_url.getProtocol();
00166 }
00168 String
00169 CIMNameSpace::getFileName() const
00170 {
00171    return m_pdata->m_url.getFile();
00172 }
00174 bool
00175 CIMNameSpace::isLocal() const
00176 {
00177    return m_pdata->m_url.isLocal();
00178 }
00180 String
00181 CIMNameSpace::toString() const
00182 {
00183    return String(m_pdata->m_nameSpace);
00184 }
00186 CIMNameSpace&
00187 CIMNameSpace::setNameSpace(const String& nameSpace)
00188 {
00189    // Remove any preceeding '/' chars or spaces
00190    String tns(nameSpace);
00191    tns.trim();
00192    const char* p = tns.c_str();
00193    while (*p && *p == '/')
00194    {
00195       p++;
00196    }
00197    m_pdata->m_nameSpace = p;
00198    return *this;
00199 }
00201 CIMNameSpace&
00202 CIMNameSpace::setHostUrl(const CIMUrl& hostUrl)
00203 {
00204    m_pdata->m_url = hostUrl;
00205    return *this;
00206 }
00208 CIMNameSpace&
00209 CIMNameSpace::setHost(const String& host)
00210 {
00211    m_pdata->m_url.setHost(host);
00212    return *this;
00213 }
00215 CIMNameSpace&
00216 CIMNameSpace::setProtocol(const String& protocol)
00217 {
00218    m_pdata->m_url.setProtocol(protocol);
00219    return *this;
00220 }
00222 void
00223 CIMNameSpace::readObject(istream &istrm)
00224 {
00225    CIMBase::readSig( istrm, OWBI1_CIMNAMESPACESIG );
00226    String ns;
00227    ns.readObject(istrm);
00228    CIMUrl url(CIMNULL);
00229    url.readObject(istrm);
00230    // Assign here in case exception gets thrown on preceeding readObjects
00231    if (!m_pdata)
00232    {
00233       m_pdata = new NSData;
00234    }
00235    m_pdata->m_nameSpace = ns;
00236    m_pdata->m_url = url;
00237 }
00239 void
00240 CIMNameSpace::writeObject(ostream &ostrm) const
00241 {
00242    CIMBase::writeSig( ostrm, OWBI1_CIMNAMESPACESIG );
00243    m_pdata->m_nameSpace.writeObject(ostrm);
00244    m_pdata->m_url.writeObject(ostrm);
00245 }
00247 bool operator<(const CIMNameSpace& lhs, const CIMNameSpace& rhs)
00248 {
00249    return *lhs.m_pdata < *rhs.m_pdata;
00250 }
00251 
00253 String
00254 CIMNameSpace::toMOF() const
00255 {
00256    return "UMIMPLEMENTED"; 
00257 }
00258 
00259 } // end namespace OWBI1
00260 

Generated on Thu Feb 9 08:48:26 2006 for openwbem by  doxygen 1.4.6