01: /*
02: * Copyright (c) 1998 - 2005 Versant Corporation
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * Versant Corporation - initial API and implementation
10: */
11: package com.versant.core.common;
12:
13: import javax.xml.parsers.SAXParserFactory;
14: import javax.xml.parsers.SAXParser;
15:
16: import com.versant.core.common.BindingSupportImpl;
17:
18: /**
19: * Utility methods to get hold of XML parsers.
20: */
21: public class JaxpUtils {
22:
23: private static final String SAX_PARSER_FACTORY_SYSPROP = "versant.SAXParserFactory";
24: private static final String SAX_PARSER_FACTORY_SYSPROP_OLD = "jdogenie.SAXParserFactory";
25:
26: /**
27: * Get a SAXParserFactory.
28: */
29: public static SAXParserFactory getSAXParserFactory() {
30: String parserFactoryName = System
31: .getProperty(SAX_PARSER_FACTORY_SYSPROP);
32: if (parserFactoryName == null) {
33: parserFactoryName = System
34: .getProperty(SAX_PARSER_FACTORY_SYSPROP_OLD);
35: }
36: SAXParserFactory parserFactory = null;
37: if (parserFactoryName != null) {
38: try {
39: Class cls = Class.forName(parserFactoryName);
40: parserFactory = (SAXParserFactory) cls.newInstance();
41: } catch (Throwable t) {
42: throw BindingSupportImpl.getInstance().runtime(
43: "Unable to create SAXParserFactory '"
44: + parserFactoryName + "': " + t, t);
45: }
46: System.out.println("Versant Open Access: Using "
47: + parserFactory);
48: } else {
49: parserFactory = SAXParserFactory.newInstance();
50: }
51: parserFactory.setValidating(false);
52: parserFactory.setNamespaceAware(false);
53: return parserFactory;
54: }
55:
56: /**
57: * Create a SAXParser from a factory. Throws a JDOFatalUserException if
58: * this fails for some reason.
59: */
60: public static SAXParser createSAXParser(
61: SAXParserFactory parserFactory) {
62: try {
63: return parserFactory.newSAXParser();
64: } catch (Throwable t) {
65: throw BindingSupportImpl
66: .getInstance()
67: .runtime(
68: "Unable to create SAXParser from factory: "
69: + parserFactory
70: + "\n"
71: + "Versant Open Access requires a JAXP 1.1 compliant parser. If this is not possible\n"
72: + "in your environment (e.g. WebLogic 6.0) try invoking java with\n"
73: + "-D"
74: + SAX_PARSER_FACTORY_SYSPROP
75: + "=<name of SAXParserFactory> to bypass JAXP\n"
76: + t, t);
77: }
78: }
79:
80: }
|