src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamReaderFactory.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 397
b99d7e355d4b
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
26 package com.sun.xml.internal.ws.api.streaming; 26 package com.sun.xml.internal.ws.api.streaming;
27 27
28 import com.sun.istack.internal.NotNull; 28 import com.sun.istack.internal.NotNull;
29 import com.sun.istack.internal.Nullable; 29 import com.sun.istack.internal.Nullable;
30 import com.sun.xml.internal.ws.streaming.XMLReaderException; 30 import com.sun.xml.internal.ws.streaming.XMLReaderException;
31 import com.sun.xml.internal.ws.util.xml.XmlUtil;
31 import org.xml.sax.InputSource; 32 import org.xml.sax.InputSource;
32 33
33 import javax.xml.stream.XMLInputFactory; 34 import javax.xml.stream.XMLInputFactory;
34 import javax.xml.stream.XMLStreamException; 35 import javax.xml.stream.XMLStreamException;
35 import javax.xml.stream.XMLStreamReader; 36 import javax.xml.stream.XMLStreamReader;
36 import java.io.IOException; 37 import java.io.*;
37 import java.io.InputStream;
38 import java.io.InputStreamReader;
39 import java.io.Reader;
40 import java.io.StringReader;
41 import java.io.UnsupportedEncodingException;
42 import java.lang.reflect.InvocationTargetException; 38 import java.lang.reflect.InvocationTargetException;
43 import java.lang.reflect.Method; 39 import java.lang.reflect.Method;
44 import java.net.URL; 40 import java.net.URL;
41 import java.security.AccessController;
42 import java.util.logging.Level;
45 import java.util.logging.Logger; 43 import java.util.logging.Logger;
46 import java.security.AccessController;
47 44
48 /** 45 /**
49 * Factory for {@link XMLStreamReader}. 46 * Factory for {@link XMLStreamReader}.
50 * 47 *
51 * <p> 48 * <p>
52 * This wraps {@link XMLInputFactory} and allows us to reuse {@link XMLStreamReader} instances 49 * This wraps {@link XMLInputFactory} and allows us to reuse {@link XMLStreamReader} instances
53 * when appropriate. 50 * when appropriate.
54 * 51 *
55 * @author Kohsuke Kawaguchi 52 * @author Kohsuke Kawaguchi
56 */ 53 */
54 @SuppressWarnings("StaticNonFinalUsedInInitialization")
57 public abstract class XMLStreamReaderFactory { 55 public abstract class XMLStreamReaderFactory {
58 56
59 private static final Logger LOGGER = Logger.getLogger(XMLStreamReaderFactory.class.getName()); 57 private static final Logger LOGGER = Logger.getLogger(XMLStreamReaderFactory.class.getName());
60 58
61 /** 59 /**
67 XMLInputFactory xif = getXMLInputFactory(); 65 XMLInputFactory xif = getXMLInputFactory();
68 XMLStreamReaderFactory f=null; 66 XMLStreamReaderFactory f=null;
69 67
70 // this system property can be used to disable the pooling altogether, 68 // this system property can be used to disable the pooling altogether,
71 // in case someone hits an issue with pooling in the production system. 69 // in case someone hits an issue with pooling in the production system.
72 if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) 70 if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) {
73 f = Zephyr.newInstance(xif); 71 f = Zephyr.newInstance(xif);
72 }
74 73
75 if(f==null) { 74 if(f==null) {
76 // is this Woodstox? 75 // is this Woodstox?
77 if(xif.getClass().getName().equals("com.ctc.wstx.stax.WstxInputFactory")) 76 if (xif.getClass().getName().equals("com.ctc.wstx.stax.WstxInputFactory")) {
78 f = new Woodstox(xif); 77 f = new Woodstox(xif);
79 } 78 }
80 79 }
81 if(f==null) 80
81 if (f==null) {
82 f = new Default(); 82 f = new Default();
83 }
83 84
84 theInstance = f; 85 theInstance = f;
85 LOGGER.fine("XMLStreamReaderFactory instance is = "+theInstance); 86 LOGGER.log(Level.FINE, "XMLStreamReaderFactory instance is = {0}", theInstance);
86 } 87 }
87 88
88 private static XMLInputFactory getXMLInputFactory() { 89 private static XMLInputFactory getXMLInputFactory() {
89 XMLInputFactory xif = null; 90 XMLInputFactory xif = null;
90 if (getProperty(XMLStreamReaderFactory.class.getName()+".woodstox")) { 91 if (getProperty(XMLStreamReaderFactory.class.getName()+".woodstox")) {
93 } catch (Exception e) { 94 } catch (Exception e) {
94 // Ignore and fallback to default XMLInputFactory 95 // Ignore and fallback to default XMLInputFactory
95 } 96 }
96 } 97 }
97 if (xif == null) { 98 if (xif == null) {
98 xif = XMLInputFactory.newInstance(); 99 xif = XmlUtil.newXMLInputFactory(true);
99 } 100 }
100 xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true); 101 xif.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, true);
101 xif.setProperty(XMLInputFactory.SUPPORT_DTD, false); 102 xif.setProperty(XMLInputFactory.SUPPORT_DTD, false);
102 xif.setProperty(XMLInputFactory.IS_COALESCING, true); 103 xif.setProperty(XMLInputFactory.IS_COALESCING, true);
103 return xif; 104 return xif;
107 /** 108 /**
108 * Overrides the singleton {@link XMLStreamReaderFactory} instance that 109 * Overrides the singleton {@link XMLStreamReaderFactory} instance that
109 * the JAX-WS RI uses. 110 * the JAX-WS RI uses.
110 */ 111 */
111 public static void set(XMLStreamReaderFactory f) { 112 public static void set(XMLStreamReaderFactory f) {
112 if(f==null) throw new IllegalArgumentException(); 113 if(f==null) {
114 throw new IllegalArgumentException();
115 }
113 theInstance = f; 116 theInstance = f;
114 } 117 }
115 118
116 public static XMLStreamReaderFactory get() { 119 public static XMLStreamReaderFactory get() {
117 return theInstance; 120 return theInstance;
211 } 214 }
212 215
213 /** 216 /**
214 * {@link XMLStreamReaderFactory} implementation for SJSXP/JAXP RI. 217 * {@link XMLStreamReaderFactory} implementation for SJSXP/JAXP RI.
215 */ 218 */
216 public static final class Zephyr extends XMLStreamReaderFactory { 219 private static final class Zephyr extends XMLStreamReaderFactory {
217 private final XMLInputFactory xif; 220 private final XMLInputFactory xif;
218 221
219 private final ThreadLocal<XMLStreamReader> pool = new ThreadLocal<XMLStreamReader>(); 222 private final ThreadLocal<XMLStreamReader> pool = new ThreadLocal<XMLStreamReader>();
220 223
221 /** 224 /**

mercurial