001: /* XMLParserFactory.java NanoXML/Java
002: *
003: * $Revision: 1.3 $
004: * $Date: 2002/01/04 21:03:29 $
005: * $Name: RELEASE_2_2_1 $
006: *
007: * This file is part of NanoXML 2 for Java.
008: * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved.
009: *
010: * This software is provided 'as-is', without any express or implied warranty.
011: * In no event will the authors be held liable for any damages arising from the
012: * use of this software.
013: *
014: * Permission is granted to anyone to use this software for any purpose,
015: * including commercial applications, and to alter it and redistribute it
016: * freely, subject to the following restrictions:
017: *
018: * 1. The origin of this software must not be misrepresented; you must not
019: * claim that you wrote the original software. If you use this software in
020: * a product, an acknowledgment in the product documentation would be
021: * appreciated but is not required.
022: *
023: * 2. Altered source versions must be plainly marked as such, and must not be
024: * misrepresented as being the original software.
025: *
026: * 3. This notice may not be removed or altered from any source distribution.
027: */
028:
029: package net.n3.nanoxml;
030:
031: import java.io.IOException;
032:
033: /**
034: * Creates an XML parser.
035: *
036: * @author Marc De Scheemaecker
037: * @version $Name: RELEASE_2_2_1 $, $Revision: 1.3 $
038: */
039: public class XMLParserFactory {
040:
041: /**
042: * The class name of the default XML parser.
043: */
044: public static final String DEFAULT_CLASS = "net.n3.nanoxml.StdXMLParser";
045:
046: /**
047: * The Java properties key of the XML parser class name.
048: */
049: public static final String CLASS_KEY = "net.n3.nanoxml.XMLParser";
050:
051: /**
052: * Creates a default parser.
053: *
054: * @see #DEFAULT_CLASS
055: * @see #CLASS_KEY
056: *
057: * @return the non-null parser.
058: *
059: * @throws java.lang.ClassNotFoundException
060: * if the class of the parser or validator could not be found.
061: * @throws java.lang.InstantiationException
062: * if the parser could not be created
063: * @throws java.lang.IllegalAccessException
064: * if the parser could not be created
065: */
066: public static IXMLParser createDefaultXMLParser()
067: throws ClassNotFoundException, InstantiationException,
068: IllegalAccessException {
069: String className = System.getProperty(
070: XMLParserFactory.CLASS_KEY,
071: XMLParserFactory.DEFAULT_CLASS);
072: return XMLParserFactory.createXMLParser(className,
073: new StdXMLBuilder());
074: }
075:
076: /**
077: * Creates a default parser.
078: *
079: * @see #DEFAULT_CLASS
080: * @see #CLASS_KEY
081: *
082: * @param builder the XML builder.
083: *
084: * @return the non-null parser.
085: *
086: * @throws java.lang.ClassNotFoundException
087: * if the class of the parser could not be found.
088: * @throws java.lang.InstantiationException
089: * if the parser could not be created
090: * @throws java.lang.IllegalAccessException
091: * if the parser could not be created
092: */
093: public static IXMLParser createDefaultXMLParser(IXMLBuilder builder)
094: throws ClassNotFoundException, InstantiationException,
095: IllegalAccessException {
096: String className = System.getProperty(
097: XMLParserFactory.CLASS_KEY,
098: XMLParserFactory.DEFAULT_CLASS);
099: return XMLParserFactory.createXMLParser(className, builder);
100: }
101:
102: /**
103: * Creates a parser.
104: *
105: * @param className the name of the class of the XML parser
106: * @param builder the XML builder.
107: *
108: * @return the non-null parser.
109: *
110: * @throws java.lang.ClassNotFoundException
111: * if the class of the parser could not be found.
112: * @throws java.lang.InstantiationException
113: * if the parser could not be created
114: * @throws java.lang.IllegalAccessException
115: * if the parser could not be created
116: */
117: public static IXMLParser createXMLParser(String className,
118: IXMLBuilder builder) throws ClassNotFoundException,
119: InstantiationException, IllegalAccessException {
120: Class cls = Class.forName(className);
121: IXMLParser parser = (IXMLParser) cls.newInstance();
122: parser.setBuilder(builder);
123: parser.setValidator(new NonValidator());
124: return parser;
125: }
126:
127: }
|