Initial marshalling support.
[shibboleth/cpp-xmltooling.git] / xmltooling / XMLObject.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 XMLObject.h\r
19  * \r
20  * Abstract interface to objects that can be manipulated in and out of XML form. \r
21  */\r
22 \r
23 #if !defined(__xmltooling_xmlobj_h__)\r
24 #define __xmltooling_xmlobj_h__\r
25 \r
26 #include <set>\r
27 #include <list>\r
28 #include <xmltooling/QName.h>\r
29 #include <xmltooling/Namespace.h>\r
30 \r
31 namespace xmltooling {\r
32 \r
33     /**\r
34      * Object that represents an XML Element that has been unmarshalled into this C++ object.\r
35      */\r
36     class XMLTOOL_API XMLObject\r
37     {\r
38         MAKE_NONCOPYABLE(XMLObject);\r
39     public:\r
40         XMLObject() {}\r
41         virtual ~XMLObject() {}\r
42         \r
43         /**\r
44          * Creates a copy of the object, along with all of its children.\r
45          * \r
46          * The new object tree will be completely distinct and independent of\r
47          * the original in all respects.\r
48          */\r
49         virtual XMLObject* clone() const=0;\r
50         \r
51         /**\r
52          * Gets the QName for this element.  This QName <strong>MUST</strong> \r
53          * contain the namespace URI, namespace prefix, and local element name.\r
54          * \r
55          * @return constant reference to the QName for this object\r
56          */\r
57         virtual const QName& getElementQName() const=0;\r
58         \r
59         /**\r
60          * Sets the namespace prefix for this element.\r
61          * \r
62          * @param prefix the prefix for this element\r
63          */\r
64         virtual void setElementNamespacePrefix(const XMLCh* prefix)=0;\r
65         \r
66         /**\r
67          * Gets the namespaces that are scoped to this element.\r
68          * \r
69          * The caller MUST NOT modify the set returned, but may use any\r
70          * non-modifying operations or algorithms on it. Iterators will\r
71          * remain valid unless the set member referenced is removed using\r
72          * the removeNamespace method.\r
73          * \r
74          * @return the namespaces that are scoped to this element\r
75          */\r
76         virtual const std::set<Namespace>& getNamespaces() const=0;\r
77         \r
78         /**\r
79          * Adds a namespace to the ones already scoped to this element\r
80          * \r
81          * @param ns the namespace to add\r
82          */\r
83         virtual void addNamespace(const Namespace& ns)=0;\r
84         \r
85         /**\r
86          * Removes a namespace from this element\r
87          * \r
88          * @param ns the namespace to remove\r
89          */\r
90         virtual void removeNamespace(const Namespace& ns)=0;\r
91         \r
92         /**\r
93          * Gets the XML schema type of this element.  This translates to contents the xsi:type\r
94          * attribute for the element.\r
95          * \r
96          * @return XML schema type of this element\r
97          */\r
98         virtual const QName* getSchemaType() const=0;\r
99         \r
100         /**\r
101          * Sets the XML schema type of this element.  This translates to contents the xsi:type\r
102          * attribute for the element.\r
103          * \r
104          * @param type XML schema type of this element\r
105          */\r
106         virtual void setSchemaType(const QName* type)=0;\r
107         \r
108         /**\r
109          * Checks to see if this object has a parent.\r
110          * \r
111          * @return true if the object has a parent, false if not\r
112          */\r
113         virtual bool hasParent() const=0;\r
114         \r
115         /**\r
116          * Gets the parent of this element or null if there is no parent.\r
117          * \r
118          * @return the parent of this element or null\r
119          */\r
120         virtual XMLObject* getParent() const=0;\r
121         \r
122         /**\r
123          * Sets the parent of this element.\r
124          * \r
125          * @param parent the parent of this element\r
126          */\r
127         virtual void setParent(XMLObject* parent)=0;\r
128         \r
129         /**\r
130          * Checks if this XMLObject has children.\r
131          * \r
132          * @return true if this XMLObject has children, false if not\r
133          */\r
134         virtual bool hasChildren() const=0;\r
135         \r
136         /**\r
137          * Stores an unmodifiable list of child objects in the order that they\r
138          * will appear in the serialized representation.\r
139          * \r
140          * The validity of the returned objects is not maintained if any non-const\r
141          * operations are performed on the parent object. \r
142          * \r
143          * @param v     vector in which to store pointers to child objects\r
144          * @return the number of children\r
145          */\r
146         virtual size_t getOrderedChildren(std::vector<XMLObject*>& v) const=0;\r
147  };\r
148 \r
149 };\r
150 \r
151 #endif /* __xmltooling_xmlobj_h__ */\r