source: NonGTP/Xerces/xerces/samples/PSVIWriter/PSVIWriterHandlers.hpp @ 358

Revision 358, 12.8 KB checked in by bittner, 19 years ago (diff)

xerces added

Line 
1/*
2 * Copyright 2003,2004 The Apache Software Foundation.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17#ifndef PSVIWRITERHANDLER_HPP
18#define PSVIWRITERHANDLER_HPP
19
20// ---------------------------------------------------------------------------
21//  Includes
22// ---------------------------------------------------------------------------
23#include <xercesc/sax2/Attributes.hpp>
24#include <xercesc/sax2/DefaultHandler.hpp>
25#include <xercesc/framework/psvi/XSConstants.hpp>
26#include <xercesc/framework/psvi/PSVIHandler.hpp>
27#include <xercesc/framework/psvi/PSVIAttribute.hpp>
28#include <xercesc/framework/psvi/PSVIAttributeList.hpp>
29#include <xercesc/framework/psvi/PSVIElement.hpp>
30#include <xercesc/framework/psvi/PSVIItem.hpp>
31#include <xercesc/framework/psvi/XSAnnotation.hpp>
32#include <xercesc/framework/psvi/XSAttributeDeclaration.hpp>
33#include <xercesc/framework/psvi/XSAttributeGroupDefinition.hpp>
34#include <xercesc/framework/psvi/XSAttributeUse.hpp>
35#include <xercesc/framework/psvi/XSComplexTypeDefinition.hpp>
36#include <xercesc/framework/psvi/XSElementDeclaration.hpp>
37#include <xercesc/framework/psvi/XSFacet.hpp>
38#include <xercesc/framework/psvi/XSIDCDefinition.hpp>
39#include <xercesc/framework/psvi/XSModel.hpp>
40#include <xercesc/framework/psvi/XSModelGroup.hpp>
41#include <xercesc/framework/psvi/XSModelGroupDefinition.hpp>
42#include <xercesc/framework/psvi/XSMultiValueFacet.hpp>
43#include <xercesc/framework/psvi/XSNamedMap.hpp>
44#include <xercesc/framework/psvi/XSNamespaceItem.hpp>
45#include <xercesc/framework/psvi/XSNotationDeclaration.hpp>
46#include <xercesc/framework/psvi/XSParticle.hpp>
47#include <xercesc/framework/psvi/XSSimpleTypeDefinition.hpp>
48#include <xercesc/framework/psvi/XSTypeDefinition.hpp>
49#include <xercesc/framework/psvi/XSWildcard.hpp>
50#include <xercesc/framework/XMLFormatter.hpp>
51#include <xercesc/dom/DOMElement.hpp>
52#include <xercesc/dom/DOMNamedNodeMap.hpp>
53#include <xercesc/util/ValueStackOf.hpp>
54#include <xercesc/util/ValueVectorOf.hpp>
55#include <xercesc/util/XMLEntityResolver.hpp>
56#include <xercesc/util/XMLResourceIdentifier.hpp>
57#include <stdlib.h>
58#include <string.h>
59
60XERCES_CPP_NAMESPACE_USE
61
62
63class AttrInfo {
64public:
65        AttrInfo(const XMLCh* pUri, const XMLCh* pName, const XMLCh* pType, const XMLCh* pValue) {
66                uri = XMLString::replicate(pUri);
67                name = XMLString::replicate(pName);
68                type = XMLString::replicate(pType);
69                value = XMLString::replicate(pValue);
70        }
71       
72        ~AttrInfo() {
73                XMLString::release((XMLCh**)&uri);
74                XMLString::release((XMLCh**)&name);
75                XMLString::release((XMLCh**)&type);
76                XMLString::release((XMLCh**)&value);
77        }
78       
79        const XMLCh* getUri() const {
80                return uri;     
81        }
82       
83        const XMLCh* getLocalName() const {
84                return name;
85        }
86       
87        const XMLCh* getType() const {
88                return type;
89        }
90               
91        const XMLCh* getValue() const {
92                return value;
93        }
94
95private:
96        const XMLCh* uri;
97        const XMLCh* name;
98        const XMLCh* type;
99        const XMLCh* value;
100};
101
102class PSVIWriterHandlers : public PSVIHandler, public DefaultHandler, public XMLEntityResolver {
103public:
104    // -----------------------------------------------------------------------
105    //  Constructors and Destructor
106    // -----------------------------------------------------------------------
107    PSVIWriterHandlers(XMLFormatter* outputFormatter, XMLFormatter* errorFormatter = NULL);
108    ~PSVIWriterHandlers();
109   
110    // -----------------------------------------------------------------------
111    //  Convenience Utility
112    // -----------------------------------------------------------------------
113        void resetPSVIFormatter(XMLFormatter* outputFormatter);
114    void resetDocument();
115       
116    // -----------------------------------------------------------------------
117    //  Handlers for the SAX ContentHandler interface
118    // -----------------------------------------------------------------------
119    void startElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname, const Attributes& attrs);
120    void endElement(const XMLCh* const uri, const XMLCh* const localname, const XMLCh* const qname);
121    void startDocument();
122    void endDocument();
123    void characters(const XMLCh* const chars, const unsigned int length);
124    void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
125    void comment(const XMLCh* const chars, const unsigned int length);
126    void processingInstruction(const XMLCh* const target, const XMLCh* const data);
127    void startPrefixMapping(const XMLCh* const prefix, const XMLCh* const uri);
128    void endPrefixMapping(const XMLCh* const prefix);
129    InputSource* resolveEntity(XMLResourceIdentifier* resourceIdentifier);
130    InputSource* resolveEntity(const XMLCh* const publicId, const XMLCh* const systemId);
131
132    // -----------------------------------------------------------------------
133    //  Handlers for the SAX ErrorHandler interface
134    // -----------------------------------------------------------------------
135        void warning(const SAXParseException& exception);
136    void error(const SAXParseException& exception);
137    void fatalError(const SAXParseException& exception);
138    void resetErrors();
139   
140    // -----------------------------------------------------------------------
141    //  Handlers for the PSVIHandler interface
142    // -----------------------------------------------------------------------
143       
144        void handleAttributesPSVI( const XMLCh* const localName,
145                                                                const XMLCh* const uri,
146                                                                PSVIAttributeList* psviAttributes );
147        void handleElementPSVI( const XMLCh* const localName,
148                                const XMLCh* const uri,
149                                PSVIElement* elementInfo );
150        void handlePartialElementPSVI( const XMLCh* const localName,
151                                   const XMLCh* const uri,
152                                   PSVIElement* elementInfo );
153private:
154    // -----------------------------------------------------------------------
155    //  Private methods
156    // -----------------------------------------------------------------------
157
158    void processAttributes(PSVIAttributeList* psviAttributes, const RefVectorOf<AttrInfo>* attributesInfo);
159    void processNamespaceAttributes(PSVIAttributeList* psviAttributes, const RefVectorOf<AttrInfo>* attributes);
160    void processAttributePSVI(PSVIAttribute* attribute);
161    void processInScopeNamespaces();
162    void processActualValue(PSVIItem*);
163    void formDateTime(XSValue*);
164
165    void processSchemaInformation(XSModel* model);
166    void processNamespaceItem(XSNamespaceItem* namespaceItem);
167    void processSchemaComponents(XSNamespaceItem* namespaceItem);
168    void processSchemaDocuments(XSNamespaceItem* namespaceItem);
169    void processSchemaAnnotations(XSAnnotationList* annotations);
170    void processSchemaErrorCode(StringList* errors);
171   
172    void processTypeDefinition(XSTypeDefinition* type);
173    void processComplexTypeDefinition(XSComplexTypeDefinition* complexType);
174    void processSimpleTypeDefinition(XSSimpleTypeDefinition* simpleType);
175    void processModelGroupDefinition(XSModelGroupDefinition* modelGroup);
176    void processAttributeGroupDefinition(XSAttributeGroupDefinition* attributeGroup);
177   
178    void processElementDeclaration(XSElementDeclaration* element);
179    void processAttributeDeclaration(XSAttributeDeclaration* attribute);
180    void processNotationDeclaration(XSNotationDeclaration* notation);
181   
182    void processAnnotations(XSAnnotationList* annotations);
183    void processAttributeUses(XSAttributeUseList* attributeUses);
184    void processFacets(XSFacetList* facets, XSMultiValueFacetList* multiFacets);
185    void processFundamentalFacets(XSSimpleTypeDefinition* facets);
186    void processMemberTypeDefinitions(XSSimpleTypeDefinitionList* memberTypes);
187   
188    void processAnnotation(XSAnnotation* annotation);
189    void processDOMElement(const XMLCh* const encloseName, DOMElement* rootElem, const XMLCh* const elementName);
190    void processDOMAttributes(DOMNamedNodeMap* attrs);
191    void processWildcard(XSWildcard* wildcard);
192    void processModelGroup(XSModelGroup* modelGroup);
193    void processParticle(XSParticle* particle);
194   
195    void processAttributeWildcard(XSWildcard* wildcard);
196    void processScope(XSComplexTypeDefinition* enclosingCTD, short scope);
197    void processValueConstraint(XSConstants::VALUE_CONSTRAINT ConstraintType, const XMLCh* constraintValue);
198   
199    void processIdentityConstraintDefinition(XSNamedMap<XSIDCDefinition>* identityConstraint);
200    void processFields(StringList* fields);
201    void processXPath(const XMLCh* xpath);
202   
203    void processChildren();
204    void processChildrenEnd();
205   
206    void processTypeDefinitionOrRef(const XMLCh* enclose, XSTypeDefinition* type);
207        void processSimpleTypeDefinitionOrRef(XSSimpleTypeDefinition* type);
208    void processAttributeDeclarationOrRef(XSAttributeDeclaration* attrDecl);
209    void processElementDeclarationOrRef(XSElementDeclaration* elemDecl);
210        void processTypeDefinitionRef(const XMLCh* enclose, XSTypeDefinition* type);
211    void processAttributeDeclarationRef(const XMLCh* enclose, XSAttributeDeclaration* attrDecl);
212    void processElementDeclarationRef(const XMLCh* enclose, XSElementDeclaration* elemDecl);
213    void sendReference(const XMLCh* elementName, XSObject* obj);
214   
215    void sendElementEmpty(const XMLCh* elementName);
216        void sendElementValueInt(const XMLCh* elementName, const int value);
217    void sendElementValue(const XMLCh* elementName, const XMLCh* const value);
218    void sendElementValueList(const XMLCh* const elementName, const StringList* const values);
219
220        void sendIndentedElement(const XMLCh* elementName);
221    void sendIndentedElementWithID(const XMLCh* elementName, XSObject* obj);    //adds the ID to the attribute list before sending
222    void sendUnindentedElement(const XMLCh* elementName);
223   
224    void writeOpen(const XMLCh* const elementName);
225        void writeOpen(const XMLCh* const elementName, const StringList* const attrs);
226        void writeClose(const XMLCh* const elementName);
227        void writeValue(const XMLCh* const elementName, const XMLCh* const value);
228        void writeValue(const XMLCh* const elementName, const StringList* const values);
229        void writeEmpty(const XMLCh* const elementName, const StringList* const attrs);
230        void writeEmpty(const XMLCh* const elementName);
231    void writeString(const XMLCh* const string);
232
233    const XMLCh* translateScope(XSConstants::SCOPE scope);
234    const XMLCh* translateValueConstraint(XSConstants::VALUE_CONSTRAINT constraintKind);
235    const XMLCh* translateBlockOrFinal(short val);
236    const XMLCh* translateDerivationMethod(XSConstants::DERIVATION_TYPE derivation);
237    const XMLCh* translateProcessContents(XSWildcard::PROCESS_CONTENTS processContents);
238    const XMLCh* translateCompositor(XSModelGroup::COMPOSITOR_TYPE compositor);
239    const XMLCh* translateValidity(PSVIItem::VALIDITY_STATE validity);
240    const XMLCh* translateValidationAttempted(PSVIItem::ASSESSMENT_TYPE validation);
241    const XMLCh* translateIdConstraintCategory(XSIDCDefinition::IC_CATEGORY category);
242    const XMLCh* translateComplexContentType(XSComplexTypeDefinition::CONTENT_TYPE contentType);
243    const XMLCh* translateSimpleTypeVariety(XSSimpleTypeDefinition::VARIETY variety);
244    const XMLCh* translateOrderedFacet(XSSimpleTypeDefinition::ORDERING ordered);
245    const XMLCh* translateFacet(XSSimpleTypeDefinition::FACET facetKind);
246    const XMLCh* translateComponentType(XSConstants::COMPONENT_TYPE type);
247    const XMLCh* translateBool(bool flag);
248   
249    XMLCh* createID(XSObject* obj);
250    const XMLCh* getIdName(XSObject* obj);
251    void incIndent();
252    void decIndent();
253   
254protected:   
255        XMLFormatter* fFormatter;
256        XMLFormatter* fErrorFormatter;
257       
258        StringList* fAttrList;
259    XMLCh* fTempResult;
260    XMLCh* fIndentChars;
261    XMLCh* fBaseUri;
262   
263    unsigned int fIndent;
264    unsigned int fIndentCap;
265    unsigned int fAnonNum;
266   
267        RefHashTableOf<XMLCh>* fIdMap;
268    RefVectorOf<XSObject>* fDefinedIds;
269    RefArrayVectorOf<XMLCh>* fIdNames;
270    RefArrayVectorOf<XMLCh>* fObjectLocations;
271   
272        RefHashTableOf<XMLCh>* fPrefixMap;
273    RefArrayVectorOf<XMLCh>* fNamespaces;
274   
275        ValueVectorOf<unsigned int>* fNSAttributes;  //REVISIT  dont need if NSAttrs in different object
276        ValueStackOf<bool>* fElementChildren;
277               
278        RefVectorOf<AttrInfo>* fAttributesInfo;
279};
280
281
282#endif
283
Note: See TracBrowser for help on using the repository browser.