OW_XMLQualifier.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_XMLQualifier.hpp"
00038 #include "OW_CIMFlavor.hpp"
00039 #include "OW_CIMScope.hpp"
00040 #include "OW_CIMQualifierType.hpp"
00041 #include "OW_CIMDataType.hpp"
00042 #include "OW_CIMValue.hpp"
00043 #include "OW_XMLCIMFactory.hpp"
00044 #include "OW_CIMException.hpp"
00045 #include "OW_CIMXMLParser.hpp"
00046 #include "OW_CIMName.hpp"
00047 
00048 namespace OW_NAMESPACE
00049 {
00050 
00051 namespace XMLQualifier
00052 {
00053 
00054 void
00055 processQualifierDecl(CIMXMLParser& parser,
00056    CIMQualifierType& cimQualifier)
00057 {
00058    if (!parser.tokenIsId(CIMXMLParser::E_QUALIFIER_DECLARATION))
00059    {
00060       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER, "Expected but did not find <QUALIFIER.DECLARATION>");
00061    }
00062    CIMName superClassName;
00063    CIMName inClassName;
00064    CIMName qualName = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00065    cimQualifier.setName(qualName);
00066    String qualType = parser.mustGetAttribute(CIMXMLParser::A_TYPE);
00067    CIMDataType dt = CIMDataType::getDataType(qualType);
00068    String qualISARRAY = parser.getAttribute(CIMXMLParser::A_ISARRAY);
00069    if (qualISARRAY.equalsIgnoreCase("true"))
00070    {
00071       String qualArraySize = parser.getAttribute(CIMXMLParser::A_ARRAYSIZE);
00072       if (!qualArraySize.empty())
00073       {
00074          try
00075          {
00076             dt.setToArrayType(qualArraySize.toInt32());
00077          }
00078          catch (const StringConversionException&)
00079          {
00080             OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00081                "Invalid array size");
00082          }
00083       }
00084       else
00085       {
00086          dt.setToArrayType(-1);  // unlimited array type
00087       }
00088    }
00089    cimQualifier.setDataType(dt);
00090    String qualFlavor = parser.getAttribute("OVERRIDABLE");
00091    if (qualFlavor.equalsIgnoreCase("false"))
00092    {
00093       cimQualifier.addFlavor(CIMFlavor(CIMFlavor::DISABLEOVERRIDE));
00094    }
00095    else
00096    {
00097       cimQualifier.addFlavor(CIMFlavor(CIMFlavor::ENABLEOVERRIDE));
00098    }
00099    qualFlavor = parser.getAttribute("TOSUBCLASS");
00100    if (qualFlavor.equalsIgnoreCase("false"))
00101    {
00102       cimQualifier.addFlavor(CIMFlavor(CIMFlavor::RESTRICTED));
00103    }
00104    else
00105    {
00106       cimQualifier.addFlavor(CIMFlavor(CIMFlavor::TOSUBCLASS));
00107    }
00108    //qualFlavor = parser.getAttribute("TOINSTANCE");
00109    //if (qualFlavor.equalsIgnoreCase("true"))
00110    //{
00111    // cimQualifier.addFlavor(CIMFlavor(CIMFlavor::TOINSTANCE));
00112    //}
00113    qualFlavor = parser.getAttribute("TRANSLATABLE");
00114    if (qualFlavor.equalsIgnoreCase("true"))
00115    {
00116       cimQualifier.addFlavor(CIMFlavor(CIMFlavor::TRANSLATE));
00117    }
00118    parser.getNextTag();
00119    if (parser.tokenIsId(CIMXMLParser::E_SCOPE))
00120    {
00121       // process optional scope child
00122       processScope(parser,cimQualifier,"CLASS",CIMScope::CLASS);
00123       processScope(parser,cimQualifier,"ASSOCIATION",CIMScope::ASSOCIATION);
00124       processScope(parser,cimQualifier,"REFERENCE",CIMScope::REFERENCE);
00125       processScope(parser,cimQualifier,"PROPERTY",CIMScope::PROPERTY);
00126       processScope(parser,cimQualifier,"METHOD",CIMScope::METHOD);
00127       processScope(parser,cimQualifier,"PARAMETER",CIMScope::PARAMETER);
00128       processScope(parser,cimQualifier,"INDICATION",CIMScope::INDICATION);
00129       if (cimQualifier.hasScope(CIMScope::CLASS) &&
00130          cimQualifier.hasScope(CIMScope::ASSOCIATION) &&
00131          cimQualifier.hasScope(CIMScope::REFERENCE) &&
00132          cimQualifier.hasScope(CIMScope::PROPERTY) &&
00133          cimQualifier.hasScope(CIMScope::METHOD) &&
00134          cimQualifier.hasScope(CIMScope::PARAMETER) &&
00135          cimQualifier.hasScope(CIMScope::INDICATION))
00136       {
00137          cimQualifier.addScope(CIMScope::ANY); // This will erase all the others.
00138       }
00139       parser.mustGetNextTag();
00140       parser.mustGetEndTag();
00141    }
00142    else
00143    {
00144       // The SCOPE subelement ... if absent it implies that there is no
00145       // restriction on the scope at which the Qualifier may be applied
00146       // (so that it has 'any' scop in the terminology of CIM)
00147       cimQualifier.addScope(CIMScope::ANY);
00148    }
00149    if (parser.tokenIsId(CIMXMLParser::E_VALUE) ||
00150       parser.tokenIsId(CIMXMLParser::E_VALUE_ARRAY))
00151    {
00152       // process optional value or value.array child
00153       CIMValue val = XMLCIMFactory::createValue(parser,qualType, XMLCIMFactory::E_VALUE_NOT_EMBEDDED_OBJECT);
00154       cimQualifier.setDefaultValue(val);
00155    }
00156    parser.mustGetEndTag(); // pass </QUALIFIER.DECLARATION>
00157 }
00159 void
00160 processScope(CIMXMLParser& parser,
00161       CIMQualifierType& cqt, const char* attrName,
00162       CIMScope::Scope scopeValue)
00163 {
00164    String scope = parser.getAttribute(attrName);
00165    if (scope.empty())
00166    {
00167       return;
00168    }
00169 
00170    if (scope.equalsIgnoreCase("true"))
00171    {
00172       cqt.addScope(CIMScope(scopeValue));
00173    }
00174    else if (!scope.equalsIgnoreCase("false"))
00175    {
00176       OW_THROWCIM(CIMException::FAILED);
00177    }
00178 }
00180 String
00181 getQualifierName(CIMXMLParser& parser)
00182 {
00183    if (!parser.tokenIsId(CIMXMLParser::E_IPARAMVALUE))
00184    {
00185       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00186          "Expected IPARAMVALUE to lead into QualifierName");
00187    }
00188    String propertyName = parser.mustGetAttribute(CIMXMLParser::A_NAME);
00189    if (!propertyName.equalsIgnoreCase(CIMXMLParser::P_QualifierName))
00190    {
00191       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00192             "Cannot find qualifier name");
00193    }
00194    parser.getChild();
00195    if (!parser.tokenIsId(CIMXMLParser::E_VALUE))
00196    {
00197       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00198             "Cannot find value for qualifier name");
00199    }
00200    parser.mustGetNext();
00201    if (!parser.isData())
00202    {
00203       OW_THROWCIMMSG(CIMException::INVALID_PARAMETER,
00204             "Cannot find value for qualifier name");
00205    }
00206    String name = parser.getData();
00207    parser.mustGetNextTag();
00208    parser.mustGetEndTag();
00209    return name;
00210 }
00211 
00212 } // end namespace XMLQualifier
00213 } // end namespace OW_NAMESPACE
00214 

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