OWBI1_SimpleAssociatorProviderIFC.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2004 Novell, 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 Novell 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 Novell, 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 "OWBI1_SimpleAssociatorProviderIFC.hpp"
00038 #include "OWBI1_CIMInstance.hpp"
00039 #include "OWBI1_CIMClass.hpp"
00040 #include "OWBI1_CIMObjectPath.hpp"
00041 #include "OWBI1_CIMProperty.hpp"
00042 #include "OWBI1_CIMValue.hpp"
00043 #include "OWBI1_CIMNameSpace.hpp"
00044 #include "OWBI1_ResultHandlerIFC.hpp"
00045 #include "OWBI1_CIMOMHandleIFC.hpp"
00046 #include "OWBI1_ProviderEnvironmentIFC.hpp"
00047 #include "OWBI1_CIMPropertyList.hpp"
00048 
00049 
00050 namespace OWBI1
00051 {
00052 namespace
00053 {
00054    class AssocHelperResultHandlerIFC : public CIMInstanceResultHandlerIFC
00055    {
00056    public:
00057       AssocHelperResultHandlerIFC(const CIMObjectPath& objectName,
00058          const CIMName& resultClass, const CIMName& role,
00059          const CIMName& resultRole)
00060       : _objectName(objectName)
00061       , _resultClass(resultClass)
00062       , _role(role)
00063       , _resultRole(resultRole)
00064       {
00065       }
00066       void doHandle(const CIMInstance& inst)
00067       {
00068          if (_resultRole != "")
00069          {
00070             CIMProperty prop = inst.getProperty(_resultRole);
00071 
00072             if (prop)
00073             {
00074                CIMObjectPath cop;
00075                prop.getValue().get(cop);
00076                assocAuxHandler(cop);
00077             }
00078          }
00079          else
00080          {
00081             CIMPropertyArray cpa = inst.getProperties();
00082             for (CIMPropertyArray::const_iterator iter = cpa.begin();
00083                iter < cpa.end(); ++iter)
00084             {
00085                CIMDataType dt = iter->getDataType();
00086                if (!dt.isReferenceType())
00087                {
00088                   continue;
00089                }
00090                CIMName propName = iter->getName();
00091                if (_role == propName)
00092                {
00093                   continue;
00094                }
00095                CIMObjectPath cop;
00096                iter->getValue().get(cop);
00097                if (cop != _objectName)
00098                {
00099                   assocAuxHandler(cop);
00100                }
00101             }
00102          }
00103       }
00104    protected:
00105       virtual void assocAuxHandler(const CIMObjectPath& cop) = 0;
00106    private:
00107       CIMObjectPath _objectName;
00108       CIMName _resultClass;
00109       CIMName _role;
00110       CIMName _resultRole;
00111    };
00112 
00113 
00115    class _RHAssociators : public AssocHelperResultHandlerIFC
00116    {
00117    public:
00118       _RHAssociators(CIMInstanceResultHandlerIFC& result,
00119          const CIMObjectPath& objectName,
00120          const CIMName& resultClass,
00121          const CIMName& role,
00122          const CIMName& resultRole,
00123          const CIMOMHandleIFCRef& lch,
00124          const CIMPropertyList& propertyList)
00125       : AssocHelperResultHandlerIFC(objectName,resultClass ,role ,resultRole)
00126       , _realHandler(result)
00127       , _lch(lch)
00128       , _propertyList(propertyList)
00129       {
00130       }
00131    protected:
00132       virtual void assocAuxHandler(const CIMObjectPath &cop)
00133       {
00134          CIMInstance inst = _lch->getInstance(cop.getFullNameSpace().getNameSpace(),
00135             cop, _propertyList);
00136          _realHandler.handle(inst);
00137       }
00138    private:
00139       CIMInstanceResultHandlerIFC& _realHandler;
00140       const CIMOMHandleIFCRef& _lch;
00141       const CIMPropertyList _propertyList;
00142    };
00143 
00145    class _RHAssociatorNames : public AssocHelperResultHandlerIFC
00146    {
00147    public:
00148       _RHAssociatorNames(CIMObjectPathResultHandlerIFC& result,
00149          const CIMObjectPath& objectName,
00150          const CIMName& resultClass,
00151          const CIMName& role,
00152          const CIMName& resultRole)
00153       : AssocHelperResultHandlerIFC(objectName,resultClass ,role ,resultRole)
00154       , _realHandler(result)
00155       {
00156       }
00157    protected:
00158       virtual void assocAuxHandler(const CIMObjectPath &cop)
00159       {
00160          _realHandler.handle(cop);
00161       }
00162    private:
00163       CIMObjectPathResultHandlerIFC& _realHandler;
00164    };
00165 
00167    class _RHReferences : public CIMInstanceResultHandlerIFC
00168    {
00169    public:
00170       _RHReferences(CIMInstanceResultHandlerIFC& realHandler,
00171          const CIMPropertyList& propertyList)
00172       : _realHandler(realHandler)
00173       , _propertyList(propertyList)
00174       {
00175       }
00176 
00177       void doHandle(const CIMInstance& inst)
00178       {
00179          CIMInstance rval = inst.clone(_propertyList);
00180          _realHandler.handle(rval);
00181       }
00182    private:
00183       CIMInstanceResultHandlerIFC& _realHandler;
00184       const CIMPropertyList _propertyList;
00185    };
00186 
00188    class _RHReferenceNames : public CIMInstanceResultHandlerIFC
00189    {
00190    public:
00191       _RHReferenceNames(CIMObjectPathResultHandlerIFC& realHandler, const String& ns)
00192       : _realHandler(realHandler)
00193       , _ns(ns)
00194       {
00195       }
00196       void doHandle(const CIMInstance& inst)
00197       {
00198          CIMObjectPath cop(_ns, inst);
00199          _realHandler.handle(cop);
00200       }
00201    private:
00202       CIMObjectPathResultHandlerIFC& _realHandler;
00203       String _ns;
00204    };
00205 
00206 } // end anonymous namespace
00207 
00208 void
00209 BI1SimpleAssociatorProviderIFC::associators(const ProviderEnvironmentIFCRef &env,
00210    CIMInstanceResultHandlerIFC &result,
00211    const String &ns,
00212    const CIMObjectPath &objectName,
00213    const CIMName &assocClass,
00214    const CIMName &resultClass,
00215    const CIMName &role,
00216    const CIMName &resultRole,
00217    const CIMPropertyList& propertyList)
00218 {
00219 
00220    CIMOMHandleIFCRef lch = env->getCIMOMHandle();
00221    CIMClass theAssocClass = lch->getClass(ns, assocClass);
00222    _RHAssociators rh(result, objectName, resultClass, role, resultRole,
00223       lch, propertyList);
00224 
00225    doReferences(env, rh, ns, objectName, theAssocClass, resultClass,
00226       role, resultRole);
00227 }
00228 
00229 void
00230 BI1SimpleAssociatorProviderIFC::associatorNames(const ProviderEnvironmentIFCRef &env,
00231    CIMObjectPathResultHandlerIFC &result,
00232    const String &ns,
00233    const CIMObjectPath &objectName,
00234    const CIMName &assocClass,
00235    const CIMName &resultClass,
00236    const CIMName &role,
00237    const CIMName &resultRole)
00238 {
00239 
00240 
00241    _RHAssociatorNames rh(result, objectName, resultClass, role, resultRole);
00242 
00243    CIMOMHandleIFCRef lch = env->getCIMOMHandle();
00244    CIMClass theAssocClass = lch->getClass(ns, assocClass);
00245 
00246    doReferences(env, rh, ns, objectName, theAssocClass, resultClass,
00247       role, resultRole);
00248 }
00249 
00250 void
00251 BI1SimpleAssociatorProviderIFC::references(const ProviderEnvironmentIFCRef
00252    &env, CIMInstanceResultHandlerIFC &result,
00253    const String &ns,
00254    const CIMObjectPath &objectName,
00255    const CIMName &resultClass,
00256    const CIMName &role,
00257    const CIMPropertyList& propertyList)
00258 {
00259 
00260    CIMOMHandleIFCRef lch = env->getCIMOMHandle();
00261    CIMClass theAssocClass = lch->getClass(ns, resultClass);
00262 
00263    _RHReferences rh(result, propertyList );
00264    doReferences(env, rh, ns, objectName, theAssocClass, "", role, "");
00265 }
00280 void
00281 BI1SimpleAssociatorProviderIFC::referenceNames(const ProviderEnvironmentIFCRef &env,
00282    CIMObjectPathResultHandlerIFC &result,
00283    const String &ns,
00284    const CIMObjectPath &objectName,
00285    const CIMName &resultClass,
00286    const CIMName &role)
00287 {
00288 
00289    CIMOMHandleIFCRef lch = env->getCIMOMHandle();
00290    CIMClass theAssocClass = lch->getClass(ns, resultClass);
00291    _RHReferenceNames rh(result,ns);
00292    doReferences(env, rh,ns ,objectName , theAssocClass,"",role, "");
00293 }
00294 
00295 }

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