KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > n3 > nanoxml > XMLParserFactory


1 /* XMLParserFactory.java NanoXML/Java
2  *
3  * $Revision: 1421 $
4  * $Date: 2006-03-12 17:32:32 +0100 (Sun, 12 Mar 2006) $
5  * $Name$
6  *
7  * This file is part of NanoXML 2 for Java.
8  * Copyright (C) 2001 Marc De Scheemaecker, All Rights Reserved.
9  *
10  * This software is provided 'as-is', without any express or implied warranty.
11  * In no event will the authors be held liable for any damages arising from the
12  * use of this software.
13  *
14  * Permission is granted to anyone to use this software for any purpose,
15  * including commercial applications, and to alter it and redistribute it
16  * freely, subject to the following restrictions:
17  *
18  * 1. The origin of this software must not be misrepresented; you must not
19  * claim that you wrote the original software. If you use this software in
20  * a product, an acknowledgment in the product documentation would be
21  * appreciated but is not required.
22  *
23  * 2. Altered source versions must be plainly marked as such, and must not be
24  * misrepresented as being the original software.
25  *
26  * 3. This notice may not be removed or altered from any source distribution.
27  */

28
29 package net.n3.nanoxml;
30
31 /**
32  * Creates an XML parser.
33  *
34  * @author Marc De Scheemaecker
35  * @version $Name$, $Revision: 1421 $
36  */

37 public class XMLParserFactory
38 {
39
40     /**
41      * The class name of the default XML parser.
42      */

43     public static final String JavaDoc DEFAULT_CLASS = "net.n3.nanoxml.StdXMLParser";
44
45     /**
46      * The Java properties key of the XML parser class name.
47      */

48     public static final String JavaDoc CLASS_KEY = "net.n3.nanoxml.XMLParser";
49
50     /**
51      * Creates a default parser.
52      *
53      * @see #DEFAULT_CLASS
54      * @see #CLASS_KEY
55      *
56      * @return the non-null parser.
57      *
58      * @throws java.lang.ClassNotFoundException if the class of the parser or validator could not be
59      * found.
60      * @throws java.lang.InstantiationException if the parser could not be created
61      * @throws java.lang.IllegalAccessException if the parser could not be created
62      */

63     public static IXMLParser createDefaultXMLParser() throws ClassNotFoundException JavaDoc,
64             InstantiationException JavaDoc, IllegalAccessException JavaDoc
65     {
66         String JavaDoc className = System.getProperty(XMLParserFactory.CLASS_KEY,
67                 XMLParserFactory.DEFAULT_CLASS);
68         return XMLParserFactory.createXMLParser(className, new StdXMLBuilder());
69     }
70
71     /**
72      * Creates a default parser.
73      *
74      * @see #DEFAULT_CLASS
75      * @see #CLASS_KEY
76      *
77      * @param builder the XML builder.
78      *
79      * @return the non-null parser.
80      *
81      * @throws java.lang.ClassNotFoundException if the class of the parser could not be found.
82      * @throws java.lang.InstantiationException if the parser could not be created
83      * @throws java.lang.IllegalAccessException if the parser could not be created
84      */

85     public static IXMLParser createDefaultXMLParser(IXMLBuilder builder)
86             throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc
87     {
88         String JavaDoc className = System.getProperty(XMLParserFactory.CLASS_KEY,
89                 XMLParserFactory.DEFAULT_CLASS);
90         return XMLParserFactory.createXMLParser(className, builder);
91     }
92
93     /**
94      * Creates a parser.
95      *
96      * @param className the name of the class of the XML parser
97      * @param builder the XML builder.
98      *
99      * @return the non-null parser.
100      *
101      * @throws java.lang.ClassNotFoundException if the class of the parser could not be found.
102      * @throws java.lang.InstantiationException if the parser could not be created
103      * @throws java.lang.IllegalAccessException if the parser could not be created
104      */

105     public static IXMLParser createXMLParser(String JavaDoc className, IXMLBuilder builder)
106             throws ClassNotFoundException JavaDoc, InstantiationException JavaDoc, IllegalAccessException JavaDoc
107     {
108         Class JavaDoc cls = Class.forName(className);
109         IXMLParser parser = (IXMLParser) cls.newInstance();
110         parser.setBuilder(builder);
111         parser.setValidator(new NonValidator());
112         return parser;
113     }
114
115 }
116
Popular Tags