1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
|
// $Id: Debug_Element_Builder.cpp 91257 2010-08-03 11:54:04Z johnnyw $
#include "ACEXML/common/SAXExceptions.h"
#include "ACEXML/parser/debug_validator/Debug_Element_Builder.h"
ACEXML_Debug_Element_Builder::ACEXML_Debug_Element_Builder ()
: type_ (UNDEFINED),
root_ (0)
{
}
ACEXML_Debug_Element_Builder::~ACEXML_Debug_Element_Builder ()
{
delete this->root_;
}
int
ACEXML_Debug_Element_Builder::setElementName (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *qName)
{
this->element_.set (qName, 0);
return 0;
}
int
ACEXML_Debug_Element_Builder::setContentType (CONTENT_TYPE type)
{
if (this->type_ == UNDEFINED)
{
this->type_ = type;
return 0;
}
ACEXML_THROW_RETURN (ACEXML_SAXParseException (ACE_TEXT("Element type redefinition in Debug_Validator.")), -1);
}
int
ACEXML_Debug_Element_Builder::insertMixedElement (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *qName)
{
ACEXML_Element_Tree_Name_Node *node = 0;
// @@ We should "throw" an exception here instead of returning -1.
ACE_NEW_RETURN (node,
ACEXML_Element_Tree_Name_Node (qName),
-1);
if (this->root_ == 0)
// @@ Memory leak if fail?
ACE_NEW_RETURN (this->root_,
ACEXML_Element_Tree_List_Node (),
-1);
return this->root_->insert (node);
}
int
ACEXML_Debug_Element_Builder::startChildGroup ()
{
ACEXML_Element_Tree_List_Node *lnode = 0;
ACE_NEW_RETURN (lnode,
ACEXML_Element_Tree_List_Node (),
-1);
if (this->root_ == 0)
{
this->root_ = lnode;
}
else
{
// @@ check error?
this->root_->insert (lnode);
}
this->active_list_.push (lnode);
return 0;
}
int
ACEXML_Debug_Element_Builder::endChildGroup (CARDINALITY )
{
this->active_list_.pop ();
return 0;
}
int
ACEXML_Debug_Element_Builder::setChoice ()
{
this->active_list_.top ()->set (ACEXML_Element_Tree_List_Node::CHOICE);
return 0;
}
int
ACEXML_Debug_Element_Builder::setSequence ()
{
this->active_list_.top ()->set (ACEXML_Element_Tree_List_Node::SEQUENCE);
return 0;
}
int
ACEXML_Debug_Element_Builder::insertElement (const ACEXML_Char *,
const ACEXML_Char *,
const ACEXML_Char *qName)
{
ACEXML_Element_Tree_Name_Node *node = 0;
// @@ We should "throw" an exception here instead of returning -1.
ACE_NEW_RETURN (node,
ACEXML_Element_Tree_Name_Node (qName),
-1);
return this->active_list_.top ()->insert (node);
}
void
ACEXML_Debug_Element_Builder::dump ()
{
cout << "<!ELEMENT " << this->element_;
// @@ Also dump element contentspec here.
switch (this->type_)
{
case EMPTY:
cout << "EMPTY";
break;
case ANY:
cout << "ANY";
break;
case MIXED:
case CHILDREN:
// @@ Dump the content of this->root_
cout << "*** not implemented ***";
break;
default:
cout << "*** Unidentified element type ***";
break;
}
cout << ">" << endl;
}
|