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

changeset 515
6cd506508147
parent 384
8f2986ff0235
child 637
9c07ef4934dd
child 1609
09b083e0759c
equal deleted inserted replaced
514:29a761eaff0d 515:6cd506508147
1 /* 1 /*
2 * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2014, 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
60 private static final Logger LOGGER = Logger.getLogger(XMLStreamWriterFactory.class.getName()); 60 private static final Logger LOGGER = Logger.getLogger(XMLStreamWriterFactory.class.getName());
61 61
62 /** 62 /**
63 * Singleton instance. 63 * Singleton instance.
64 */ 64 */
65 private static volatile @NotNull XMLStreamWriterFactory theInstance; 65 private static volatile ContextClassloaderLocal<XMLStreamWriterFactory> writerFactory =
66 66 new ContextClassloaderLocal<XMLStreamWriterFactory>() {
67 67
68 static { 68 @Override
69 XMLOutputFactory xof = null; 69 protected XMLStreamWriterFactory initialValue() {
70 if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) { 70 XMLOutputFactory xof = null;
71 try { 71 if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
72 xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance(); 72 try {
73 } catch (Exception e) { 73 xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
74 // Ignore and fallback to default XMLOutputFactory 74 } catch (Exception e) {
75 } 75 // Ignore and fallback to default XMLOutputFactory
76 }
77 if (xof == null) {
78 xof = XMLOutputFactory.newInstance();
79 }
80
81 XMLStreamWriterFactory f=null;
82
83 // this system property can be used to disable the pooling altogether,
84 // in case someone hits an issue with pooling in the production system.
85 if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
86 try {
87 Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
88 if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
89 f = new Zephyr(xof,clazz);
90 } 76 }
91 } catch (XMLStreamException ex) { 77 }
92 Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); 78 if (xof == null) {
93 } catch (NoSuchMethodException ex) { 79 xof = XMLOutputFactory.newInstance();
94 Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex); 80 }
95 } 81
96 } 82 XMLStreamWriterFactory f=null;
97 83
98 if(f==null) { 84 // this system property can be used to disable the pooling altogether,
99 // is this Woodstox? 85 // in case someone hits an issue with pooling in the production system.
100 if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory")) 86 if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
101 f = new NoLock(xof); 87 try {
102 } 88 Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
103 if (f == null) 89 if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
104 f = new Default(xof); 90 f = new Zephyr(xof,clazz);
105 91 }
106 theInstance = f; 92 } catch (XMLStreamException ex) {
107 if (LOGGER.isLoggable(Level.FINE)) { 93 Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
108 LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f); 94 } catch (NoSuchMethodException ex) {
109 } 95 Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
110 } 96 }
97 }
98
99 if(f==null) {
100 // is this Woodstox?
101 if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
102 f = new NoLock(xof);
103 }
104 if (f == null)
105 f = new Default(xof);
106
107 if (LOGGER.isLoggable(Level.FINE)) {
108 LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
109 }
110 return f;
111 }
112 };
111 113
112 /** 114 /**
113 * See {@link #create(OutputStream)} for the contract. 115 * See {@link #create(OutputStream)} for the contract.
114 * This method may be invoked concurrently. 116 * This method may be invoked concurrently.
115 */ 117 */
168 170
169 /** 171 /**
170 * Gets the singleton instance. 172 * Gets the singleton instance.
171 */ 173 */
172 public static @NotNull XMLStreamWriterFactory get() { 174 public static @NotNull XMLStreamWriterFactory get() {
173 return theInstance; 175 return writerFactory.get();
174 } 176 }
175 177
176 /** 178 /**
177 * Overrides the singleton {@link XMLStreamWriterFactory} instance that 179 * Overrides the singleton {@link XMLStreamWriterFactory} instance that
178 * the JAX-WS RI uses. 180 * the JAX-WS RI uses.
181 * must not be null. 183 * must not be null.
182 */ 184 */
183 @SuppressWarnings({"null", "ConstantConditions"}) 185 @SuppressWarnings({"null", "ConstantConditions"})
184 public static void set(@NotNull XMLStreamWriterFactory f) { 186 public static void set(@NotNull XMLStreamWriterFactory f) {
185 if(f==null) throw new IllegalArgumentException(); 187 if(f==null) throw new IllegalArgumentException();
186 theInstance = f; 188 writerFactory.set(f);
187 } 189 }
188 190
189 /** 191 /**
190 * Short-cut for {@link #create(OutputStream, String)} with UTF-8. 192 * Short-cut for {@link #create(OutputStream, String)} with UTF-8.
191 */ 193 */

mercurial