Statistics
| Revision:

root / import / ext3D / trunk / install-extension3d / IzPack / src / lib / net / n3 / nanoxml / XMLParserFactory.java @ 15280

History | View | Annotate | Download (4.47 KB)

1
/* XMLParserFactory.java                                           NanoXML/Java
2
 *
3
 * $Revision: 1.1 $
4
 * $Date: 2006/06/14 07:29:07 $
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

    
33

    
34
/**
35
 * Creates an XML parser.
36
 *
37
 * @author Marc De Scheemaecker
38
 * @version $Name:  $, $Revision: 1.1 $
39
 */
40
public class XMLParserFactory
41
{
42

    
43
    /**
44
     * The class name of the default XML parser.
45
     */
46
    public static final String DEFAULT_CLASS = "net.n3.nanoxml.StdXMLParser";
47
    
48
    
49
    /**
50
     * The Java properties key of the XML parser class name.
51
     */
52
    public static final String CLASS_KEY = "net.n3.nanoxml.XMLParser";
53
    
54
    
55
    /**
56
     * Creates a default parser.
57
     *
58
     * @see #DEFAULT_CLASS
59
     * @see #CLASS_KEY
60
     *
61
     * @return the non-null parser.
62
     *
63
     * @throws java.lang.ClassNotFoundException
64
     *                if the class of the parser or validator could not be found.
65
     * @throws java.lang.InstantiationException
66
     *                if the parser could not be created
67
     * @throws java.lang.IllegalAccessException
68
     *                if the parser could not be created
69
     */
70
    public static IXMLParser createDefaultXMLParser()
71
        throws ClassNotFoundException,
72
               InstantiationException,
73
               IllegalAccessException
74
    {
75
        String className = System.getProperty(XMLParserFactory.CLASS_KEY,
76
                                              XMLParserFactory.DEFAULT_CLASS);
77
        return XMLParserFactory.createXMLParser(className,
78
                                                new StdXMLBuilder());
79
    }
80
    
81
    
82
    /**
83
     * Creates a default parser.
84
     *
85
     * @see #DEFAULT_CLASS
86
     * @see #CLASS_KEY
87
     *
88
     * @param builder the XML builder.
89
     *
90
     * @return the non-null parser.
91
     *
92
     * @throws java.lang.ClassNotFoundException
93
     *                if the class of the parser could not be found.
94
     * @throws java.lang.InstantiationException
95
     *                if the parser could not be created
96
     * @throws java.lang.IllegalAccessException
97
     *                if the parser could not be created
98
     */
99
    public static IXMLParser createDefaultXMLParser(IXMLBuilder builder)
100
        throws ClassNotFoundException,
101
               InstantiationException,
102
               IllegalAccessException
103
    {
104
        String className = System.getProperty(XMLParserFactory.CLASS_KEY,
105
                                              XMLParserFactory.DEFAULT_CLASS);
106
        return XMLParserFactory.createXMLParser(className, builder);
107
    }
108
    
109
    
110
    /**
111
     * Creates a parser.
112
     *
113
     * @param className the name of the class of the XML parser
114
     * @param builder the XML builder.
115
     *
116
     * @return the non-null parser.
117
     *
118
     * @throws java.lang.ClassNotFoundException
119
     *                if the class of the parser could not be found.
120
     * @throws java.lang.InstantiationException
121
     *                if the parser could not be created
122
     * @throws java.lang.IllegalAccessException
123
     *                if the parser could not be created
124
     */
125
    public static IXMLParser createXMLParser(String      className,
126
                                             IXMLBuilder builder)
127
        throws ClassNotFoundException,
128
               InstantiationException,
129
               IllegalAccessException
130
    {
131
        Class cls = Class.forName(className);
132
        IXMLParser parser = (IXMLParser) cls.newInstance();
133
        parser.setBuilder(builder);
134
        parser.setValidator(new NonValidator());
135
        return parser;
136
    }
137

    
138
}