1 /*-----------------------------------------------------------------------------
 2 Name:      ParserFactory.h
 3 Project:   xmlBlaster.org
 4 Copyright: xmlBlaster.org, see xmlBlaster-LICENSE file
 5 Comment:   The abstraction parser for xml literals
 6 -----------------------------------------------------------------------------*/
 7 
 8 #ifndef _UTIL_PARSER_PARSERFACTORY_H
 9 #define _UTIL_PARSER_PARSERFACTORY_H
10 
11 #include <util/xmlBlasterDef.h>
12 #include <util/parser/I_Parser.h>
13 #include <util/Global.h>
14 #include <util/parser/XmlHandlerBase.h>
15 
16 namespace org { namespace xmlBlaster { namespace util { namespace parser {
17     
18 /**
19  * Abstraction for the xml handling. 
20  * <p />
21  * You may use this as the interface to extend in your specific XML handling (example SAX2).
22  * <p />
23  * It is a singleton class and has for
24  * that reason private constructors, destructor and assignment operator. 
25  * To get a reference to the singleton instance you must invoke getFactory(...).
26  */
27 class Dll_Export ParserFactory {
28    friend class Sax2Parser; // g++ 2.95.3 warning: `class org::xmlBlaster::util::parser::ParserFactory' only defines private constructors and has no friends
29 
30    private:
31    const std::string ME;
32    bool isInitialized_;
33    std::string locale_;
34 
35    static ParserFactory* factory_;
36    
37    ParserFactory();
38    ParserFactory(const ParserFactory& factory);
39    ParserFactory& operator =(const ParserFactory& factory);
40 
41    public:
42    ~ParserFactory();
43 
44    /**
45     * Static access to the factory. 
46     * @exception XmlBlasterException
47     */
48    static ParserFactory& getFactory();
49 
50    /**
51     * The locale used to initialize the parser. 
52     * Xerces defaults to "en_US", configurable with
53     * for example <tt>-xmlBlaster/locale</tt> "de_DE.iso-8859-1" or "en_US.UTF-8"
54     */
55    std::string getLocale(org::xmlBlaster::util::Global& global);
56 
57    /**
58     * Initialize the used parser. 
59     * The locale is set if the Initialize() is invoked for the very first time,
60     * to ensure that each and every message loaders, in the process space, share the same locale.
61     *
62     * All subsequent invocations of Initialize(), with a different locale,
63     * have no effect on the message loaders, either instantiated, or to be instantiated. 
64     * @see http://xml.apache.org/xerces-c/apiDocs/classXMLPlatformUtils.html#z489_0
65     */
66    void initialize(org::xmlBlaster::util::Global& global);
67 
68    /**
69     * Creates a parser implementation. 
70     * <p />
71     * It is the responsibility of the user to delete the I_Parser
72     * object once it is not needed anymore.
73     * @exception XmlBlasterException
74     */
75    I_Parser* createParser(org::xmlBlaster::util::Global& global, XmlHandlerBase *handler);
76 };
77 
78 }}}} // namespace
79 
80 #endif


syntax highlighted by Code2HTML, v. 0.9.1