/*
 *    ALMA - Atacama Large Millimiter Array
 *    (c) European Southern Observatory, 2002
 *    Copyright by ESO (in the framework of the ALMA collaboration)
 *    and Cosylab 2002, All rights reserved
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation; either
 *    version 2.1 of the License, or (at your option) any later version.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
 *    MA 02111-1307  USA
 */
package alma.acs.logging.engine.parser;

/**
 * A factory to build parsers.
 * <P>
 * The purpose of this object is to hide the type of parser really used at run time.
 * <P>
 * The object could instantiate a new parser or use only one instance, a singleton.
 * <P>
 * At the present there is one parser available, <code>ACSLogParserDOM</code> but we are
 * trying to adopt VTD XML parser.
 * <BR>
 * Having this factory allows to transparently use a different implementation at run-time
 * depending on the real availability of the parser.
 *   
 * @author acaproni
 *
 */
public class ACSLogParserFactory {
	
	/**
	 * The parser is a singleton built at the first invocation
	 * of <code>getParser()</code>.
	 */
	private static ACSLogParser parser=null;
	
	/**
	 * Get a parser.
	 * <P>
	 * The <code>ACSLogParser</code> returned by this method can be a new instance
	 * or not, depending on the implementation.
	 * 
	 * @return The parser.
	 * @throws <code>Exception</code> in case of error building the parser
	 */
	public static ACSLogParser getParser() throws Exception {
		if (parser==null) {
			parser =  new ACSLogParserDOM();
		}
		return parser;
	}
}

@@ -1253,127 +1253,320 @@
 %0A * 
-At the present there is one parser available, %3Ccode%3EACSLogParserDOM%3C/code%3E but we are%0A * trying to adopt VTD XML parser
+There are 2 parsers available: DOM and VTD.%0A * VTD is ACS/LGPL/Tools and installed by ACS. It is licensed under GPL and available%0A * at http://vtd-xml.sourceforge.net/%0A * VTD claims to be very fast (and effectively it performs better then DOM) so the factory%0A * tries to instantiate a VTD parser if it is present
 .%0A *
@@ -1712,16 +1712,17 @@
 e parser
+s
 .%0A *   %0A
@@ -1933,24 +1933,325 @@
 ull;%0A%09%0A%09/**%0A
+%09 * This property is used to check if VTD is installed to avoid trying to instantiate%0A%09 * if the library is missing%0A%09 * %3CP%3E %0A%09 * It is initially set to %3Ccode%3Etrue%3C/code%3E to try to instantiate VTD the first time%0A%09 * %3Ccode%3EgetParser()%3C/code%3E is called%0A%09 */%0A%09private static boolean usingVTD=true;%0A%09%0A%09/**%0A
 %09 * Get a pa
@@ -2566,17 +2566,17 @@
  (parser
-=
+!
 =null) %7B
@@ -2583,16 +2583,120 @@
 %0A%09%09%09
+return parser;%0A%09%09%7D%0A%09%09if (usingVTD) %7B%0A%09%09%09try %7B%0A%09%09%09%09// Initially try to in instantiate VTD-XML parser%0A%09%09%09%09
 parser =
   ne
@@ -2691,17 +2691,16 @@
 parser =
- 
  new ACS
@@ -2712,18 +2712,125 @@
 rser
-DOM
+VTD
 ();%0A%09%09
-%7D
+%09%09return parser;%0A%09%09%09%7D catch (Throwable t) %7B%0A%09%09%09%09usingVTD=false;%0A%09%09%09%7D%0A%09%09%7D %0A%09%09parser =  new ACSLogParserDOM();
 %0A%09%09r

Instantiate the VTD-XML if the package is installed.