*/
#include <cxxtest/TestSuite.h>
+#include <xmltooling/AbstractComplexElement.h>
#include <xmltooling/ElementProxy.h>
#include <xmltooling/exceptions.h>
#include <xmltooling/XMLObjectBuilder.h>
#include <xmltooling/io/AbstractXMLObjectUnmarshaller.h>
#include <xmltooling/impl/AnyElement.h>
#include <xmltooling/impl/UnknownElement.h>
-#ifndef XMLTOOLING_NO_XMLSEC
- #include <xmltooling/signature/Signature.h>
-#endif
#include <xmltooling/util/ParserPool.h>
#include <xmltooling/util/XMLConstants.h>
#include <xmltooling/util/XMLHelper.h>
#include <xmltooling/util/XMLObjectChildrenList.h>
+#ifndef XMLTOOLING_NO_XMLSEC
+ #include <xmltooling/signature/Signature.h>
+ using namespace xmlsignature;
+#endif
+
using namespace xmltooling;
using namespace std;
-extern ParserPool* validatingPool;
-extern ParserPool* nonvalidatingPool;
extern string data_path;
#if defined (_MSC_VER)
#pragma warning( disable : 4250 4251 )
#endif
-class SimpleXMLObject : public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller
+class SimpleXMLObject
+ : public AbstractComplexElement,
+ public AbstractDOMCachingXMLObject,
+ public AbstractXMLObjectMarshaller,
+ public AbstractXMLObjectUnmarshaller
{
+protected:
+ SimpleXMLObject(const SimpleXMLObject& src)
+ : AbstractXMLObject(src), AbstractComplexElement(src), AbstractDOMCachingXMLObject(src),
+ m_id(XMLString::replicate(src.m_id)) {
+#ifndef XMLTOOLING_NO_XMLSEC
+ m_children.push_back(NULL);
+ m_signature=m_children.begin();
+#endif
+ VectorOf(SimpleXMLObject) mine=getSimpleXMLObjects();
+ for (vector<SimpleXMLObject*>::const_iterator i=src.m_simples.begin(); i!=src.m_simples.end(); i++) {
+ mine.push_back((*i) ? (*i)->clone() : NULL);
+ }
+ }
+
public:
static const XMLCh NAMESPACE[];
static const XMLCh NAMESPACE_PREFIX[];
static const XMLCh ID_ATTRIB_NAME[];
SimpleXMLObject(
- const XMLCh* namespaceURI=NULL, const XMLCh* elementLocalName=NULL, const XMLCh* namespacePrefix=NULL
- ) : AbstractXMLObject(namespaceURI, elementLocalName, namespacePrefix), m_id(NULL), m_value(NULL) {
+ const XMLCh* nsURI=NULL, const XMLCh* localName=NULL, const XMLCh* prefix=NULL, const QName* schemaType=NULL
+ ) : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_id(NULL) {
#ifndef XMLTOOLING_NO_XMLSEC
m_children.push_back(NULL);
m_signature=m_children.begin();
virtual ~SimpleXMLObject() {
XMLString::release(&m_id);
- XMLString::release(&m_value);
}
-
+
+ SimpleXMLObject* clone() const {
+ auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
+ SimpleXMLObject* ret=dynamic_cast<SimpleXMLObject*>(domClone.get());
+ if (ret) {
+ domClone.release();
+ return ret;
+ }
+
+ return new SimpleXMLObject(*this);
+ }
+
+ const XMLCh* getXMLID() const { return getId(); }
const XMLCh* getId() const { return m_id; }
void setId(const XMLCh* id) { m_id=prepareForAssignment(m_id,id); }
- const XMLCh* getValue() const { return m_value; }
- void setValue(const XMLCh* value) { m_value=prepareForAssignment(m_value,value); }
+ const XMLCh* getValue() const { return getTextContent(); }
+ void setValue(const XMLCh* value) { setTextContent(value); }
#ifndef XMLTOOLING_NO_XMLSEC
Signature* getSignature() const {
return VectorOf(SimpleXMLObject)(this, m_simples, &m_children, m_children.end());
}
- SimpleXMLObject* clone() const {
- auto_ptr<XMLObject> domClone(AbstractDOMCachingXMLObject::clone());
- SimpleXMLObject* ret=dynamic_cast<SimpleXMLObject*>(domClone.get());
- if (ret) {
- domClone.release();
- return ret;
- }
-
- ret=new SimpleXMLObject();
- ret->m_namespaces=m_namespaces;
- ret->setId(m_id);
- ret->setValue(m_value);
- xmltooling::clone(m_children, ret->m_children);
- return ret;
+ const std::vector<SimpleXMLObject*>& getSimpleXMLObjects() const {
+ return m_simples;
}
+protected:
void marshallAttributes(DOMElement* domElement) const {
if(getId()) {
domElement->setAttributeNS(NULL, SimpleXMLObject::ID_ATTRIB_NAME, getId());
}
}
- void marshallElementContent(DOMElement* domElement) const {
- if(getValue()) {
- domElement->setTextContent(getValue());
- }
- }
-
void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {
SimpleXMLObject* simple=dynamic_cast<SimpleXMLObject*>(childXMLObject);
if (simple) {
throw UnmarshallingException("Unknown attribute cannot be processed by parent object.");
}
- void processElementContent(const XMLCh* elementContent) {
- setValue(elementContent);
- }
-
private:
XMLCh* m_id;
- XMLCh* m_value;
vector<SimpleXMLObject*> m_simples;
#ifndef XMLTOOLING_NO_XMLSEC
list<XMLObject*>::iterator m_signature;
}
SimpleXMLObject* buildObject(
- const XMLCh* namespaceURI, const XMLCh* elementLocalName, const XMLCh* namespacePrefix=NULL
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL
) const {
- return new SimpleXMLObject(namespaceURI,elementLocalName,namespacePrefix);
+ return new SimpleXMLObject(nsURI, localName, prefix, schemaType);
+ }
+
+ static SimpleXMLObject* newSimpleXMLObject() {
+ const SimpleXMLObjectBuilder* b = dynamic_cast<const SimpleXMLObjectBuilder*>(
+ XMLObjectBuilder::getBuilder(QName(SimpleXMLObject::NAMESPACE,SimpleXMLObject::LOCAL_NAME))
+ );
+ if (b)
+ return b->buildObject();
+ throw XMLObjectException("Unable to obtain typed builder for SimpleXMLObject.");
}
};