OW_MetaRepository2.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001 Center 7, 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 Center 7 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 Center 7, 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 #include "OW_config.h"
00031 #include "OW_MetaRepository2.hpp"
00032 #include "OW_DataStreams.hpp"
00033 #include "OW_CIMObjectPath.hpp"
00034 #include "OW_CIMProperty.hpp"
00035 #include "OW_CIMFlavor.hpp"
00036 #include "OW_CIMMethod.hpp"
00037 #include "OW_CIMClass.hpp"
00038 #include "OW_CIMValue.hpp"
00039 #include "OW_CIMQualifierType.hpp"
00040 #include "OW_CIMQualifier.hpp"
00041 #include "OW_Format.hpp"
00042 #include "OW_Assertion.hpp"
00043 #include "OW_Array.hpp"
00044 #include "OW_ConfigOpts.hpp"
00045 #include "OW_Logger.hpp"
00046 
00047 namespace OW_NAMESPACE
00048 {
00049 
00050 using namespace WBEMFlags;
00051 
00053 bool
00054 MetaRepository2::nameSpaceExists(const String& ns)
00055 {
00056    return false;
00057 }
00058 
00060 void
00061 MetaRepository2::enumNameSpace(StringResultHandlerIFC&, OperationContext&)
00062 {
00063 }
00064 
00066 MetaRepository2::~MetaRepository2()
00067 {
00068    try
00069    {
00070       close();
00071    }
00072    catch (...)
00073    {
00074       // logDebug or close could throw.
00075    }
00076 }
00078 void
00079 MetaRepository2::open(::DB_ENV* env, ::DB_TXN* txn)
00080 {
00081    m_namespaces.open("namespaces", env, txn, dbDatabase::E_NO_DUPLICATES);
00082    m_qualifiers.open("qualifiers", env, txn, dbDatabase::E_NO_DUPLICATES);
00083    m_classes.open("classes", env, txn, dbDatabase::E_NO_DUPLICATES);
00084    m_subclasslists.open("subclasslists", env, txn, dbDatabase::E_DUPLICATES);
00085    m_qualifierlists.open("qualifierlists", env, txn, dbDatabase::E_DUPLICATES);
00086 //     // Create root qualifier container
00087 //     HDBHandleLock hdl(this, getHandle());
00088 //     String qcontk(QUAL_CONTAINER);
00089 //     createRootNode(qcontk, hdl);
00090 //     qcontk += "/" + String("root");
00091 //     createRootNode(qcontk,hdl);
00092 //     // Create root class container
00093 //     qcontk = CLASS_CONTAINER;
00094 //     createRootNode(qcontk, hdl);
00095 //     qcontk += "/" + String("root");
00096 //     createRootNode(qcontk,hdl);
00097 }
00098 
00100 void
00101 MetaRepository2::close()
00102 {
00103    m_namespaces.close();
00104    m_qualifiers.close();
00105    m_classes.close();
00106    m_subclasslists.close();
00107    m_qualifierlists.close();
00108 }
00109 
00111 String
00112 MetaRepository2::_makeQualPath(const String& ns, const String& qualName)
00113 {
00114    OW_ASSERT(!ns.empty());
00115    OW_ASSERT(!qualName.empty());
00116 
00117    StringBuffer qp(ns);
00118    qp += "/";
00119    qp += qualName;
00120    
00121    return qp.releaseString();
00122 }
00124 String
00125 MetaRepository2::_makeClassPath(const String& ns,
00126    const String& className)
00127 {
00128    OW_ASSERT(!ns.empty());
00129    OW_ASSERT(!className.empty());
00130 
00131    StringBuffer cp(ns);
00132    cp += "/";
00133    cp += className;
00134    return cp.releaseString();
00135 }
00137 CIMQualifierType
00138 MetaRepository2::getQualifierType(const String& ns,
00139    const String& qualName)
00140 {
00141 //     throwIfNotOpen();
00142 //     String qkey = _makeQualPath(ns, qualName);
00143 //     CIMQualifierType qualType = m_qualCache.getFromCache(qkey);
00144 //     if (qualType)
00145 //     {
00146 //         return qualType;
00147 //     }
00148 //     GenericHDBRepository* prep;
00149 //     HDBHandle lhdl;
00150 //     if (phdl)
00151 //     {
00152 //         prep = NULL;
00153 //         lhdl = *phdl;
00154 //     }
00155 //     else
00156 //     {
00157 //         prep = this;
00158 //         lhdl = getHandle();
00159 //     }
00160 //     HDBHandleLock hdl(prep, lhdl);
00161 //     getCIMObject(qualType, qkey, hdl.getHandle());
00162 //     if (!qualType)
00163 //     {
00164 //         if (nameSpaceExists(QUAL_CONTAINER + "/" + ns))
00165 //         {
00166 //             OW_THROWCIMMSG(CIMException::NOT_FOUND,
00167 //                     format("CIM QualifierType \"%1\" not found in namespace: %2",
00168 //                         qualName, ns).c_str());
00169 //         }
00170 //         else
00171 //         {
00172 //             OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE,
00173 //                     ns.c_str());
00174 //         }
00175 //     }
00176 //     m_qualCache.addToCache(qualType, qkey);
00177    return CIMQualifierType();
00178 }
00179 #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00180 
00181 void
00182 MetaRepository2::enumQualifierTypes(const String& ns,
00183    CIMQualifierTypeResultHandlerIFC& result)
00184 {
00185 //     throwIfNotOpen();
00186 //     String nskey = _makeQualPath(ns, String());
00187 //     HDBHandleLock hdl(this, getHandle());
00188 //     HDBNode node = hdl->getNode(nskey);
00189 //     if (!node)
00190 //     {
00191 //         OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE, ns.c_str());
00192 //     }
00193 //     if (!node.areAllFlagsOn(HDBNSNODE_FLAG))
00194 //     {
00195 //         OW_THROW(HDBException, "Expected namespace node");
00196 //     }
00197 //     node = hdl->getFirstChild(node);
00198 //     while (node)
00199 //     {
00200 //         // If this is not a namespace node, assume it's a qualifier
00201 //         if (!node.areAllFlagsOn(HDBNSNODE_FLAG))
00202 //         {
00203 //             CIMQualifierType qual(CIMNULL);
00204 //             nodeToCIMObject(qual, node);
00205 //             result.handle(qual);
00206 //         }
00207 //         node = hdl->getNextSibling(node);
00208 //     }
00209 }
00211 bool
00212 MetaRepository2::deleteQualifierType(const String& ns,
00213    const String& qualName)
00214 {
00215 //     throwIfNotOpen();
00216 //     String qkey = _makeQualPath(ns, qualName);
00217 //     HDBHandleLock hdl(this, getHandle());
00218 //     HDBNode node = hdl->getNode(qkey);
00219 //     if (!node)
00220 //     {
00221 //         // Didn't find a node associated with the key
00222 //         return false;
00223 //     }
00224 //     // To ensure the node is a qualifier type, we create a qualifier
00225 //     // type from the node. If the node is not a qualifier type, an
00226 //     // exception will be thrown
00227 //     CIMQualifierType qt(CIMNULL);
00228 //     nodeToCIMObject(qt, node);
00229 //     // If we've hit this point, we know this is a qualifier
00230 //     hdl->removeNode(node);
00231 //     m_qualCache.removeFromCache(qkey);
00232    return true;
00233 }
00235 void
00236 MetaRepository2::_addQualifierType(const String& ns,
00237    const CIMQualifierType& qt)
00238 {
00239 //     throwIfNotOpen();
00240 //     if (!qt)
00241 //     {
00242 //         OW_THROWCIM(CIMException::INVALID_PARAMETER);
00243 //     }
00244 //     GenericHDBRepository* prep;
00245 //     HDBHandle lhdl;
00246 //     if (phdl)
00247 //     {
00248 //         prep = 0;
00249 //         lhdl = *phdl;
00250 //     }
00251 //     else
00252 //     {
00253 //         prep = this;
00254 //         lhdl = getHandle();
00255 //     }
00256 //     HDBHandleLock hdl(prep, lhdl);
00257 //     String qkey = _makeQualPath(ns, qt.getName());
00258 //     HDBNode node = hdl->getNode(qkey);
00259 //     if (node)
00260 //     {
00261 //         String msg(ns);
00262 //         if (!ns.empty())
00263 //         {
00264 //             msg += "/";
00265 //         }
00266 //         msg += qt.getName();
00267 //         OW_THROWCIMMSG(CIMException::ALREADY_EXISTS, msg.c_str());
00268 //     }
00269 //     HDBNode pnode = _getQualContainer(hdl, ns);
00270 //     if (!pnode)
00271 //     {
00272 //         OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE, ns.c_str());
00273 //     }
00274 //     addCIMObject(qt, qkey, pnode, hdl.getHandle());
00275 //     m_qualCache.addToCache(qt, qkey);
00276 }
00278 void
00279 MetaRepository2::setQualifierType(const String& ns,
00280    const CIMQualifierType& qt)
00281 {
00282 //     throwIfNotOpen();
00283 //     String qkey = _makeQualPath(ns, qt.getName());
00284 //     HDBHandleLock hdl(this, getHandle());
00285 //     HDBNode node = hdl->getNode(qkey);
00286 //     if (!node)
00287 //     {
00288 //         HDBHandle lhdl = hdl.getHandle();
00289 //         _addQualifierType(ns, qt, &lhdl);
00290 //     }
00291 //     else
00292 //     {
00293 //         // No ensure the node is a qualifier type before we delete it
00294 //         //CIMQualifierType tqt(CIMNULL);
00295 //         //nodeToCIMObject(tqt, node);
00296 //         // If we made it to this point, we know we have a qualifier type
00297 //         // So go ahead and update it.
00298 //         updateCIMObject(qt, node, hdl.getHandle());
00299 //         m_qualCache.removeFromCache(qkey);
00300 //         m_qualCache.addToCache(qt, qkey);
00301 //     }
00302 }
00303 #endif // #ifndef OW_DISABLE_QUALIFIER_DECLARATION
00304 
00305 CIMException::ErrNoType
00306 MetaRepository2::getCIMClass(const String& ns, const String& className,
00307    ELocalOnlyFlag localOnly,
00308    EIncludeQualifiersFlag includeQualifiers, EIncludeClassOriginFlag includeClassOrigin,
00309    const StringArray* propertyList,
00310    CIMClass& cc)
00311 {
00312 //     throwIfNotOpen();
00313 //     String ckey = _makeClassPath(ns, className);
00314 //     cc = m_classCache.getFromCache(ckey);
00315 //     if (!cc)
00316 //     {
00317 //         HDBHandleLock hdl(this, getHandle());
00318 //         HDBNode node = hdl->getNode(ckey);
00319 //         if (node)
00320 //         {
00321 //             // _getClassFromNode throws if unable to get class.
00322 //             cc = _getClassFromNode(node, hdl.getHandle());
00323 //             if (!cc)
00324 //             {
00325 //                 return CIMException::FAILED;
00326 //             }
00327 //             m_classCache.addToCache(cc, ckey);
00328 //         }
00329 //         else
00330 //         {
00331 //             return CIMException::NOT_FOUND;
00332 //         }
00333 //     }
00334 //     // now do some filtering
00335 //     if (propertyList || localOnly == true || includeQualifiers == false || includeClassOrigin == false)
00336 //     { // only clone if we have to
00337 //         StringArray lpropList;
00338 //         bool noProps = false;
00339 //         if (propertyList)
00340 //         {
00341 //             if (propertyList->size() == 0)
00342 //             {
00343 //                 noProps = true;
00344 //             }
00345 //             else
00346 //             {
00347 //                 lpropList = *propertyList;
00348 //             }
00349 //         }
00350 //         cc = cc.clone(localOnly, includeQualifiers, includeClassOrigin,
00351 //             lpropList, noProps);
00352 //         if (!cc) // clone doesn't throw
00353 //         {
00354 //             return CIMException::FAILED;
00355 //         }
00356 //     }
00357    return CIMException::SUCCESS;
00358 }
00359 #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00360 
00361 bool
00362 MetaRepository2::deleteClass(const String& ns, const String& className)
00363 {
00364 //     throwIfNotOpen();
00365 //     String ckey = _makeClassPath(ns, className);
00366 //     HDBHandleLock hdl(this, getHandle());
00367 //     HDBNode node = hdl->getNode(ckey);
00368 //     if (!node)
00369 //     {
00370 //         return false;
00371 //     }
00372 //     // Just to be safe, we will attempt to create an CIMClass object
00373 //     // from the node. If the node is not for an CIMClass, an exception
00374 //     // will be thrown.
00375 //     CIMClass theClassToDelete(CIMNULL);
00376 //     nodeToCIMObject(theClassToDelete, node);
00377 //     m_classCache.removeFromCache(ckey);     // Ensure class is not in the cache
00378 //     return hdl->removeNode(node);
00379    return false;
00380 }
00382 void
00383 MetaRepository2::createClass(const String& ns, CIMClass& cimClass)
00384 {
00385 //     throwIfNotOpen();
00386 //     HDBHandleLock hdl(this, getHandle());
00387 //     CIMQualifierArray qra = cimClass.getQualifiers();
00388 //     _resolveQualifiers(ns, qra, hdl.getHandle());
00389 //     cimClass.setQualifiers(qra);
00390 //     // Ensure integrity with any super classes
00391 //     HDBNode pnode = adjustClass(ns, cimClass, hdl.getHandle());
00392 //     // pnode is null if there is no parent class, so get namespace node
00393 //     if (!pnode)
00394 //     {
00395 //         if (!(pnode = getNameSpaceNode(hdl, CLASS_CONTAINER + "/" + ns)))
00396 //         {
00397 //             OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE,
00398 //                 ns.c_str());
00399 //         }
00400 //     }
00401 //     String ckey = _makeClassPath(ns, cimClass.getName());
00402 //     HDBNode node = hdl->getNode(ckey);
00403 //     if (node)
00404 //     {
00405 //         OW_THROWCIMMSG(CIMException::ALREADY_EXISTS, ckey.c_str());
00406 //     }
00407 //     UInt32 flags = (cimClass.isAssociation()) ? HDBCLSASSOCNODE_FLAG
00408 //         : 0;
00409 //     addCIMObject(cimClass, ckey, pnode, hdl.getHandle(), flags);
00410 }
00412 void
00413 MetaRepository2::modifyClass(const String& ns,
00414    const CIMClass& cimClass_)
00415 {
00416 //     throwIfNotOpen();
00417 //     HDBHandleLock hdl(this, getHandle());
00418 //     CIMClass cimClass(cimClass_);
00419 //     adjustClass(ns, cimClass, hdl.getHandle());
00420 //     String ckey = _makeClassPath(ns, cimClass.getName());
00421 //     HDBNode node = hdl->getNode(ckey);
00422 //     if (!node)
00423 //     {
00424 //         OW_THROWCIMMSG(CIMException::NOT_FOUND, ckey.c_str());
00425 //     }
00426 //     // Create an CIMClass object out of the node we just read to ensure
00427 //     // the data belongs to an CIMClass.
00428 //     CIMClass clsToUpdate(CIMNULL);
00429 //     nodeToCIMObject(clsToUpdate, node);
00430 //     // At this point we know we are updating an CIMClass
00431 //     m_classCache.removeFromCache(ckey);
00432 //     updateCIMObject(cimClass, node, hdl.getHandle());
00433 }
00434 #endif // #ifndef OW_DISABLE_SCHEMA_MANIPULATION
00435 
00436 void
00437 MetaRepository2::enumClass(const String& ns, const String& className,
00438    CIMClassResultHandlerIFC& result,
00439    EDeepFlag deep, ELocalOnlyFlag localOnly, EIncludeQualifiersFlag includeQualifiers,
00440    EIncludeClassOriginFlag includeClassOrigin)
00441 {
00442 //     throwIfNotOpen();
00443 //     HDBHandleLock hdl(this, getHandle());
00444 //     HDBNode pnode;
00445 //     if (!className.empty())
00446 //     {
00447 //         String ckey = _makeClassPath(ns, className);
00448 //         pnode = hdl->getNode(ckey);
00449 //         if (!pnode)
00450 //         {
00451 //             pnode = getNameSpaceNode(hdl, CLASS_CONTAINER + "/" + ns);
00452 //             if (!pnode)
00453 //             {
00454 //                 OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE, ns.c_str());
00455 //             }
00456 //             else
00457 //             {
00458 //                 OW_THROWCIMMSG(CIMException::INVALID_CLASS, className.c_str());
00459 //             }
00460 //         }
00461 //     }
00462 //     else
00463 //     {
00464 //         String ns2(ns);
00465 //         while (!ns2.empty() && ns2[0] == '/')
00466 //         {
00467 //             ns2 = ns2.substring(1);
00468 //         }
00469 //         pnode = getNameSpaceNode(hdl, CLASS_CONTAINER + "/" + ns2);
00470 //         if (!pnode)
00471 //         {
00472 //             OW_THROWCIMMSG(CIMException::INVALID_NAMESPACE, ns2.c_str());
00473 //         }
00474 //     }
00475 //     pnode = hdl->getFirstChild(pnode);
00476 //     while (pnode)
00477 //     {
00478 //         if (!pnode.areAllFlagsOn(HDBNSNODE_FLAG))
00479 //         {
00480 //             _getClassNodes(result, pnode, hdl.getHandle(), deep, localOnly,
00481 //                 includeQualifiers, includeClassOrigin);
00482 //         }
00483 //         pnode = hdl->getNextSibling(pnode);
00484 //     }
00485 }
00487 void
00488 MetaRepository2::enumClassNames(const String& ns, const String& className,
00489    StringResultHandlerIFC& result,
00490    EDeepFlag deep)
00491 {
00492 }
00493 #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00494 
00495 void
00496 MetaRepository2::deleteNameSpace(const String& nsName, OperationContext& context)
00497 {
00498 }
00499 
00500 ::DB_TXN* getTxn(OperationContext& context)
00501 {
00502    return 0; // TODO: write this
00503 }
00505 void
00506 MetaRepository2::createNameSpace(String ns, OperationContext& context)
00507 {
00508    if (ns.empty())
00509    {
00510       OW_THROWCIM(CIMException::INVALID_PARAMETER);
00511    }
00512    std::vector<unsigned char> tmpData;
00513    ::DB_TXN* txn = getTxn(context);
00514    if (m_namespaces.get(ns, tmpData, txn))
00515    {
00516       OW_THROWCIMMSG(CIMException::ALREADY_EXISTS,
00517          ns.c_str());
00518    }
00519    m_namespaces.put(ns, std::vector<unsigned char>(), txn);
00520    if (m_env->getLogger(COMPONENT_NAME)->getLogLevel() == E_DEBUG_LEVEL)
00521    {
00522       OW_LOG_DEBUG(m_env->getLogger(COMPONENT_NAME), Format("CIMRepository created namespace: %1", ns));
00523    }
00524 }
00525 #endif // #ifndef OW_DISABLE_INSTANCE_MANIPULATION
00526 
00527 MetaRepository2::MetaRepository2(const ServiceEnvironmentIFCRef& env)
00528    : m_env(env)
00529 {
00530    String maxCacheSizeOpt = env->getConfigItem(ConfigOpts::MAX_CLASS_CACHE_SIZE_opt, OW_DEFAULT_MAX_CLASS_CACHE_SIZE_S);
00531    try
00532    {
00533       m_classCache.setMaxCacheSize(maxCacheSizeOpt.toUInt32());
00534    }
00535    catch (const StringConversionException&)
00536    {
00537       m_classCache.setMaxCacheSize(OW_DEFAULT_MAX_CLASS_CACHE_SIZE_I);
00538    }
00539 }
00540 
00541 } // end namespace OW_NAMESPACE
00542 

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