Main Page | Modules | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

XMLMetadataWriter Class Reference

MetadataWriter that writes metadata information to XML file. More...

#include <XMLMetadataWriter.h>

Inheritance diagram for XMLMetadataWriter:

Inheritance graph
[legend]
Collaboration diagram for XMLMetadataWriter:

Collaboration graph
[legend]
List of all members.

Public Member Functions

virtual void initialize (const char *projectName, const char *locationCommonPart, IopcMappingType defaultMappingType, const void *implSpecificParam)
virtual int addClass (const char *className, const BaseClassesList &baseClasses, const ClassAttributeList &classAttributes, const char *sourceFileName, CStdString &tmpDataLocation, const char *hint, CStdString &warningsForUser, CStdString &errorForUser)
virtual int saveMetadata (const std::list< CStdString > &tmpDataLocations, const char *metadataLocation, CStdString &warningsForUser, CStdString &errorForUser)

Protected Member Functions

void generateTmpFileName (const char *cppFileName, CStdString &tmpFileName)
int loadTmpFiles (const std::list< CStdString > &tmpDataLocations, MWClassHierarchy *classes, CStdString &warningsForUser, CStdString &errorForUser)
int loadTmpFilesFromDirectory (const char *directory, MWClassHierarchy *classes, CStdString &warningsForUser, CStdString &errorForUser)
int loadTmpFile (const char *tmpFileName, MWClassHierarchy *classes, CStdString &warningsForUser, CStdString &errorForUser)
int writeXMLFile (const MWClassHierarchy &classes, const char *outputFileName, CStdString &warningsForUser, CStdString &errorForUser)
DOMNode * createClassNode (const FullClassInfo *classInfo, DOMDocument *doc, CStdString &warningsForUser, CStdString &errorForUser)

Static Protected Member Functions

int getLine (std::ifstream &input, CStdString &line)
void parseCommaSeparatedList (const char *csl, std::vector< CStdString > &values)

Protected Attributes

CStdString m_dtdFilePath

Detailed Description

MetadataWriter that writes metadata information to XML file.

After parsing a declaration of C++ class in IOPC SP addClass() method is called. This method saves given data in some temporal format in file <source_name>.iopc . Method saveMetadata() puts together information from the temporary files, check whether the data are consistent and write it as XML mapping file.

See also:
MetadataWriter


Member Function Documentation

void XMLMetadataWriter::initialize const char *  projectName,
const char *  locationCommonPart,
IopcMappingType  defaultMappingType,
const void *  implSpecificParam
[virtual]
 

Remembers all given parameters for future use.

This functions copies only implSpecificParam to m_dtdFilePath and calls MetadataWriter::initialize().

Parameters:
projectName See MetadataWriter::initialize().
locationCommonPart Directory in which both temporary files and target XML file should be created. If NULL, current directory will be used.
defaultMappingType See MetadataWriter::initialize().
implSpecificParam Contains path to DTD for XML mapping files (only path - without filename).

Reimplemented from MetadataWriter.

int XMLMetadataWriter::addClass const char *  className,
const BaseClassesList baseClasses,
const ClassAttributeList classAttributes,
const char *  sourceFileName,
CStdString &  tmpDataLocation,
const char *  hint,
CStdString &  warningsForUser,
CStdString &  errorForUser
[virtual]
 

Remembers class information in temporary file.

Name of temporary file is generated by generateTmpFileName().

If no classes have been added to the file by this instance of XMLMetadataWriter yet, old content of file is rewritten.

Temporary file consist of one or more class information. Information about one class has this format (indentation and ending commas are reguired):

project_name class_name 1st_base_class, ... n-th_base_class, 1st_attribute_name, 1st_attribute_type_as_string, 1_if_persistent_0_otherwise, .... n-th_attribute_name, ....

Parameters:
className See MetadataWriter::initialize().
baseClasses See MetadataWriter::initialize().
classAttributes See MetadataWriter::initialize().
sourceFileName File where this class have been found (.cpp file, not .h).
tmpDataLocation Return value of the function - name of the temporary file.
hint This parameter is ignored
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.

Implements MetadataWriter.

int XMLMetadataWriter::saveMetadata const std::list< CStdString > &  tmpDataLocations,
const char *  metadataLocation,
CStdString &  warningsForUser,
CStdString &  errorForUser
[virtual]
 

Puts together ("links") information from XMLMetadataWriter's temporary files, checks whether they are consistent, generates DB related information (table names, column names etc.) and writes all the data into XML file in format described by mapping.dtd.

