001: /*---------------------------------------------------------------------------*\
002: $Id: RSSParserFactory.java 7041 2007-09-09 01:04:47Z bmc $
003: ---------------------------------------------------------------------------
004: This software is released under a BSD-style license:
005:
006: Copyright (c) 2004-2007 Brian M. Clapper. All rights reserved.
007:
008: Redistribution and use in source and binary forms, with or without
009: modification, are permitted provided that the following conditions are
010: met:
011:
012: 1. Redistributions of source code must retain the above copyright notice,
013: this list of conditions and the following disclaimer.
014:
015: 2. The end-user documentation included with the redistribution, if any,
016: must include the following acknowlegement:
017:
018: "This product includes software developed by Brian M. Clapper
019: (bmc@clapper.org, http://www.clapper.org/bmc/). That software is
020: copyright (c) 2004-2007 Brian M. Clapper."
021:
022: Alternately, this acknowlegement may appear in the software itself,
023: if wherever such third-party acknowlegements normally appear.
024:
025: 3. Neither the names "clapper.org", "curn", nor any of the names of the
026: project contributors may be used to endorse or promote products
027: derived from this software without prior written permission. For
028: written permission, please contact bmc@clapper.org.
029:
030: 4. Products derived from this software may not be called "curn", nor may
031: "clapper.org" appear in their names without prior written permission
032: of Brian M. Clapper.
033:
034: THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
035: WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
036: MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
037: NO EVENT SHALL BRIAN M. CLAPPER BE LIABLE FOR ANY DIRECT, INDIRECT,
038: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
039: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
040: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
041: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
042: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
043: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
044: \*---------------------------------------------------------------------------*/
045:
046: package org.clapper.curn.parser;
047:
048: import java.lang.reflect.Constructor;
049: import java.lang.reflect.InvocationTargetException;
050:
051: /**
052: * This class provides a factory for retrieving a specific RSS parser
053: * implementation.
054: *
055: * @see RSSParser
056: * @see RSSChannel
057: * @see RSSItem
058: *
059: * @version <tt>$Revision: 7041 $</tt>
060: */
061: public class RSSParserFactory {
062: /*----------------------------------------------------------------------*\
063: Constructor
064: \*----------------------------------------------------------------------*/
065:
066: private RSSParserFactory() {
067: // Nothing to do
068: }
069:
070: /*----------------------------------------------------------------------*\
071: Public Methods
072: \*----------------------------------------------------------------------*/
073:
074: /**
075: * Get the named RSS parser. This method loads the specified class,
076: * verifies that it conforms to the {@link RSSParser} interface,
077: * instantiates it (via its default constructor), and returns the
078: * resulting <tt>RSSParser</tt> object.
079: *
080: * @param className the class name
081: *
082: * @return an <tt>RSSParser</tt> object
083: *
084: * @throws RSSParserException Error instantiating class. The
085: * exception will contain (i.e., nest)
086: * the real underlying exception.
087: */
088: public static RSSParser getRSSParser(String className)
089: throws RSSParserException {
090: try {
091: Class<?> parserClass = Class.forName(className);
092: Constructor constructor = parserClass.getConstructor();
093: return (RSSParser) constructor.newInstance();
094: }
095:
096: catch (ClassNotFoundException ex) {
097: throw new RSSParserException(ex);
098: }
099:
100: catch (NoSuchMethodException ex) {
101: throw new RSSParserException(ex);
102: }
103:
104: catch (InvocationTargetException ex) {
105: throw new RSSParserException(ex);
106: }
107:
108: catch (InstantiationException ex) {
109: throw new RSSParserException(ex);
110: }
111:
112: catch (IllegalAccessException ex) {
113: throw new RSSParserException(ex);
114: }
115:
116: }
117: }
|