#define __xmltooling_absattrextxmlobj_h__\r
\r
#include <map>\r
-#include <xmltooling/AbstractDOMCachingXMLObject.h>\r
+#include <xmltooling/AbstractXMLObject.h>\r
#include <xmltooling/AttributeExtensibleXMLObject.h>\r
\r
#if defined (_MSC_VER)\r
#ifndef __xmltooling_abseleproxy_h__\r
#define __xmltooling_abseleproxy_h__\r
\r
-#include <xmltooling/AbstractDOMCachingXMLObject.h>\r
+#include <xmltooling/AbstractXMLObject.h>\r
#include <xmltooling/ElementProxy.h>\r
\r
#if defined (_MSC_VER)\r
#include "signature/impl/XMLSecSignatureImpl.h"
#include "util/NDC.h"
#include "util/XMLConstants.h"
+#include "validation/Validator.h"
#ifdef HAVE_DLFCN_H
# include <dlfcn.h>
// default registrations
XMLObjectBuilder::registerDefaultBuilder(new UnknownElementBuilder());
- XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,KeyInfo::LOCAL_NAME),new KeyInfoBuilderImpl());
+
+ QName q(XMLConstants::XMLSIG_NS,KeyInfo::LOCAL_NAME);
+ XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl());
+ Validator::registerValidator(q,new KeyInfoSchemaValidator());
+ q=QName(XMLConstants::XMLSIG_NS,KeyInfo::TYPE_NAME);
+ XMLObjectBuilder::registerBuilder(q,new KeyInfoBuilderImpl());
+ Validator::registerValidator(q,new KeyInfoSchemaValidator());
+
+ q=QName(XMLConstants::XMLSIG_NS,KeyName::LOCAL_NAME);
+ XMLObjectBuilder::registerBuilder(q,new KeyNameBuilderImpl());
+ Validator::registerValidator(q,new KeyNameSchemaValidator());
+
+ q=QName(XMLConstants::XMLSIG_NS,MgmtData::LOCAL_NAME);
+ XMLObjectBuilder::registerBuilder(q,new MgmtDataBuilderImpl());
+ Validator::registerValidator(q,new MgmtDataSchemaValidator());
+
#ifndef XMLTOOLING_NO_XMLSEC
XMLObjectBuilder::registerBuilder(QName(XMLConstants::XMLSIG_NS,Signature::LOCAL_NAME),new XMLSecSignatureBuilder());
#endif
+
REGISTER_EXCEPTION_FACTORY(XMLParserException);
REGISTER_EXCEPTION_FACTORY(XMLObjectException);
REGISTER_EXCEPTION_FACTORY(MarshallingException);
virtual ~cname() {} \
XMLTOOLING_DOXYGEN(Type-specific clone method.) \
virtual cname* clone##cname() const=0; \
- XMLTOOLING_DOXYGEN(Element prefix) \
- static const XMLCh PREFIX[]; \
XMLTOOLING_DOXYGEN(Element local name) \
static const XMLCh LOCAL_NAME[]
}
/**
+ * Declares abstract get/set methods for named XML element content.
+ *
+ * @param proper the proper name to label the element's content
+ */
+#define DECL_XMLOBJECT_CONTENT(proper) \
+ XMLTOOLING_DOXYGEN(Returns proper.) \
+ virtual const XMLCh* get##proper() const=0; \
+ XMLTOOLING_DOXYGEN(Sets proper.) \
+ virtual void set##proper(const XMLCh* proper)=0
+
+/**
+ * Implements get/set methods and a private member for named XML element content.
+ *
+ * @param proper the proper name to label the element's content
+ */
+#define IMPL_XMLOBJECT_CONTENT(proper) \
+ private: \
+ XMLCh* m_##proper; \
+ public: \
+ const XMLCh* get##proper() const { \
+ return m_##proper; \
+ } \
+ void set##proper(const XMLCh* proper) { \
+ m_##proper = prepareForAssignment(m_##proper,proper); \
+ } \
+ protected: \
+ void marshallElementContent(DOMElement* domElement) const { \
+ if(get##proper()) { \
+ domElement->appendChild(domElement->getOwnerDocument()->createTextNode(get##proper())); \
+ } \
+ } \
+ void processElementContent(const XMLCh* elementContent) { \
+ set##proper(elementContent); \
+ }
+
+
+/**
* Implements cloning methods for an XMLObject specialization implementation class.
*
* @param cname the name of the XMLObject specialization
/**
* Begins the declaration of an XMLObjectBuilder specialization implementation class.
*
- * @param cname the name of the XMLObject specialization
- * @param namespaceURI the XML namespace of the default associated element
+ * @param cname the name of the XMLObject specialization
+ * @param namespaceURI the XML namespace of the default associated element
+ * @param namespacePrefix the XML namespace prefix of the default associated element
*/
-#define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI) \
+#define BEGIN_XMLOBJECTBUILDERIMPL(cname,namespaceURI,namespacePrefix) \
class XMLTOOL_DLLLOCAL cname##BuilderImpl : public cname##Builder { \
public: \
cname* buildObject( \
- const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL\
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix=NULL, const QName* schemaType=NULL \
) const; \
cname* buildObject() const { \
- return buildObject(namespaceURI,cname::LOCAL_NAME,cname::PREFIX); \
+ return buildObject(namespaceURI,cname::LOCAL_NAME,namespacePrefix); \
}
/**
+ * Begins the declaration of an XMLObjectBuilder specialization implementation class.
+ *
+ * @param cname the name of the XMLObject specialization
+ */
+#define IMPL_XMLOBJECTBUILDER(cname) \
+ cname* cname##BuilderImpl::buildObject( \
+ const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType \
+ ) const \
+ { \
+ return new cname##Impl(nsURI,localName,prefix,schemaType); \
+ }
+
+/**
* Ends the declaration of an XMLObjectBuilder specialization implementation class.
*/
#define END_XMLOBJECTBUILDERIMPL }
+/**
+ * Begins the declaration of a Validator specialization.
+ *
+ * @param cname the base name of the Validator specialization
+ */
+ #define BEGIN_XMLOBJECTVALIDATOR(cname) \
+ class cname##Validator : public Validator \
+ { \
+ public: \
+ virtual ~cname##Validator() {} \
+ Validator* clone() const { \
+ return new cname##Validator(); \
+ } \
+ void validate(const XMLObject* xmlObject) const
+
+/**
+ * Ends the declaration of a Validator specialization.
+ */
+#define END_XMLOBJECTVALIDATOR }
+
+
#include <utility>
namespace xmltooling {
* \r
* @throws MarshallingException thrown if there is a problem marshalling an attribute\r
*/\r
- virtual void marshallAttributes(DOMElement* domElement) const=0;\r
+ virtual void marshallAttributes(DOMElement* domElement) const {}\r
\r
/**\r
* Marshalls data from the XMLObject into content of the DOM Element.\r
* \r
* @param domElement the DOM element recieving the content\r
*/\r
- virtual void marshallElementContent(DOMElement* domElement) const=0;\r
+ virtual void marshallElementContent(DOMElement* domElement) const {}\r
};\r
\r
};\r
* \r
* @throws UnmarshallingException thrown if there is a problem adding the child to the parent\r
*/\r
- virtual void processChildElement(XMLObject* child, const DOMElement* childRoot)=0;\r
+ virtual void processChildElement(XMLObject* child, const DOMElement* childRoot) {}\r
\r
/**\r
* Called after an attribute has been unmarshalled so that it can be added to the XMLObject.\r
* \r
* @throws UnmarshallingException thrown if there is a problem adding the attribute to the XMLObject\r
*/\r
- virtual void processAttribute(const DOMAttr* attribute)=0;\r
+ virtual void processAttribute(const DOMAttr* attribute) {}\r
\r
/**\r
* Called if the element being unmarshalled contained textual content so that it can be added to the XMLObject.\r
* \r
* @param elementContent the Element's text content\r
*/\r
- virtual void processElementContent(const XMLCh* elementContent)=0;\r
+ virtual void processElementContent(const XMLCh* elementContent) {}\r
};\r
\r
};\r
*/\r
BEGIN_XMLOBJECT(KeyInfo,ElementProxy);\r
DECL_XMLOBJECT_ATTRIB(Id,ID);\r
+ static const XMLCh TYPE_NAME[];\r
END_XMLOBJECT;\r
\r
BEGIN_XMLOBJECTBUILDER(KeyInfo);\r
const XMLCh KeyInfo::LOCAL_NAME[] = {\r
chLatin_K, chLatin_e, chLatin_y, chLatin_I, chLatin_n, chLatin_f, chLatin_o, chNull\r
}; \r
- const XMLCh KeyInfo::PREFIX[] = {\r
- chLatin_d, chLatin_s, chNull\r
- };\r
+ const XMLCh KeyInfo::TYPE_NAME[] = {\r
+ chLatin_K, chLatin_e, chLatin_y, chLatin_I, chLatin_n, chLatin_f, chLatin_o,\r
+ chLatin_T, chLatin_y, chLatin_p, chLatin_e, chNull\r
+ }; \r
const XMLCh KeyInfo::ID_ATTRIB_NAME[] = {\r
chLatin_I, chLatin_d, chNull\r
};\r
#endif\r
\r
+ /**\r
+ * XMLObject representing XML Digital Signature, version 20020212, KeyName element.\r
+ */\r
+ BEGIN_XMLOBJECT(KeyName,XMLObject);\r
+ DECL_XMLOBJECT_CONTENT(Name);\r
+ END_XMLOBJECT;\r
+\r
+ BEGIN_XMLOBJECTBUILDER(KeyName);\r
+ END_XMLOBJECTBUILDER;\r
+\r
+#ifdef XMLTOOLING_DEFINE_CONSTANTS\r
+ const XMLCh KeyName::LOCAL_NAME[] = {\r
+ chLatin_K, chLatin_e, chLatin_y, chLatin_N, chLatin_a, chLatin_m, chLatin_e, chNull\r
+ }; \r
+#endif\r
+\r
+ /**\r
+ * XMLObject representing XML Digital Signature, version 20020212, MgmtData element.\r
+ */\r
+ BEGIN_XMLOBJECT(MgmtData,XMLObject);\r
+ DECL_XMLOBJECT_CONTENT(Data);\r
+ END_XMLOBJECT;\r
+\r
+ BEGIN_XMLOBJECTBUILDER(MgmtData);\r
+ END_XMLOBJECTBUILDER;\r
+\r
+#ifdef XMLTOOLING_DEFINE_CONSTANTS\r
+ const XMLCh MgmtData::LOCAL_NAME[] = {\r
+ chLatin_M, chLatin_g, chLatin_m, chLatin_t, chLatin_D, chLatin_a, chLatin_t, chLatin_a, chNull\r
+ }; \r
+#endif\r
};\r
\r
#endif /* __xmltooling_keyinfo_h__ */\r
#include "io/AbstractXMLObjectMarshaller.h"\r
#include "io/AbstractXMLObjectUnmarshaller.h"\r
#include "signature/impl/KeyInfoImpl.h"\r
-#include "util/NDC.h"\r
#include "util/XMLHelper.h"\r
#include "validation/AbstractValidatingXMLObject.h"\r
\r
-#include <log4cpp/Category.hh>\r
+#include <typeinfo.h>\r
\r
using namespace xmltooling;\r
-using namespace log4cpp;\r
using namespace std;\r
\r
#if defined (_MSC_VER)\r
\r
namespace xmltooling {\r
\r
- class XMLTOOL_DLLLOCAL KeyInfoImpl : public KeyInfo, public AbstractDOMCachingXMLObject, public AbstractElementProxy,\r
- public AbstractValidatingXMLObject, public AbstractXMLObjectMarshaller, public AbstractXMLObjectUnmarshaller\r
+ class XMLTOOL_DLLLOCAL KeyInfoImpl\r
+ : public KeyInfo,\r
+ public AbstractDOMCachingXMLObject,\r
+ public AbstractElementProxy,\r
+ public AbstractValidatingXMLObject,\r
+ public AbstractXMLObjectMarshaller,\r
+ public AbstractXMLObjectUnmarshaller\r
{\r
public:\r
virtual ~KeyInfoImpl() {}\r
\r
KeyInfoImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)\r
- : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Id(NULL) {}\r
+ : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Id(NULL) {\r
+ }\r
\r
- KeyInfoImpl(const KeyInfoImpl& src) : AbstractXMLObject(src), AbstractDOMCachingXMLObject(src),\r
- AbstractElementProxy(src), AbstractValidatingXMLObject(src), m_Id(XMLString::replicate(src.m_Id)) {\r
+ KeyInfoImpl(const KeyInfoImpl& src)\r
+ : AbstractXMLObject(src),\r
+ AbstractDOMCachingXMLObject(src),\r
+ AbstractElementProxy(src),\r
+ AbstractValidatingXMLObject(src),\r
+ m_Id(XMLString::replicate(src.m_Id)) {\r
+ \r
for (list<XMLObject*>::const_iterator i=src.m_children.begin(); i!=src.m_children.end(); i++) {\r
getXMLObjects().push_back((*i) ? (*i)->clone() : NULL);\r
}\r
}\r
\r
- IMPL_XMLOBJECT_ATTRIB(Id);\r
IMPL_XMLOBJECT_CLONE(KeyInfo);\r
+ IMPL_XMLOBJECT_ATTRIB(Id);\r
\r
protected:\r
void marshallAttributes(DOMElement* domElement) const {\r
}\r
}\r
\r
+ void processElementContent(const XMLCh* elementContent) {\r
+ setTextContent(elementContent);\r
+ }\r
+\r
void processChildElement(XMLObject* childXMLObject, const DOMElement* root) {\r
getXMLObjects().push_back(childXMLObject);\r
}\r
\r
void processAttribute(const DOMAttr* attribute) {\r
- if (XMLHelper::isNodeNamed(attribute, NULL, ID_ATTRIB_NAME))\r
+ if (XMLHelper::isNodeNamed(attribute, NULL, ID_ATTRIB_NAME)) {\r
setId(attribute->getValue());\r
+ static_cast<DOMElement*>(attribute->getParentNode())->setIdAttributeNode(attribute);\r
+ }\r
}\r
+ };\r
+ \r
+ class XMLTOOL_DLLLOCAL KeyNameImpl\r
+ : public KeyName,\r
+ public AbstractDOMCachingXMLObject,\r
+ public AbstractValidatingXMLObject,\r
+ public AbstractXMLObjectMarshaller,\r
+ public AbstractXMLObjectUnmarshaller\r
+ {\r
+ public:\r
+ virtual ~KeyNameImpl() {}\r
\r
- void processElementContent(const XMLCh* elementContent) {\r
- setTextContent(elementContent);\r
+ KeyNameImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)\r
+ : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Name(NULL) {\r
}\r
+ \r
+ KeyNameImpl(const KeyNameImpl& src)\r
+ : AbstractXMLObject(src),\r
+ AbstractDOMCachingXMLObject(src),\r
+ AbstractValidatingXMLObject(src),\r
+ m_Name(XMLString::replicate(src.m_Name)) {\r
+ }\r
+ \r
+ IMPL_XMLOBJECT_CLONE(KeyName);\r
+ IMPL_XMLOBJECT_CONTENT(Name);\r
+ };\r
+\r
+ class XMLTOOL_DLLLOCAL MgmtDataImpl\r
+ : public MgmtData,\r
+ public AbstractDOMCachingXMLObject,\r
+ public AbstractValidatingXMLObject,\r
+ public AbstractXMLObjectMarshaller,\r
+ public AbstractXMLObjectUnmarshaller\r
+ {\r
+ public:\r
+ virtual ~MgmtDataImpl() {}\r
+\r
+ MgmtDataImpl(const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType)\r
+ : AbstractXMLObject(nsURI, localName, prefix, schemaType), m_Data(NULL) {\r
+ }\r
+ \r
+ MgmtDataImpl(const MgmtDataImpl& src)\r
+ : AbstractXMLObject(src),\r
+ AbstractDOMCachingXMLObject(src),\r
+ AbstractValidatingXMLObject(src),\r
+ m_Data(XMLString::replicate(src.m_Data)) {\r
+ }\r
+ \r
+ IMPL_XMLOBJECT_CLONE(MgmtData);\r
+ IMPL_XMLOBJECT_CONTENT(Data);\r
};\r
- \r
};\r
\r
#if defined (_MSC_VER)\r
#pragma warning( pop )\r
#endif\r
\r
-KeyInfo* KeyInfoBuilderImpl::buildObject(\r
- const XMLCh* nsURI, const XMLCh* localName, const XMLCh* prefix, const QName* schemaType\r
- ) const\r
+// Builder Implementations\r
+\r
+IMPL_XMLOBJECTBUILDER(KeyInfo);\r
+IMPL_XMLOBJECTBUILDER(KeyName);\r
+IMPL_XMLOBJECTBUILDER(MgmtData);\r
+\r
+// Validators\r
+\r
+void KeyInfoSchemaValidator::validate(const XMLObject* xmlObject) const\r
+{\r
+ const KeyInfo* ptr=dynamic_cast<const KeyInfo*>(xmlObject);\r
+ if (!ptr)\r
+ throw ValidationException("KeyInfoSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name()));\r
+ if (!ptr->hasChildren())\r
+ throw ValidationException("KeyInfo is empty");\r
+}\r
+\r
+void KeyNameSchemaValidator::validate(const XMLObject* xmlObject) const\r
+{\r
+ const KeyName* ptr=dynamic_cast<const KeyName*>(xmlObject);\r
+ if (!ptr)\r
+ throw ValidationException("KeyNameSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name()));\r
+ if (XMLString::stringLen(ptr->getName())==0)\r
+ throw ValidationException("KeyName is empty");\r
+}\r
+\r
+void MgmtDataSchemaValidator::validate(const XMLObject* xmlObject) const\r
{\r
- return new KeyInfoImpl(nsURI,localName,prefix,schemaType);\r
+ const MgmtData* ptr=dynamic_cast<const MgmtData*>(xmlObject);\r
+ if (!ptr)\r
+ throw ValidationException("MgmtDataSchemaValidator: unsupported object type ($1)",params(1,typeid(xmlObject).name()));\r
+ if (XMLString::stringLen(ptr->getData())==0)\r
+ throw ValidationException("MgmtData is empty");\r
}\r
\r
#include <xmltooling/signature/KeyInfo.h>\r
#include <xmltooling/util/XMLConstants.h>\r
+#include <xmltooling/validation/Validator.h>\r
+\r
+#define BEGIN_XMLSIGOBJECTBUILDERIMPL(cname) \\r
+ BEGIN_XMLOBJECTBUILDERIMPL(cname,XMLConstants::XMLSIG_NS,XMLConstants::XMLSIG_PREFIX)\r
\r
namespace xmltooling {\r
+ \r
+ BEGIN_XMLSIGOBJECTBUILDERIMPL(KeyInfo);\r
+ END_XMLOBJECTBUILDERIMPL;\r
\r
- BEGIN_XMLOBJECTBUILDERIMPL(KeyInfo,XMLConstants::XMLSIG_NS);\r
+ BEGIN_XMLSIGOBJECTBUILDERIMPL(KeyName);\r
END_XMLOBJECTBUILDERIMPL;\r
\r
+ BEGIN_XMLSIGOBJECTBUILDERIMPL(MgmtData);\r
+ END_XMLOBJECTBUILDERIMPL;\r
+ \r
+ BEGIN_XMLOBJECTVALIDATOR(KeyInfoSchema);\r
+ END_XMLOBJECTVALIDATOR;\r
+\r
+ BEGIN_XMLOBJECTVALIDATOR(KeyNameSchema);\r
+ END_XMLOBJECTVALIDATOR;\r
+\r
+ BEGIN_XMLOBJECTVALIDATOR(MgmtDataSchema);\r
+ END_XMLOBJECTVALIDATOR;\r
};\r
\r
#endif /* __xmltooling_keyinfoimpl_h__ */\r