summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthrall <thrall@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-07-15 18:41:19 +0000
committerthrall <thrall@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>2003-07-15 18:41:19 +0000
commit90650c1b53a78196e2a961b470da4c933f0963cc (patch)
tree396e8626f0826c49140e944435466ee329f8e7e8
parent2b74bc1f41c0c59c6ec033a87d6159d7debc3578 (diff)
downloadATCD-90650c1b53a78196e2a961b470da4c933f0963cc.tar.gz
Implemented parsing of Test_Config XML based on the testconfig.dtd XML descriptor
-rw-r--r--TAO/orbsvcs/tests/EC_Config/Test_Handler.cpp355
-rw-r--r--TAO/orbsvcs/tests/EC_Config/Test_Handler.h11
2 files changed, 300 insertions, 66 deletions
diff --git a/TAO/orbsvcs/tests/EC_Config/Test_Handler.cpp b/TAO/orbsvcs/tests/EC_Config/Test_Handler.cpp
index d19d542bf46..9ff5baf2bbc 100644
--- a/TAO/orbsvcs/tests/EC_Config/Test_Handler.cpp
+++ b/TAO/orbsvcs/tests/EC_Config/Test_Handler.cpp
@@ -1,14 +1,24 @@
// -*- C++ -*- $Id$
#include "Test_Handler.h"
+
+#include "TestConfig.h"
#include "ace/ACE.h"
#include "ace/Log_Msg.h"
-// TODO Create test_config_t's based on XML using entities described in testconfig.dtd
+#include <stdlib.h> //for atol
+#include <sstream> //for istringstream
+
+// TODO Indicate error if missing test_config_t field, empty cdata for leaf elements
Test_Handler::Test_Handler (ACEXML_Char* fileName)
: configs_(0),
- fileName_(ACE::strnew (fileName))
+ fileName_(ACE::strnew (fileName)),
+ didtype_(0), //false
+ didperiod_(0),
+ didcrit_(0),
+ didimp_(0),
+ didnum_(0)
{
}
@@ -30,109 +40,176 @@ Test_Handler::get_configs (void) const
void
-Test_Handler::characters (const ACEXML_Char *cdata,
- int start,
- int end ACEXML_ENV_ARG_DECL_NOT_USED)
+Test_Handler::characters (const ACEXML_Char * cdata,
+ int ,
+ int ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event characters () ** start: %d end: %d ***************\n%s\n- End event characters () ---------------\n"),
- start, end, cdata));
+ TestConfig::test_config_t *curcfg = 0; //current test_config_t is last in set
+ std::istringstream iss(cdata);
+
+ switch (this->scope_.top())
+ {
+ case TYPE:
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("TYPE Characters: %s\n"),cdata));
+ curcfg = this->configs_[this->configs_.size()-1];
+ if (curcfg == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("No existing test_config_t")));
+ }
+ if ((iss >> curcfg->type) == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("Invalid number format")));
+ }
+ this->didtype_ = 1; //true
+ break;
+ case PERIOD:
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("PERIOD Characters: %s\n"),cdata));
+ curcfg = this->configs_[this->configs_.size()-1];
+ if (curcfg == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("No existing test_config_t")));
+ }
+ if ((iss >> curcfg->period) == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("Invalid number format")));
+ }
+ this->didperiod_ = 1; //true
+ break;
+ case NUM_ENTITIES:
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("NUM_ENTITIES Characters: %s\n"),cdata));
+ curcfg = this->configs_[this->configs_.size()-1];
+ if (curcfg == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("No existing test_config_t")));
+ }
+ if ((iss >> curcfg->num_entities) == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT ("Invalid number format")));
+ }
+ this->didnum_ = 1; //true
+ break;
+ case CRITICALITY:
+ case IMPORTANCE:
+ case TEST_CONFIG_T:
+ case TESTCONFIG:
+ default:
+ //ignore characters outside leaf elements
+ /*
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Ignoring characters outside leaf elements: %s\n"),
+ cdata));
+ */
+ break;
+ }
}
void
Test_Handler::endDocument (ACEXML_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
+ // Print out test_config_t's:
+ char *cfg_format = "{%10d, %10d, %10d, %10d, %10d }";
+ for (size_t i=0; i<this->configs_.size(); ++i) {
+ TestConfig::test_config_t *cfg = this->configs_[i];
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event endDocument () ***************\n")));
+ if (i!=0)
+ {
+ //finish previous line
+ ACE_DEBUG ((LM_DEBUG, "\n"));
+ }
+ ACE_DEBUG ((LM_DEBUG, cfg_format,
+ cfg->type,
+ cfg->period,
+ cfg->criticality,
+ cfg->importance,
+ cfg->num_entities));
+ }
+ //finish last line
+ ACE_DEBUG ((LM_DEBUG, "\n"));
}
void
-Test_Handler::endElement (const ACEXML_Char *uri,
- const ACEXML_Char *name,
- const ACEXML_Char *qName
- ACEXML_ENV_ARG_DECL_NOT_USED)
- ACE_THROW_SPEC ((ACEXML_SAXException))
+Test_Handler::endElement (const ACEXML_Char *,
+ const ACEXML_Char *,
+ const ACEXML_Char *
+ ACEXML_ENV_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event endElement (%s, %s, %s) ***************\n"),
- uri, name, qName));
+ if (this->scope_.empty() == 1)
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Element end outside of any scope")));
+ }
+ else
+ {
+ if (this->scope_.top() == TEST_CONFIG_T)
+ {
+ //check that all leaf elements were there
+ if (this->didtype_ == 0
+ || this->didperiod_ == 0
+ || this->didcrit_ == 0
+ || this->didimp_ == 0
+ || this->didnum_ == 0)
+ {
+ ACEXML_THROW(ACEXML_SAXException(ACE_TEXT("Missing leaf element "
+ "(TYPE, PERIOD, CRITICALITY, "
+ "IMPORTANCE, or NUM_ENTITIES)")));
+ }
+ }
+ this->scope_.pop();
+ /*
+ ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Popped scope; new top is %d\n"),
+ this->scope_.empty() ? -1 : this->scope_.top()));
+ */
+ }
}
void
-Test_Handler::endPrefixMapping (const ACEXML_Char *prefix
- ACEXML_ENV_ARG_DECL_NOT_USED)
- ACE_THROW_SPEC ((ACEXML_SAXException))
+Test_Handler::endPrefixMapping (const ACEXML_Char *
+ ACEXML_ENV_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event endPrefixMapping (%s) ***************\n"),
- prefix));
+ // no-op
}
void
Test_Handler::ignorableWhitespace (const ACEXML_Char *,
- int,
- int
- ACEXML_ENV_ARG_DECL_NOT_USED)
- ACE_THROW_SPEC ((ACEXML_SAXException))
+ int,
+ int
+ ACEXML_ENV_ARG_DECL_NOT_USED)
+ ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event ignorableWhitespace () ***************\n")));
+ // no-op
}
void
-Test_Handler::processingInstruction (const ACEXML_Char *target,
- const ACEXML_Char *data
+Test_Handler::processingInstruction (const ACEXML_Char *,
+ const ACEXML_Char *
ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event processingInstruction (%s, %s) ***************\n"),
- target, data));
+ // no-op
}
void
Test_Handler::setDocumentLocator (ACEXML_Locator * locator)
{
-
this->locator_ = locator;
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event setDocumentLocator () ***************\n")));
}
void
-Test_Handler::skippedEntity (const ACEXML_Char *name
+Test_Handler::skippedEntity (const ACEXML_Char *
ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event skippedEntity (%s) ***************\n"),
- name));
+ // no-op
}
void
Test_Handler::startDocument (ACEXML_ENV_SINGLE_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event startDocument () ***************\n")));
+ // no-op
}
void
@@ -143,8 +220,7 @@ Test_Handler::startElement (const ACEXML_Char *uri,
ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
-
-
+ /*
ACE_DEBUG ((LM_DEBUG,
ACE_TEXT ("* Event startElement (%s, %s, %s) ***************\n"),
uri, name, qName));
@@ -156,17 +232,164 @@ Test_Handler::startElement (const ACEXML_Char *uri,
ACE_TEXT (" %s = \"%s\"\n"),
alist->getQName (i), alist->getValue (i)));
}
+ */
+ ACE_UNUSED_ARG(uri);
+ ACE_UNUSED_ARG(name);
+
+ element newscope;
+ if (ACE_OS_String::strcmp (qName, ACE_TEXT ("type")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing TYPE scope\n")));
+ newscope = TYPE;
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("period")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing PERIOD scope\n")));
+ newscope = PERIOD;
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("criticality")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing CRITICALITY scope\n")));
+ newscope = CRITICALITY;
+ if (alist != 0)
+ {
+ const ACEXML_Char *val = alist->getValue(ACE_TEXT("value"));
+ if (val != 0)
+ {
+ TestConfig::test_config_t *curcfg = 0; //current test_config_t is last in set
+ curcfg = this->configs_[this->configs_.size()-1];
+ if (curcfg == 0)
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("No existing test_config_t")));
+ }
+ if (ACE_OS_String::strcmp(val,ACE_TEXT("VERY_LOW")) == 0)
+ {
+ curcfg->criticality = TestConfig::VERY_LOW_CRITICALITY;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("LOW")) == 0)
+ {
+ curcfg->criticality = TestConfig::LOW_CRITICALITY;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("MEDIUM")) == 0)
+ {
+ curcfg->criticality = TestConfig::MEDIUM_CRITICALITY;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("HIGH")) == 0)
+ {
+ curcfg->criticality = TestConfig::HIGH_CRITICALITY;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("VERY_HIGH")) == 0)
+ {
+ curcfg->criticality = TestConfig::VERY_HIGH_CRITICALITY;
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Invalid value for \"value\""
+ " attribute for criticality")));
+ }
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Invalid attributes for criticality")));
+ }
+ this->didcrit_ = 1; //true
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("No attributes for criticality")));
+ }
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("importance")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing IMPORTANCE scope\n")));
+ newscope = IMPORTANCE;
+ if (alist != 0)
+ {
+ const ACEXML_Char *val = alist->getValue(ACE_TEXT("value"));
+ if (val != 0)
+ {
+ TestConfig::test_config_t *curcfg = 0; //current test_config_t is last in set
+ curcfg = this->configs_[this->configs_.size()-1];
+ if (curcfg == 0)
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("No existing test_config_t")));
+ }
+ if (ACE_OS_String::strcmp(val,ACE_TEXT("VERY_LOW")) == 0)
+ {
+ curcfg->importance = TestConfig::VERY_LOW_IMPORTANCE;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("LOW")) == 0)
+ {
+ curcfg->importance = TestConfig::LOW_IMPORTANCE;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("MEDIUM")) == 0)
+ {
+ curcfg->importance = TestConfig::MEDIUM_IMPORTANCE;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("HIGH")) == 0)
+ {
+ curcfg->importance = TestConfig::HIGH_IMPORTANCE;
+ }
+ else if (ACE_OS_String::strcmp(val,ACE_TEXT("VERY_HIGH")) == 0)
+ {
+ curcfg->importance = TestConfig::VERY_HIGH_IMPORTANCE;
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Invalid value for \"value\""
+ " attribute for importance")));
+ }
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Invalid attributes for importance")));
+ }
+ this->didimp_ = 1; //true
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("No attributes for importance")));
+ }
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("num_entities")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing NUM_ENTITIES scope\n")));
+ newscope = NUM_ENTITIES;
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("test_config_t")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing TEST_CONFIG_T scope\n")));
+ newscope = TEST_CONFIG_T;
+ //create test_config_t for filling in by the sub-elements of this element
+ TestConfig::test_config_t *newcfg = 0;
+ ACE_NEW(newcfg,TestConfig::test_config_t());
+ size_t cfgsize = this->configs_.size();
+ this->configs_.size(cfgsize+1);
+ this->configs_[cfgsize] = newcfg;
+ this->didtype_ = 0; //false
+ this->didperiod_ = 0; //false
+ this->didcrit_ = 0; //false
+ this->didimp_ = 0; //false
+ this->didnum_ = 0; //false
+ }
+ else if (ACE_OS_String::strcmp (qName, ACE_TEXT ("testconfig")) == 0)
+ {
+ //ACE_DEBUG ((LM_DEBUG, ACE_TEXT ("Pushing TESTCONFIG scope\n")));
+ newscope = TESTCONFIG;
+ }
+ else
+ {
+ ACEXML_THROW (ACEXML_SAXException (ACE_TEXT("Element start of unknown type")));
+ }
+ this->scope_.push(newscope);
}
void
-Test_Handler::startPrefixMapping (const ACEXML_Char * prefix,
- const ACEXML_Char * uri ACEXML_ENV_ARG_DECL_NOT_USED)
+Test_Handler::startPrefixMapping (const ACEXML_Char *,
+ const ACEXML_Char * ACEXML_ENV_ARG_DECL_NOT_USED)
ACE_THROW_SPEC ((ACEXML_SAXException))
{
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("* Event startPrefixMapping () ***************\n")));
- ACE_DEBUG ((LM_DEBUG,
- ACE_TEXT ("Prefix = %s, URI = %s\n"), prefix, uri));
+ // no-op
}
// Methods inherited from ACEXML_ErrorHandler.
diff --git a/TAO/orbsvcs/tests/EC_Config/Test_Handler.h b/TAO/orbsvcs/tests/EC_Config/Test_Handler.h
index 5c2b332a255..d7c224309f3 100644
--- a/TAO/orbsvcs/tests/EC_Config/Test_Handler.h
+++ b/TAO/orbsvcs/tests/EC_Config/Test_Handler.h
@@ -19,6 +19,10 @@
#include "TestConfig.h"
+#include <stack>
+
+enum element { TESTCONFIG,TEST_CONFIG_T,TYPE,PERIOD,CRITICALITY,IMPORTANCE,NUM_ENTITIES };
+
/**
* @class Test_Handler
*
@@ -30,6 +34,9 @@
class Test_Handler : public ACEXML_ContentHandler, public ACEXML_ErrorHandler
{
public:
+
+ typedef std::stack<element> STACK;
+
/*
* Default constructor.
*/
@@ -163,6 +170,10 @@ private:
ACEXML_Char* fileName_;
ACEXML_Locator* locator_;
+ STACK scope_;
+
+ int didtype_,didperiod_,didcrit_,didimp_,didnum_;
+ //for each test_config_t, whether the leaf element was processed or not
};
#endif /* TEST_HANDLER_H */