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

changeset 558
d950f4a0753b
parent 515
6cd506508147
child 637
9c07ef4934dd
child 1609
09b083e0759c
     1.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Fri Feb 14 10:53:55 2014 +0100
     1.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Fri Feb 14 11:13:45 2014 +0100
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -62,52 +62,54 @@
    1.11      /**
    1.12       * Singleton instance.
    1.13       */
    1.14 -    private static volatile @NotNull XMLStreamWriterFactory theInstance;
    1.15 +    private static volatile ContextClassloaderLocal<XMLStreamWriterFactory> writerFactory =
    1.16 +            new ContextClassloaderLocal<XMLStreamWriterFactory>() {
    1.17  
    1.18 +        @Override
    1.19 +        protected XMLStreamWriterFactory initialValue() {
    1.20 +            XMLOutputFactory  xof = null;
    1.21 +            if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
    1.22 +                try {
    1.23 +                    xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
    1.24 +                } catch (Exception e) {
    1.25 +                    // Ignore and fallback to default XMLOutputFactory
    1.26 +                }
    1.27 +            }
    1.28 +            if (xof == null) {
    1.29 +                xof = XMLOutputFactory.newInstance();
    1.30 +            }
    1.31  
    1.32 -    static {
    1.33 -        XMLOutputFactory  xof = null;
    1.34 -        if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
    1.35 -            try {
    1.36 -                xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
    1.37 -            } catch (Exception e) {
    1.38 -                // Ignore and fallback to default XMLOutputFactory
    1.39 +            XMLStreamWriterFactory f=null;
    1.40 +
    1.41 +            // this system property can be used to disable the pooling altogether,
    1.42 +            // in case someone hits an issue with pooling in the production system.
    1.43 +            if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
    1.44 +                try {
    1.45 +                    Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
    1.46 +                    if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
    1.47 +                        f =  new Zephyr(xof,clazz);
    1.48 +                    }
    1.49 +                } catch (XMLStreamException ex) {
    1.50 +                    Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
    1.51 +                } catch (NoSuchMethodException ex) {
    1.52 +                    Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
    1.53 +                }
    1.54              }
    1.55 +
    1.56 +            if(f==null) {
    1.57 +                // is this Woodstox?
    1.58 +                if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
    1.59 +                    f = new NoLock(xof);
    1.60 +            }
    1.61 +            if (f == null)
    1.62 +                f = new Default(xof);
    1.63 +
    1.64 +            if (LOGGER.isLoggable(Level.FINE)) {
    1.65 +                LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
    1.66 +            }
    1.67 +            return f;
    1.68          }
    1.69 -        if (xof == null) {
    1.70 -            xof = XMLOutputFactory.newInstance();
    1.71 -        }
    1.72 -
    1.73 -        XMLStreamWriterFactory f=null;
    1.74 -
    1.75 -        // this system property can be used to disable the pooling altogether,
    1.76 -        // in case someone hits an issue with pooling in the production system.
    1.77 -        if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
    1.78 -            try {
    1.79 -                Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
    1.80 -                if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
    1.81 -                    f =  new Zephyr(xof,clazz);
    1.82 -                }
    1.83 -            } catch (XMLStreamException ex) {
    1.84 -                Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
    1.85 -            } catch (NoSuchMethodException ex) {
    1.86 -                Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
    1.87 -            }
    1.88 -        }
    1.89 -
    1.90 -        if(f==null) {
    1.91 -            // is this Woodstox?
    1.92 -            if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
    1.93 -                f = new NoLock(xof);
    1.94 -        }
    1.95 -        if (f == null)
    1.96 -            f = new Default(xof);
    1.97 -
    1.98 -        theInstance = f;
    1.99 -        if (LOGGER.isLoggable(Level.FINE)) {
   1.100 -            LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
   1.101 -        }
   1.102 -    }
   1.103 +    };
   1.104  
   1.105      /**
   1.106       * See {@link #create(OutputStream)} for the contract.
   1.107 @@ -170,7 +172,7 @@
   1.108       * Gets the singleton instance.
   1.109       */
   1.110      public static @NotNull XMLStreamWriterFactory get() {
   1.111 -        return theInstance;
   1.112 +        return writerFactory.get();
   1.113      }
   1.114  
   1.115      /**
   1.116 @@ -183,7 +185,7 @@
   1.117      @SuppressWarnings({"null", "ConstantConditions"})
   1.118      public static void set(@NotNull XMLStreamWriterFactory f) {
   1.119          if(f==null) throw new IllegalArgumentException();
   1.120 -        theInstance = f;
   1.121 +        writerFactory.set(f);
   1.122      }
   1.123  
   1.124      /**

mercurial