Check Class Description With the class initialized, it is possible to check that a class description in a delta or other repository file, matches the class. The description is supplied as a hzChain which is obtained by reading the file or file header. This function loads the hzChain into an XML document and then extracts tags describing the class and its members. Write out XML fragment describing the data class to the supplied chain. Note that as the class description is likely to be part of an Application Delta Profile, the supplied chain is not pre-cleared by this function. Read a <class> tag on behalf of the hdbADProfile::Import function.
| Return Type | Function name | Arguments |
|---|---|---|
| hzEcode | hdbClass::DescCheck | (hzChain&,hzChain&,) |
Declared in file: hzDatabase.h
Defined in file : hdbClass.cpp
Function Logic:
Function body:
hzEcode hdbClass::DescCheck (hzChain& report)hzChain& desc,
{
// Check Class Description
//
// With the class initialized, it is possible to check that a class description in a delta or other repository file, matches the class. The description is
// supplied as a hzChain which is obtained by reading the file or file header. This function loads the hzChain into an XML document and then extracts tags
// describing the class and its members.
//
// Write out XML fragment describing the data class to the supplied chain. Note that as the class description is likely to be part of an Application Delta
// Profile, the supplied chain is not pre-cleared by this function.
//
// Arguments: 1) report To report errors
// 2) desc The supplied description
//
// Returns: E_FORMAT If there are ANY descrepancies (details in report)
// E_OK If the description matches the class
//
// Read a <class> tag on behalf of the hdbADProfile::Import function.
_hzfunc("hdbClass::DescCheck") ;
const hdbDatatype* pType ; // Data type
hzDocXml doc ; // XML document
hzXmlNode* pRoot ; // XML root node
hzXmlNode* pN2 ; // Second level node
hzAttrset ai ; // Attribute iterator
hzString cname ; // Class name
hzString str_id ; // Member id
hzString str_uid ; // Member uid
hzString str_min ; // Member minPop
hzString str_max ; // Member minPop
hzString str_typ ; // Member data type
hzString str_sub ; // Member sub class
hzString str_nam ; // Member name
hzEcode rc = E_OK ; // Return code
int64_t n ; // Integer test value
// Load description into XML doc
rc = doc.Load(desc) ;
if (rc != E_OK)
{ report << "Could not load XML document with supplied description\n" ; return rc ; }
pRoot = doc.GetRoot() ;
if (!pRoot)
{ report << "No XML root found in supplied description\n" ; return E_CONFIG ; }
if (!pRoot->NameEQ("class"))
{ report << "Expected first tag of <class>\n" ; return E_CONFIG ; }
// Obtain <class> attributes
str_id = cname = (char*) 0;
for (ai = pRoot ; ai.Valid() ; ai.Advance())
{
if (ai.NameEQ("id")) str_id = ai.Value() ;
else if (ai.NameEQ("name")) cname = ai.Value() ;
else
{ rc = E_CONFIG ; report.Printf("Line %d: <class> bad param %s=%s\n", pRoot->Line(), ai.Name(), ai.Value()) ; break ; }
}
// Check class name and id
if (!cname)
report << "No class name supplied\n" ;
else
{
if (cname != m_Typename)
report.Printf("Name mismatch. Class actual name is %s. Description names class as %s.\n", *m_Typename, *cname) ;
}
if (!str_id)
report << "No class id supplied\n" ;
else
{
if (!IsInteger(n, *str_id))
report.Printf("Illegal Class ID: Must be integer. (%s)\n", *str_id) ;
if (n != m_ClassUID)
report.Printf("Class Delta ID mismatch. Class actual %d: Description id is %s\n", m_ClassUID, *str_id) ;
}
// Read in members
for (pN2 = pRoot->GetFirstChild() ; pN2 ; pN2 = pN2->Sibling())
{
if (!pN2->NameEQ("member"))
{ report.Printf("<class> only <member> allowed. %s unexpected\n", pN2->txtName()) ; continue ; }
str_id = str_uid = str_min = str_max = str_typ = str_sub = str_nam = (char*) 0;
// Read in member parameters
for (ai = pN2 ; ai.Valid() ; ai.Advance())
{
if (ai.NameEQ("posn")) str_id = ai.Value() ;
else if (ai.NameEQ("uid")) str_uid = ai.Value() ;
else if (ai.NameEQ("min")) str_min = ai.Value() ;
else if (ai.NameEQ("max")) str_max = ai.Value() ;
else if (ai.NameEQ("datatype")) str_typ = ai.Value() ;
else if (ai.NameEQ("subclass")) str_sub = ai.Value() ;
else if (ai.NameEQ("name")) str_nam = ai.Value() ;
else
report.Printf("Line %d: <member> bad param %s=%s\n", pN2->Line(), ai.Name(), ai.Value()) ;
}
if (!str_id) report.Printf("No member position suplied (line %d)\n", pN2->Line()) ;
if (!str_uid) report.Printf("No member UID suplied (line %d)\n", pN2->Line()) ;
if (!str_min) report.Printf("No member min pop suplied (line %d)\n", pN2->Line()) ;
if (!str_max) report.Printf("No member max pop suplied (line %d)\n", pN2->Line()) ;
if (!str_nam) report.Printf("No member name suplied (line %d)\n", pN2->Line()) ;
if (!IsInteger(n, *str_id)) report.Printf("Illegal member position: Must be integer 0+ (line %d)\n", pN2->Line()) ;
if (!IsInteger(n, *str_uid)) report.Printf("Illegal member ID: Must be integer 0+ (line %d)\n", pN2->Line()) ;
if (!IsInteger(n, *str_min)) report.Printf("Illegal member min-POP: Must be integer 0+ (line %d)\n", pN2->Line()) ;
if (!IsInteger(n, *str_max)) report.Printf("Illegal member max-POP: Must be integer 0+ (line %d)\n", pN2->Line()) ;
if (!str_typ)
str_typ = str_sub ;
pType = m_pADP->GetDatatype(str_typ) ;
if (!pType)
report.Printf("<member> No such data type or sub-class as %s\n", pN2->Line(), *str_typ) ;
}
if (report.Size())
return E_FORMAT ;
return E_OK ;
}