56189c11dbf84301885070352a8ce97bf71e908a
[shibboleth/cpp-xmltooling.git] / xmltooling / io / AbstractXMLObjectUnmarshaller.h
1 /*\r
2 *  Copyright 2001-2006 Internet2\r
3  * \r
4 * Licensed under the Apache License, Version 2.0 (the "License");\r
5  * you may not use this file except in compliance with the License.\r
6  * You may obtain a copy of the License at\r
7  *\r
8  *     http://www.apache.org/licenses/LICENSE-2.0\r
9  *\r
10  * Unless required by applicable law or agreed to in writing, software\r
11  * distributed under the License is distributed on an "AS IS" BASIS,\r
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
13  * See the License for the specific language governing permissions and\r
14  * limitations under the License.\r
15  */\r
16 \r
17 /**\r
18  * @file AbstractXMLObjectUnmarshaller.h\r
19  * \r
20  * A thread-safe abstract unmarshaller.\r
21  */\r
22 \r
23 #if !defined(__xmltooling_xmlunmarshaller_h__)\r
24 #define __xmltooling_xmlunmarshaller_h__\r
25 \r
26 #include <xmltooling/io/Unmarshaller.h>\r
27 \r
28 namespace xmltooling {\r
29 \r
30     /**\r
31      * A thread-safe abstract unmarshaller.\r
32      */\r
33     class XMLTOOL_API AbstractXMLObjectUnmarshaller : public virtual Unmarshaller\r
34     {\r
35     public:\r
36         virtual ~AbstractXMLObjectUnmarshaller() {}\r
37 \r
38         /**\r
39          * @see Unmarshaller::unmarshall()\r
40          */\r
41         XMLObject* unmarshall(DOMElement* element, bool bindDocument=false) const;\r
42             \r
43     protected:\r
44         /**\r
45          * Constructor.\r
46          * \r
47          * @param targetNamespaceURI the namespace URI of either the schema type QName or element QName of the elements this\r
48          *            unmarshaller operates on\r
49          * @param targetLocalName the local name of either the schema type QName or element QName of the elements this\r
50          *            unmarshaller operates on\r
51          */\r
52         AbstractXMLObjectUnmarshaller(const XMLCh* targetNamespaceURI, const XMLCh* targetLocalName);\r
53 \r
54         /**\r
55          * Constructs the XMLObject that the given DOM Element will be unmarshalled into. If the DOM element has an XML\r
56          * Schema type defined this method will attempt to retrieve an XMLObjectBuilder using the schema type. If no\r
57          * schema type is present or no builder is registered for the schema type, the element's QName is used. Once\r
58          * the builder is found the XMLObject is created by invoking XMLObjectBuilder::buildObject().\r
59          * Extending classes may wish to override this logic if more than just schema type or element name\r
60          * (e.g. element attributes or content) need to be used to determine how to create the XMLObject.\r
61          * \r
62          * @param domElement the DOM Element the created XMLObject will represent\r
63          * @return the empty XMLObject that DOM Element can be unmarshalled into\r
64          * \r
65          * @throws UnmarshallingException thrown if there is now XMLObjectBuilder registered for the given DOM Element\r
66          */\r
67         virtual XMLObject* buildXMLObject(const DOMElement* domElement) const;\r
68         \r
69         /**\r
70          * Unmarshalls the attributes from the given DOM Element into the given XMLObject. If the attribute is an XML\r
71          * namespace declaration the namespace is added to the given element via XMLObject::addNamespace().\r
72          * If it is a schema type (xsi:type) the schema type is added to the element via XMLObject::setSchemaType().\r
73          * All other attributes are passed to the processAttribute hook.\r
74          * \r
75          * @param domElement the DOM Element whose attributes will be unmarshalled\r
76          * @param xmlObject the XMLObject that will recieve information from the DOM attribute\r
77          * \r
78          * @throws UnmarshallingException thrown if there is a problem unmarshalling an attribute\r
79          */\r
80         virtual void unmarshallAttributes(const DOMElement* domElement, XMLObject* xmlObject) const;\r
81 \r
82         /**\r
83          * Unmarshalls a given Element's children. For each child an unmarshaller is retrieved using\r
84          * getUnmarshaller(). The unmarshaller is then used to unmarshall the child element and the\r
85          * resulting XMLObject is passed to processChildElement() for further processing.\r
86          * \r
87          * @param domElement the DOM Element whose children will be unmarshalled\r
88          * @param xmlObject the parent object of the unmarshalled children\r
89          * \r
90          * @throws UnmarshallingException thrown if an error occurs unmarshalling the child elements\r
91          */\r
92         virtual void unmarshallChildElements(const DOMElement* domElement, XMLObject* xmlObject) const;\r
93 \r
94         /**\r
95          * Called after a child element has been unmarshalled so that it can be added to the parent XMLObject.\r
96          * \r
97          * @param parent the parent XMLObject\r
98          * @param child the child XMLObject\r
99          * \r
100          * @throws UnmarshallingException thrown if there is a problem adding the child to the parent\r
101          */\r
102         virtual void processChildElement(XMLObject* parent, XMLObject* child) const=0;\r
103     \r
104         /**\r
105          * Called after an attribute has been unmarshalled so that it can be added to the XMLObject.\r
106          * \r
107          * @param xmlObject the XMLObject\r
108          * @param attribute the attribute being unmarshalled\r
109          * \r
110          * @throws UnmarshallingException thrown if there is a problem adding the attribute to the XMLObject\r
111          */\r
112         virtual void processAttribute(XMLObject* xmlObject, const DOMAttr* attribute) const=0;\r
113     \r
114         /**\r
115          * Called if the element being unmarshalled contained textual content so that it can be added to the XMLObject.\r
116          * \r
117          * @param xmlObject XMLObject the content will be given to\r
118          * @param elementContent the Element's text content\r
119          */\r
120         virtual void processElementContent(XMLObject* xmlObject, const XMLCh* elementContent) const=0;\r
121 \r
122         void* m_log;\r
123     private:\r
124         QName m_targetQName;\r
125     };\r
126     \r
127 };\r
128 \r
129 #endif /* __xmltooling_xmlunmarshaller_h__ */\r