OW_CIMQualifier.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_CIMQualifier.hpp"
00038 #include "OW_StringBuffer.hpp"
00039 #include "OW_Assertion.hpp"
00040 #include "OW_BinarySerialization.hpp"
00041 #include "OW_StrictWeakOrdering.hpp"
00042 #include "OW_NULLValueException.hpp"
00043 #include "OW_CIMValue.hpp"
00044 #include "OW_CIMQualifierType.hpp"
00045 #include "OW_CIMFlavor.hpp"
00046 #include "OW_COWIntrusiveCountableBase.hpp"
00047 
00048 namespace OW_NAMESPACE
00049 {
00050 
00051 using std::istream;
00052 using std::ostream;
00054 struct CIMQualifier::QUALData : public COWIntrusiveCountableBase
00055 {
00056    QUALData() 
00057       : m_qualifierValue(CIMNULL)
00058       , m_propagated(false) 
00059    {}
00060    CIMName m_name;
00061    CIMValue m_qualifierValue;
00062    CIMQualifierType m_qualifierType;
00063    Bool m_propagated;
00064    CIMFlavorArray m_flavors;
00065    String m_language;
00066    QUALData* clone() const { return new QUALData(*this); }
00067 };
00069 bool operator<(const CIMQualifier::QUALData& x, const CIMQualifier::QUALData& y)
00070 {
00071    return StrictWeakOrdering(
00072       x.m_name, y.m_name,
00073       x.m_language, y.m_language,
00074       x.m_qualifierValue, y.m_qualifierValue,
00075       x.m_qualifierType, y.m_qualifierType,
00076       x.m_propagated, y.m_propagated,
00077       x.m_flavors, y.m_flavors);
00078 }
00080 CIMQualifier::CIMQualifier() :
00081    CIMElement(), m_pdata(new QUALData)
00082 {
00083 }
00085 CIMQualifier::CIMQualifier(CIMNULL_t) :
00086    CIMElement(), m_pdata(0)
00087 {
00088 }
00090 CIMQualifier::CIMQualifier(const CIMName& name) :
00091    CIMElement(), m_pdata(new QUALData)
00092 {
00093    m_pdata->m_name = name;
00094 }
00096 CIMQualifier::CIMQualifier(const char* name) :
00097    CIMElement(), m_pdata(new QUALData)
00098 {
00099    m_pdata->m_name = name;
00100 }
00102 CIMQualifier::CIMQualifier(const CIMQualifierType& cgt) :
00103    CIMElement(), m_pdata(new QUALData)
00104 {
00105    m_pdata->m_name = cgt.getName();
00106    m_pdata->m_qualifierType = cgt;
00107    m_pdata->m_qualifierValue = cgt.getDefaultValue();
00108    m_pdata->m_flavors = cgt.getFlavors();
00109 }
00111 CIMQualifier::CIMQualifier(const CIMQualifier& x) :
00112    CIMElement(), m_pdata(x.m_pdata)
00113 {
00114 }
00116 CIMQualifier::~CIMQualifier()
00117 {
00118 }
00120 void
00121 CIMQualifier::setNull()
00122 {
00123    m_pdata = NULL;
00124 }
00126 CIMQualifier&
00127 CIMQualifier::operator= (const CIMQualifier& x)
00128 {
00129    m_pdata = x.m_pdata;
00130    return *this;
00131 }
00133 bool
00134 CIMQualifier::isKeyQualifier() const
00135 {
00136    return m_pdata->m_name == CIMQualifier::CIM_QUAL_KEY;
00137 }
00139 bool
00140 CIMQualifier::isAssociationQualifier() const
00141 {
00142    return m_pdata->m_name == CIMQualifier::CIM_QUAL_ASSOCIATION;
00143 }
00145 CIMValue
00146 CIMQualifier::getValue() const
00147 {
00148    return m_pdata->m_qualifierValue;
00149 }
00151 CIMValue
00152 CIMQualifier::getValueT() const
00153 {
00154    if (!m_pdata->m_qualifierValue)
00155    {
00156       OW_THROW(NULLValueException, "");
00157    }
00158    return m_pdata->m_qualifierValue;
00159 }
00161 CIMQualifier&
00162 CIMQualifier::setValue(const CIMValue& value)
00163 {
00164    m_pdata->m_qualifierValue = value;
00165    return *this;
00166 }
00168 CIMQualifier&
00169 CIMQualifier::setDefaults(const CIMQualifierType& qtype)
00170 {
00171    m_pdata->m_qualifierType = qtype;
00172    return *this;
00173 }
00175 CIMQualifierType
00176 CIMQualifier::getDefaults() const
00177 {
00178    return m_pdata->m_qualifierType;
00179 }
00181 bool
00182 CIMQualifier::hasFlavor(const CIMFlavor& flavor) const
00183 {
00184    if (flavor)
00185    {
00186       size_t tsize = m_pdata->m_flavors.size();
00187       for (size_t i = 0; i < tsize; i++)
00188       {
00189          if (m_pdata->m_flavors[i].getFlavor() == flavor.getFlavor())
00190          {
00191             return true;
00192          }
00193       }
00194    }
00195    return(false);
00196 }
00198 CIMQualifier&
00199 CIMQualifier::addFlavor(const CIMFlavor& flavor)
00200 {
00201    if (flavor)
00202    {
00203       Int32 flavorValue = flavor.getFlavor();
00204       //
00205       // Don't add it if its already present
00206       //
00207       size_t tsize = m_pdata->m_flavors.size();
00208       for (size_t i = 0; i < tsize; i++)
00209       {
00210          if (m_pdata->m_flavors[i].getFlavor() == flavorValue)
00211          {
00212             return *this;
00213          }
00214       }
00215       switch (flavorValue)
00216       {
00217          case CIMFlavor::ENABLEOVERRIDE:
00218             removeFlavor(CIMFlavor::DISABLEOVERRIDE);
00219             break;
00220          case CIMFlavor::DISABLEOVERRIDE:
00221             removeFlavor(CIMFlavor::ENABLEOVERRIDE);
00222             break;
00223          case CIMFlavor::RESTRICTED:
00224             removeFlavor(CIMFlavor::TOSUBCLASS);
00225             break;
00226          case CIMFlavor::TOSUBCLASS:
00227             removeFlavor(CIMFlavor::RESTRICTED);
00228             break;
00229       }
00230       m_pdata->m_flavors.append(flavor);
00231    }
00232    return *this;
00233 }
00235 CIMQualifier&
00236 CIMQualifier::removeFlavor(Int32 flavor)
00237 {
00238    size_t i = 0;
00239    while (i < m_pdata->m_flavors.size())
00240    {
00241       if (m_pdata->m_flavors[i].getFlavor() == flavor)
00242       {
00243          m_pdata->m_flavors.remove(i);
00244       }
00245       else
00246       {
00247          ++i;
00248       }
00249    }
00250    return *this;
00251 }
00253 bool
00254 CIMQualifier::hasValue() const
00255 {
00256    return (m_pdata->m_qualifierValue) ? true : false;
00257 }
00259 bool
00260 CIMQualifier::equals(const CIMQualifier& arg) const
00261 {
00262    return m_pdata->m_name == arg.getName();
00263 }
00265 CIMFlavorArray
00266 CIMQualifier::getFlavor() const
00267 {
00268    return m_pdata->m_flavors;
00269 }
00271 CIMQualifier&
00272 CIMQualifier::setPropagated(bool propagated)
00273 {
00274    m_pdata->m_propagated = propagated;
00275    return *this;
00276 }
00278 bool
00279 CIMQualifier::getPropagated() const
00280 {
00281    return m_pdata->m_propagated;
00282 }
00284 CIMQualifier& 
00285 CIMQualifier::setLanguage(const String& language)
00286 {
00287    OW_ASSERT(hasFlavor(CIMFlavor::TRANSLATE));
00288    m_pdata->m_language = language;
00289    return *this;
00290 }
00292 String
00293 CIMQualifier::getLanguage() const
00294 {
00295    return m_pdata->m_language;
00296 }
00298 String
00299 CIMQualifier::getName() const
00300 {
00301    return m_pdata->m_name.toString();
00302 }
00304 void
00305 CIMQualifier::setName(const CIMName& name)
00306 {
00307    m_pdata->m_name = name;
00308 }
00310 void
00311 CIMQualifier::readObject(istream &istrm)
00312 {
00313    CIMName name;
00314    CIMValue qualifierValue(CIMNULL);
00315    CIMQualifierType qualifierType(CIMNULL);
00316    Bool propagated;
00317    CIMFlavorArray flavors;
00318    Bool isValue;
00319    String language;
00320 
00321    UInt32 version = CIMBase::readSig( istrm, OW_CIMQUALIFIERSIG, OW_CIMQUALIFIERSIG_V, CIMQualifier::SERIALIZATION_VERSION );
00322 
00323    name.readObject(istrm);
00324    isValue.readObject(istrm);
00325    if (isValue)
00326    {
00327       qualifierValue.readObject(istrm);
00328    }
00329    qualifierType.readObject(istrm);
00330    propagated.readObject(istrm);
00331    BinarySerialization::readArray(istrm, flavors);
00332 
00333    // language was added in version 1
00334    if (version > 0)
00335    {
00336       language.readObject(istrm);
00337    }
00338 
00339    if (!m_pdata)
00340    {
00341       m_pdata = new QUALData;
00342    }
00343    m_pdata->m_name = name;
00344    m_pdata->m_qualifierValue = qualifierValue;
00345    m_pdata->m_qualifierType = qualifierType;
00346    m_pdata->m_propagated = propagated;
00347    m_pdata->m_flavors = flavors;
00348    m_pdata->m_language = language;
00349 }
00351 void
00352 CIMQualifier::writeObject(ostream &ostrm) const
00353 {
00354    CIMBase::writeSig(ostrm, OW_CIMQUALIFIERSIG_V, CIMQualifier::SERIALIZATION_VERSION);
00355 
00356    m_pdata->m_name.writeObject(ostrm);
00357    CIMValue qv = m_pdata->m_qualifierValue;
00358    if (!qv && m_pdata->m_qualifierType)
00359    {
00360       qv = m_pdata->m_qualifierType.getDefaultValue();
00361    }
00362    if (m_pdata->m_qualifierValue)
00363    {
00364       Bool(true).writeObject(ostrm);
00365       qv.writeObject(ostrm);
00366    }
00367    else
00368    {
00369       Bool(false).writeObject(ostrm);
00370    }
00371    m_pdata->m_qualifierType.writeObject(ostrm);
00372    m_pdata->m_propagated.writeObject(ostrm);
00373    BinarySerialization::writeArray(ostrm, m_pdata->m_flavors);
00374    m_pdata->m_language.writeObject(ostrm);
00375 }
00377 String
00378 CIMQualifier::toMOF() const
00379 {
00380    StringBuffer rv;
00381    rv += m_pdata->m_name.toString();
00382    
00383    if (!m_pdata->m_language.empty())
00384    {
00385       rv += '_';
00386       rv += m_pdata->m_language;
00387    }
00388 
00389    if (m_pdata->m_qualifierValue 
00390       && m_pdata->m_name != CIMName("Association")
00391       && m_pdata->m_name != CIMName("Indication"))
00392    {
00393       if (!m_pdata->m_qualifierValue.isArray())
00394       {
00395          rv += '(';
00396       }
00397       rv += m_pdata->m_qualifierValue.toMOF();
00398       if (!m_pdata->m_qualifierValue.isArray())
00399       {
00400          rv += ')';
00401       }
00402    }
00403    
00404    return rv.releaseString();
00405 }
00407 String
00408 CIMQualifier::toString() const
00409 {
00410    StringBuffer rv("CIMQualifier(");
00411    rv += m_pdata->m_name.toString();
00412    if (!m_pdata->m_language.empty())
00413    {
00414       rv += '_';
00415       rv += m_pdata->m_language;
00416    }
00417    rv += ')';
00418    return rv.releaseString();
00419 }
00421 // STATIC
00422 CIMQualifier
00423 CIMQualifier::createKeyQualifier()
00424 {
00425    CIMQualifier cq(CIMQualifier::CIM_QUAL_KEY);
00426    cq.setValue(CIMValue(Bool(true)));
00427    return cq;
00428 }
00430 bool operator<(const CIMQualifier& x, const CIMQualifier& y)
00431 {
00432    return *x.m_pdata < *y.m_pdata;
00433 }
00434 // Meta qualifiers
00435 const char* const CIMQualifier::CIM_QUAL_ASSOCIATION  = "Association";
00436 const char* const CIMQualifier::CIM_QUAL_INDICATION      = "Indication";
00437 // Standard qualifiers
00438 const char* const CIMQualifier::CIM_QUAL_ABSTRACT     = "Abstract";
00439 const char* const CIMQualifier::CIM_QUAL_AGGREGATE       = "Aggregate";
00440 const char* const CIMQualifier::CIM_QUAL_AGGREGATION  = "Aggregation";
00441 const char* const CIMQualifier::CIM_QUAL_ALIAS        = "Alias";
00442 const char* const CIMQualifier::CIM_QUAL_ARRAYTYPE       = "ArrayType";
00443 const char* const CIMQualifier::CIM_QUAL_BITMAP       = "BitMap";
00444 const char* const CIMQualifier::CIM_QUAL_BITVALUES       = "BitValues";
00445 const char* const CIMQualifier::CIM_QUAL_COMPOSITION    = "Composition";
00446 const char* const CIMQualifier::CIM_QUAL_COUNTER      = "Counter";
00447 const char* const CIMQualifier::CIM_QUAL_DELETE         = "Delete";
00448 const char* const CIMQualifier::CIM_QUAL_DEPRECATED     = "Deprecated";
00449 const char* const CIMQualifier::CIM_QUAL_DESCRIPTION  = "Description";
00450 const char* const CIMQualifier::CIM_QUAL_DISPLAYNAME  = "DisplayName";
00451 const char* const CIMQualifier::CIM_QUAL_DN             = "DN";
00452 const char* const CIMQualifier::CIM_QUAL_EMBEDDEDOBJECT = "EmbeddedObject";
00453 const char* const CIMQualifier::CIM_QUAL_EXCEPTION      = "Exception";
00454 const char* const CIMQualifier::CIM_QUAL_EXPENSIVE      = "Expensive";
00455 const char* const CIMQualifier::CIM_QUAL_EXPERIMENTAL   = "Experimental";
00456 const char* const CIMQualifier::CIM_QUAL_GAUGE        = "Gauge";
00457 const char* const CIMQualifier::CIM_QUAL_IFDELETED      = "Ifdeleted";
00458 const char* const CIMQualifier::CIM_QUAL_IN             = "In";
00459 const char* const CIMQualifier::CIM_QUAL_INVISIBLE      = "Invisible";
00460 const char* const CIMQualifier::CIM_QUAL_KEY            = "Key";
00461 const char* const CIMQualifier::CIM_QUAL_LARGE          = "Large";
00462 const char* const CIMQualifier::CIM_QUAL_MAPPINGSTRINGS  = "MappingStrings";
00463 const char* const CIMQualifier::CIM_QUAL_MAX          = "Max";
00464 const char* const CIMQualifier::CIM_QUAL_MAXLEN         = "MaxLen";
00465 const char* const CIMQualifier::CIM_QUAL_MAXVALUE     = "MaxValue";
00466 const char* const CIMQualifier::CIM_QUAL_MIN          = "Min";
00467 const char* const CIMQualifier::CIM_QUAL_MINLEN         = "MinLen";
00468 const char* const CIMQualifier::CIM_QUAL_MINVALUE     = "MinValue";
00469 const char* const CIMQualifier::CIM_QUAL_MODELCORRESPONDENCE = "ModelCorrespondence";
00470 const char* const CIMQualifier::CIM_QUAL_NONLOCAL     = "Nonlocal";
00471 const char* const CIMQualifier::CIM_QUAL_NONLOCALTYPE    = "NonlocalType";
00472 const char* const CIMQualifier::CIM_QUAL_NULLVALUE       = "NullValue";
00473 const char* const CIMQualifier::CIM_QUAL_OCTETSTRING    = "Octetstring";
00474 const char* const CIMQualifier::CIM_QUAL_OUT          = "Out";
00475 const char* const CIMQualifier::CIM_QUAL_OVERRIDE     = "Override";
00476 const char* const CIMQualifier::CIM_QUAL_PROPAGATED   = "Propagated";
00477 const char* const CIMQualifier::CIM_QUAL_PROPERTYUSAGE  = "PropertyUsage";
00478 const char* const CIMQualifier::CIM_QUAL_PROVIDER       = "Provider";
00479 const char* const CIMQualifier::CIM_QUAL_READ         = "Read";
00480 const char* const CIMQualifier::CIM_QUAL_REQUIRED     = "Required";
00481 const char* const CIMQualifier::CIM_QUAL_REVISION     = "Revision";
00482 const char* const CIMQualifier::CIM_QUAL_SCHEMA         = "Schema";
00483 const char* const CIMQualifier::CIM_QUAL_SOURCE         = "Source";
00484 const char* const CIMQualifier::CIM_QUAL_SOURCETYPE     = "SourceType";
00485 const char* const CIMQualifier::CIM_QUAL_STATIC         = "Static";
00486 const char* const CIMQualifier::CIM_QUAL_SYNTAX         = "Syntax";
00487 const char* const CIMQualifier::CIM_QUAL_SYNTAXTYPE     = "SyntaxType";
00488 const char* const CIMQualifier::CIM_QUAL_TERMINAL     = "Terminal";
00489 const char* const CIMQualifier::CIM_QUAL_TRIGGERTYPE    = "TriggerType";
00490 const char* const CIMQualifier::CIM_QUAL_UNITS        = "Units";
00491 const char* const CIMQualifier::CIM_QUAL_UNKNOWNVALUES  = "UnknownValues";
00492 const char* const CIMQualifier::CIM_QUAL_UNSUPPORTEDVALUES = "UnsupportedValues";
00493 const char* const CIMQualifier::CIM_QUAL_VALUEMAP     = "ValueMap";
00494 const char* const CIMQualifier::CIM_QUAL_VALUES         = "Values";
00495 const char* const CIMQualifier::CIM_QUAL_VERSION      = "Version";
00496 const char* const CIMQualifier::CIM_QUAL_WEAK         = "Weak";
00497 const char* const CIMQualifier::CIM_QUAL_WRITE        = "Write";
00498 
00499 } // end namespace OW_NAMESPACE
00500 

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