001: /* XMLParserFactory.java NanoXML/Java
002: *
003: * $Revision: 2056 $
004: * $Date: 2008-02-25 00:29:28 -0800 (Mon, 25 Feb 2008) $
005: * $Name$
006: *
007: * This file is part of NanoXML 2 for Java.
008: * Copyright (C) 2001 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: /**
032: * Creates an XML parser.
033: *
034: * @author Marc De Scheemaecker
035: * @version $Name$, $Revision: 2056 $
036: */
037: public class XMLParserFactory {
038:
039: /**
040: * The class name of the default XML parser.
041: */
042: public static final String DEFAULT_CLASS = "net.n3.nanoxml.StdXMLParser";
043:
044: /**
045: * The Java properties key of the XML parser class name.
046: */
047: public static final String CLASS_KEY = "net.n3.nanoxml.XMLParser";
048:
049: /**
050: * Creates a default parser.
051: *
052: * @see #DEFAULT_CLASS
053: * @see #CLASS_KEY
054: *
055: * @return the non-null parser.
056: *
057: * @throws java.lang.ClassNotFoundException if the class of the parser or validator could not be
058: * found.
059: * @throws java.lang.InstantiationException if the parser could not be created
060: * @throws java.lang.IllegalAccessException if the parser could not be created
061: */
062: public static IXMLParser createDefaultXMLParser()
063: throws ClassNotFoundException, InstantiationException,
064: IllegalAccessException {
065: String className = System.getProperty(
066: XMLParserFactory.CLASS_KEY,
067: XMLParserFactory.DEFAULT_CLASS);
068: return XMLParserFactory.createXMLParser(className,
069: XMLBuilderFactory.createXMLBuilder());
070: }
071:
072: /**
073: * Creates a default parser.
074: *
075: * @see #DEFAULT_CLASS
076: * @see #CLASS_KEY
077: *
078: * @param builder the XML builder.
079: *
080: * @return the non-null parser.
081: *
082: * @throws java.lang.ClassNotFoundException if the class of the parser could not be found.
083: * @throws java.lang.InstantiationException if the parser could not be created
084: * @throws java.lang.IllegalAccessException if the parser could not be created
085: */
086: public static IXMLParser createDefaultXMLParser(IXMLBuilder builder)
087: throws ClassNotFoundException, InstantiationException,
088: IllegalAccessException {
089: String className = System.getProperty(
090: XMLParserFactory.CLASS_KEY,
091: XMLParserFactory.DEFAULT_CLASS);
092: return XMLParserFactory.createXMLParser(className, builder);
093: }
094:
095: /**
096: * Creates a parser.
097: *
098: * @param className the name of the class of the XML parser
099: * @param builder the XML builder.
100: *
101: * @return the non-null parser.
102: *
103: * @throws java.lang.ClassNotFoundException if the class of the parser could not be found.
104: * @throws java.lang.InstantiationException if the parser could not be created
105: * @throws java.lang.IllegalAccessException if the parser could not be created
106: */
107: public static IXMLParser createXMLParser(String className,
108: IXMLBuilder builder) throws ClassNotFoundException,
109: InstantiationException, IllegalAccessException {
110: Class<IXMLParser> cls = (Class<IXMLParser>) Class
111: .forName(className);
112: IXMLParser parser = cls.newInstance();
113: parser.setBuilder(builder);
114: parser.setValidator(new NonValidator());
115: return parser;
116: }
117:
118: }
|