version 1.113, 2004/06/02 09:55:51
|
version 1.114, 2004/06/03 08:47:11
|
|
|
// Karl Schopmeyer(k.schopmeyer@opengroup.org) - extend ref function. | // Karl Schopmeyer(k.schopmeyer@opengroup.org) - extend ref function. |
// Robert Kieninger, IBM (kieningr@de.ibm.com) - Bugzilla 383 | // Robert Kieninger, IBM (kieningr@de.ibm.com) - Bugzilla 383 |
// Seema Gupta (gseema@in.ibm.com) - Bugzilla 281, Bugzilla 1313 | // Seema Gupta (gseema@in.ibm.com) - Bugzilla 281, Bugzilla 1313 |
|
// Adrian Schuur (schuur@de.ibm.com) - PEP 129 & 164 |
// Amit K Arora, IBM (amita@in.ibm.com) for PEP#101 | // Amit K Arora, IBM (amita@in.ibm.com) for PEP#101 |
// | // |
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
|
|
#include <Pegasus/Common/Pair.h> | #include <Pegasus/Common/Pair.h> |
#include <Pegasus/Common/FileSystem.h> | #include <Pegasus/Common/FileSystem.h> |
#include <Pegasus/Common/InternalException.h> | #include <Pegasus/Common/InternalException.h> |
#include <Pegasus/Common/XmlReader.h> |
|
#include <Pegasus/Common/XmlWriter.h> |
|
#include <Pegasus/Common/DeclContext.h> | #include <Pegasus/Common/DeclContext.h> |
#include <Pegasus/Common/Resolver.h> | #include <Pegasus/Common/Resolver.h> |
#include <Pegasus/Common/System.h> | #include <Pegasus/Common/System.h> |
|
|
#include <Pegasus/Common/MessageLoader.h> //l10n | #include <Pegasus/Common/MessageLoader.h> //l10n |
#include <Pegasus/Common/CommonUTF.h> | #include <Pegasus/Common/CommonUTF.h> |
| |
|
#include <Pegasus/Common/XmlStreamer.h> |
|
#include <Pegasus/Common/BinaryStreamer.h> |
|
#include <Pegasus/Common/AutoStreamer.h> |
|
|
#include "CIMRepository.h" | #include "CIMRepository.h" |
#include "RepositoryDeclContext.h" | #include "RepositoryDeclContext.h" |
#include "InstanceIndexFile.h" | #include "InstanceIndexFile.h" |
|
|
PEGASUS_NAMESPACE_BEGIN | PEGASUS_NAMESPACE_BEGIN |
| |
static const Uint32 _MAX_FREE_COUNT = 16; | static const Uint32 _MAX_FREE_COUNT = 16; |
|
static int binaryMode = 0; |
| |
// | // |
// The following _xx functions are local to the repository implementation | // The following _xx functions are local to the repository implementation |
|
|
template<class Object> | template<class Object> |
void _LoadObject( | void _LoadObject( |
const String& path, | const String& path, |
Object& object) |
Object& object, |
|
ObjectStreamer *streamer) |
{ | { |
PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject"); | PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_LoadObject"); |
| |
|
|
FileSystem::loadFileToMemory(data, realPath); | FileSystem::loadFileToMemory(data, realPath); |
data.append('\0'); | data.append('\0'); |
| |
XmlParser parser((char*)data.getData()); |
streamer->decode(data, 0, object); |
|
|
|
//XmlParser parser((char*)data.getData()); |
| |
XmlReader::getObject(parser, object); |
//XmlReader::getObject(parser, object); |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
|
// | // |
//////////////////////////////////////////////////////////////////////////////// | //////////////////////////////////////////////////////////////////////////////// |
| |
void _SaveObject(const String& path, Array<Sint8>& objectXml) |
void _SaveObject(const String& path, Array<Sint8>& objectXml, |
|
ObjectStreamer *streamer) |
{ | { |
PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject"); | PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::_SaveObject"); |
| |
|
|
} | } |
| |
#ifdef INDENT_XML_FILES | #ifdef INDENT_XML_FILES |
objectXml.append('\0'); |
streamer->indentedOut(os, objectXml, 2); |
XmlWriter::indentedPrint(os, objectXml.getData(), 2); |
// objectXml.append('\0'); |
|
// XmlWriter::indentedPrint(os, objectXml.getData(), 2); |
#else | #else |
os.write((char*)objectXml.getData(), objectXml.size()); | os.write((char*)objectXml.getData(), objectXml.size()); |
#endif | #endif |
|
|
{ | { |
PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository"); | PEG_METHOD_ENTER(TRC_REPOSITORY, "CIMRepository::CIMRepository"); |
| |
|
if (!binaryMode) { |
|
if (getenv("PEGASUS_BINARY_REPOSITORY")) binaryMode=1; |
|
else binaryMode=-1; |
|
} |
|
|
|
if (binaryMode>0) { |
|
streamer=new AutoStreamer(new BinaryStreamer(),BINREP_MARKER); |
|
((AutoStreamer*)streamer)->addReader(new XmlStreamer(),0); |
|
} |
|
|
|
else streamer=new XmlStreamer(); |
|
|
_context = new RepositoryDeclContext(this); | _context = new RepositoryDeclContext(this); |
_isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue( | _isDefaultInstanceProvider = (ConfigManager::getInstance()->getCurrentValue( |
"repositoryIsDefaultInstanceProvider") == "true"); | "repositoryIsDefaultInstanceProvider") == "true"); |
|
|
| |
try | try |
{ | { |
_LoadObject(classFilePath, cimClass); |
_LoadObject(classFilePath, cimClass, streamer); |
} | } |
catch (Exception& e) | catch (Exception& e) |
{ | { |
|
|
// -- Create the class file: | // -- Create the class file: |
| |
Array<Sint8> classXml; | Array<Sint8> classXml; |
XmlWriter::appendClassElement(classXml, cimClass); |
streamer->encode(classXml, cimClass); |
_SaveObject(classFilePath, classXml); |
//XmlWriter::appendClassElement(classXml, cimClass); |
|
_SaveObject(classFilePath, classXml,streamer); |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
|
| |
{ | { |
Array<Sint8> data; | Array<Sint8> data; |
XmlWriter::appendInstanceElement(data, cimInstance); |
streamer->encode(data, cimInstance); |
|
// XmlWriter::appendInstanceElement(data, cimInstance); |
size = data.size(); | size = data.size(); |
| |
if (!InstanceDataFile::appendInstance(dataFilePath, data, index)) | if (!InstanceDataFile::appendInstance(dataFilePath, data, index)) |
|
|
// | // |
| |
Array<Sint8> classXml; | Array<Sint8> classXml; |
XmlWriter::appendClassElement(classXml, cimClass); |
streamer->encode(classXml, cimClass); |
_SaveObject(classFilePath, classXml); |
//XmlWriter::appendClassElement(classXml, cimClass); |
|
_SaveObject(classFilePath, classXml,streamer); |
| |
if (cimClass.isAssociation()) { | if (cimClass.isAssociation()) { |
// Remove from Association | // Remove from Association |
|
|
| |
{ | { |
Array<Sint8> out; | Array<Sint8> out; |
XmlWriter::appendInstanceElement(out, cimInstance); |
streamer->encode(out, cimInstance); |
|
//XmlWriter::appendInstanceElement(out, cimInstance); |
| |
newSize = out.size(); | newSize = out.size(); |
| |
|
|
{ | { |
if (!freeFlags[i]) | if (!freeFlags[i]) |
{ | { |
XmlParser parser(&(buffer[indices[i]])); |
Uint32 pos=(&(buffer[indices[i]]))-buffer; |
|
streamer->decode(data, pos, tmpInstance); |
| |
XmlReader::getObject(parser, tmpInstance); |
// XmlParser parser(&(buffer[indices[i]])); |
|
// |
|
// XmlReader::getObject(parser, tmpInstance); |
| |
Resolver::resolveInstance (tmpInstance, _context, nameSpace, | Resolver::resolveInstance (tmpInstance, _context, nameSpace, |
true); | true); |
|
|
| |
try | try |
{ | { |
_LoadObject(qualifierFilePath, qualifierDecl); |
_LoadObject(qualifierFilePath, qualifierDecl, streamer); |
} | } |
catch (CannotOpenFile&) | catch (CannotOpenFile&) |
{ | { |
|
|
// -- Save qualifier: | // -- Save qualifier: |
| |
Array<Sint8> qualifierDeclXml; | Array<Sint8> qualifierDeclXml; |
XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl); |
streamer->encode(qualifierDeclXml, qualifierDecl); |
_SaveObject(qualifierFilePath, qualifierDeclXml); |
//XmlWriter::appendQualifierDeclElement(qualifierDeclXml, qualifierDecl); |
|
_SaveObject(qualifierFilePath, qualifierDeclXml,streamer); |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
} | } |
|
|
// Convert XML into an actual object: | // Convert XML into an actual object: |
// | // |
| |
XmlParser parser((char*)data.getData()); |
streamer->decode(data, 0, object); |
XmlReader::getObject(parser, object); |
//XmlParser parser((char*)data.getData()); |
|
//XmlReader::getObject(parser, object); |
| |
PEG_METHOD_EXIT(); | PEG_METHOD_EXIT(); |
return true; | return true; |