Methods of class MWClassHierarchy are used to generate the DB related information and to check consistence of data (this includes test whether we have descriptions of all persistent parents of each persistent class, whether there aren't two different definitions of the same class etc.)

If tmpDataLocations is non-empty only files specified in this parameter are processed (if file name doesn't contain path, files are assumed to be in m_locationCommonPart directory).
If tmpDataLocations is empty m_locationCommonPart directory is scanned for files matching pattern given by METADATA_WRITER_TMP_FILE_NAME.

Note:
If m_locationCommonPart is empty, current directory is used instead.
Parameters:
tmpDataLocations List of names of files to be processed
metadataLocation Name of file to which the metadata should be saved. If name without path given, file will be saved in m_locationCommonPart directory. If NULL <project_name>_mapping.xml will be used.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.
See also:
loadTmpFiles(), writeXMLFile()

Implements MetadataWriter.

void XMLMetadataWriter::generateTmpFileName const char *  cppFileName,
CStdString &  tmpFileName
[protected]
 

Generates name of XMLMetadataWriter's temporary file.

The filename is created using METADATA_WRITER_TMP_FILE_NAME and cppFileName - currently <source_name>.iopc is used.

Parameters:
cppFileName Input - name of source file.
tmpFileName Output - name of XMLMetadataWriter's temporary file (including path if m_locationCommonPart is non-empty or cppFileName contains path).

int XMLMetadataWriter::loadTmpFiles const std::list< CStdString > &  tmpDataLocations,
MWClassHierarchy classes,
CStdString &  warningsForUser,
CStdString &  errorForUser
[protected]
 

Loads XMLMetadataWriter's temporary files. Acquired data are added to classes.

Precise description which files will be loaded can be found in saveMetadata().

Parameters:
tmpDataLocations See saveMetadata().
classes Object to which acquired data should be added.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.
See also:
loadTmpFilesFromDirectory(), loadTmpFile()

int XMLMetadataWriter::loadTmpFilesFromDirectory const char *  directory,
MWClassHierarchy classes,
CStdString &  warningsForUser,
CStdString &  errorForUser
[protected]
 

Loads all XMLMetadataWriter's temporary files in given directory. Acquired data are added to classes.

Uses METADATA_WRITER_TMP_FILE_NAME to recognize XMLMetadataWriter's temporary files.

Parameters:
directory Directory to be scanned for the files. If empty, current directory is scanned.
classes Object to which acquired data should be added.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.
See also:
loadTmpFile()

int XMLMetadataWriter::loadTmpFile const char *  tmpFileName,
MWClassHierarchy classes,
CStdString &  warningsForUser,
CStdString &  errorForUser
[protected]
 

Adds data from XMLMetadataWriter's temporary file tmpFileName to classes.

Structure of the file is described in addClass().

Uses classes' FullClassInfo::otherInfo to store name of the file, in which the class have been seen for the first time. This is needed to provide user detailed error description if two different classes with the same name are found.

Parameters:
tmpFileName File to be loaded.
classes Object to which acquired data should be added.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.

int XMLMetadataWriter::writeXMLFile const MWClassHierarchy classes,
const char *  outputFileName,
CStdString &  warningsForUser,
CStdString &  errorForUser
[protected]
 

Writes information from classes to XML file outputFileName.

Parameters:
classes Object containing data to be written.
outputFileName Name of the XML file.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
0 if OK, non-zero in case of error.
See also:
createClassNode()

DOMNode * XMLMetadataWriter::createClassNode const FullClassInfo classInfo,
DOMDocument *  doc,
CStdString &  warningsForUser,
CStdString &  errorForUser
[protected]
 

Creates XML subtree for given classInfo. Used by writeXMLFile().

Note:
Doesn't ignore hints if they are present (although IOPC_SP doesn't produce them, so it's useless right now).
Parameters:
classInfo Description of class to be processed.
doc XML document to which created nodes should be added.
warningsForUser String used to send warning message(s) to user if needed.
errorForUser String used to send an error message to user if needed.
Returns:
XML subtree for given class, NULL in case of error.

int XMLMetadataWriter::getLine std::ifstream &  input,
CStdString &  line
[static, protected]
 

Reads line from input, returns it in line.

Helper function used by loadTmpFile().

Parameters:
input Input stream.
line Resulting string (this method doesn't trim it).
Returns:
0 if OK, non-zero if error occured or if end of file reached.

void XMLMetadataWriter::parseCommaSeparatedList const char *  csl,
std::vector< CStdString > &  values
[static, protected]
 

Parses comma separated string csl, returns it as list of strings values.

Helper function used by loadTmpFile().

Parameters:
csl Input comma separated string.
values Resulting list of strings.


Member Data Documentation

CStdString XMLMetadataWriter::m_dtdFilePath [protected]
 

Path (without filename) where DTD file for XML mapping files can be found.

Set by initialize().


The documentation for this class was generated from the following files:
Generated on Wed Aug 11 22:36:51 2004 for IOPC by Doxygen 1.3.6