OW_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 "OW_config.h"
00037 #include "OW_CIMNameSpace.hpp"
00038 #include "OW_CIMUrl.hpp"
00039 #include "OW_StrictWeakOrdering.hpp"
00040 #include "OW_COWIntrusiveCountableBase.hpp"
00041 #include <cctype>
00042 
00043 namespace OW_NAMESPACE
00044 {
00045 
00046 using std::ostream;
00047 using std::istream;
00049 struct CIMNameSpace::NSData : public COWIntrusiveCountableBase
00050 {
00051    String m_nameSpace;
00052    CIMUrl m_url;
00053    NSData* clone() const { return new NSData(*this); }
00054 };
00056 bool operator<(const CIMNameSpace::NSData& x, const CIMNameSpace::NSData& y)
00057 {
00058    return StrictWeakOrdering(
00059       x.m_nameSpace, y.m_nameSpace,
00060       x.m_url, y.m_url);
00061 }
00063 CIMNameSpace::CIMNameSpace() :
00064    CIMBase(), m_pdata(new NSData)
00065 {
00066    //m_pdata->m_nameSpace = CIM_OW_DEFAULT_NS;
00067 }
00069 CIMNameSpace::CIMNameSpace(CIMNULL_t) :
00070    CIMBase(), m_pdata(0)
00071 {
00072 }
00074 CIMNameSpace::CIMNameSpace(const CIMUrl& hostUrl,
00075    const String& nameSpace) :
00076    CIMBase(), m_pdata(new NSData)
00077 {
00078    m_pdata->m_url = hostUrl;
00079    if (nameSpace.empty())
00080    {
00081       //m_pdata->m_nameSpace = String(CIM_OW_DEFAULT_NS);
00082    }
00083    else
00084    {
00085       setNameSpace(nameSpace);
00086    }
00087 }
00089 CIMNameSpace::CIMNameSpace(const String& nameSpace) :
00090    CIMBase(), m_pdata(new NSData)
00091 {
00092    if (nameSpace.empty())
00093    {
00094       //m_pdata->m_nameSpace = String(CIM_OW_DEFAULT_NS);
00095    }
00096    else
00097    {
00098       setNameSpace(nameSpace);
00099    }
00100 }
00102 CIMNameSpace::CIMNameSpace(const char* nameSpace) :
00103    CIMBase(), m_pdata(new NSData)
00104 {
00105    if (nameSpace == 0 || nameSpace[0] == '\0')
00106    {
00107       //m_pdata->m_nameSpace = String(CIM_OW_DEFAULT_NS);
00108    }
00109    else
00110    {
00111       setNameSpace(nameSpace);
00112    }
00113 }
00115 CIMNameSpace::CIMNameSpace(const CIMNameSpace& arg) :
00116    CIMBase(), m_pdata(arg.m_pdata)
00117 {
00118 }
00120 CIMNameSpace::~CIMNameSpace()
00121 {
00122 }
00124 void
00125 CIMNameSpace::setNull()
00126 {
00127    m_pdata = 0;
00128 }
00130 CIMNameSpace&
00131 CIMNameSpace::operator= (const CIMNameSpace& arg)
00132 {
00133    m_pdata = arg.m_pdata;
00134    return *this;
00135 }
00137 String
00138 CIMNameSpace::getNameSpace() const
00139 {
00140    return m_pdata->m_nameSpace;
00141 }
00143 String
00144 CIMNameSpace::getHost() const
00145 {
00146    return m_pdata->m_url.getHost();
00147 }
00149 CIMUrl
00150 CIMNameSpace::getHostUrl() const
00151 {
00152    return m_pdata->m_url;
00153 }
00155 Int32
00156 CIMNameSpace::getPortNumber() const
00157 {
00158    return m_pdata->m_url.getPort();
00159 }
00161 String
00162 CIMNameSpace::getProtocol() const
00163 {
00164    return m_pdata->m_url.getProtocol();
00165 }
00167 String
00168 CIMNameSpace::getFileName() const
00169 {
00170    return m_pdata->m_url.getFile();
00171 }
00173 bool
00174 CIMNameSpace::isLocal() const
00175 {
00176    return m_pdata->m_url.isLocal();
00177 }
00179 String
00180 CIMNameSpace::toString() const
00181 {
00182    return String(m_pdata->m_nameSpace);
00183 }
00185 CIMNameSpace&
00186 CIMNameSpace::setNameSpace(const String& nameSpace)
00187 {
00188    // Remove any preceeding '/' chars or spaces
00189    String tns(nameSpace);
00190    tns.trim();
00191    const char* p = tns.c_str();
00192    while (*p && *p == '/')
00193    {
00194       p++;
00195    }
00196    m_pdata->m_nameSpace = p;
00197    return *this;
00198 }
00200 CIMNameSpace&
00201 CIMNameSpace::setHostUrl(const CIMUrl& hostUrl)
00202 {
00203    m_pdata->m_url = hostUrl;
00204    return *this;
00205 }
00207 CIMNameSpace&
00208 CIMNameSpace::setHost(const String& host)
00209 {
00210    m_pdata->m_url.setHost(host);
00211    return *this;
00212 }
00214 CIMNameSpace&
00215 CIMNameSpace::setProtocol(const String& protocol)
00216 {
00217    m_pdata->m_url.setProtocol(protocol);
00218    return *this;
00219 }
00221 void
00222 CIMNameSpace::readObject(istream &istrm)
00223 {
00224    CIMBase::readSig( istrm, OW_CIMNAMESPACESIG );
00225    String ns;
00226    ns.readObject(istrm);
00227    CIMUrl url(CIMNULL);
00228    url.readObject(istrm);
00229    // Assign here in case exception gets thrown on preceeding readObjects
00230    if (!m_pdata)
00231    {
00232       m_pdata = new NSData;
00233    }
00234    m_pdata->m_nameSpace = ns;
00235    m_pdata->m_url = url;
00236 }
00238 void
00239 CIMNameSpace::writeObject(ostream &ostrm) const
00240 {
00241    CIMBase::writeSig( ostrm, OW_CIMNAMESPACESIG );
00242    m_pdata->m_nameSpace.writeObject(ostrm);
00243    m_pdata->m_url.writeObject(ostrm);
00244 }
00246 bool operator<(const CIMNameSpace& lhs, const CIMNameSpace& rhs)
00247 {
00248    return *lhs.m_pdata < *rhs.m_pdata;
00249 }
00250 
00252 String
00253 CIMNameSpace::toMOF() const
00254 {
00255    return "UMIMPLEMENTED"; 
00256 }
00257 
00258 } // end namespace OW_NAMESPACE
00259 

Generated on Thu Feb 9 08:47:53 2006 for openwbem by  doxygen 1.4.6