8026188: Enhance envelope factory jdk8u5-b09

Fri, 14 Feb 2014 11:13:45 +0100

author
mkos
date
Fri, 14 Feb 2014 11:13:45 +0100
changeset 515
6cd506508147
parent 514
29a761eaff0d
child 516
22a840b408eb

8026188: Enhance envelope factory
Summary: Avoiding caching data initialized via TCCL in static context; fix also reviewed by Alexander Fomin
Reviewed-by: ahgross, mgrebac, skoivu

src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/Internalizer.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/XMLStreamBuffer.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamReaderFactory.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/Converter.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/developer/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/developer/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/developer/MemberSubmissionEndpointReference.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ExternalAttachmentsUnmarshaller.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ProviderImpl.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/xsom/util/ContextClassloaderLocal.java file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/xsom/util/ContextClassloaderLocal.properties file | annotate | diff | comparison | revisions
src/share/jaxws_classes/com/sun/xml/internal/xsom/util/DomAnnotationParserFactory.java file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
     1.3 @@ -0,0 +1,86 @@
     1.4 +/*
     1.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package com.sun.tools.internal.ws.wsdl.parser;
    1.30 +
    1.31 +import java.security.AccessController;
    1.32 +import java.security.PrivilegedAction;
    1.33 +import java.text.MessageFormat;
    1.34 +import java.util.ResourceBundle;
    1.35 +import java.util.WeakHashMap;
    1.36 +
    1.37 +/**
    1.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
    1.39 + */
    1.40 +abstract class ContextClassloaderLocal<V> {
    1.41 +
    1.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
    1.43 +
    1.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
    1.45 +
    1.46 +    public V get() throws Error {
    1.47 +        ClassLoader tccl = getContextClassLoader();
    1.48 +        V instance = CACHE.get(tccl);
    1.49 +        if (instance == null) {
    1.50 +            instance = createNewInstance();
    1.51 +            CACHE.put(tccl, instance);
    1.52 +        }
    1.53 +        return instance;
    1.54 +    }
    1.55 +
    1.56 +    public void set(V instance) {
    1.57 +        CACHE.put(getContextClassLoader(), instance);
    1.58 +    }
    1.59 +
    1.60 +    protected abstract V initialValue() throws Exception;
    1.61 +
    1.62 +    private V createNewInstance() {
    1.63 +        try {
    1.64 +            return initialValue();
    1.65 +        } catch (Exception e) {
    1.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
    1.67 +        }
    1.68 +    }
    1.69 +
    1.70 +    private static String format(String property, Object... args) {
    1.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
    1.72 +        return MessageFormat.format(text, args);
    1.73 +    }
    1.74 +
    1.75 +    private static ClassLoader getContextClassLoader() {
    1.76 +        return (ClassLoader)
    1.77 +                AccessController.doPrivileged(new PrivilegedAction() {
    1.78 +                    public Object run() {
    1.79 +                        ClassLoader cl = null;
    1.80 +                        try {
    1.81 +                            cl = Thread.currentThread().getContextClassLoader();
    1.82 +                        } catch (SecurityException ex) {
    1.83 +                        }
    1.84 +                        return cl;
    1.85 +                    }
    1.86 +                });
    1.87 +    }
    1.88 +}
    1.89 +
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
     2.3 @@ -0,0 +1,27 @@
     2.4 +#
     2.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     2.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 +#
     2.8 +# This code is free software; you can redistribute it and/or modify it
     2.9 +# under the terms of the GNU General Public License version 2 only, as
    2.10 +# published by the Free Software Foundation.  Oracle designates this
    2.11 +# particular file as subject to the "Classpath" exception as provided
    2.12 +# by Oracle in the LICENSE file that accompanied this code.
    2.13 +#
    2.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    2.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.17 +# version 2 for more details (a copy is included in the LICENSE file that
    2.18 +# accompanied this code).
    2.19 +#
    2.20 +# You should have received a copy of the GNU General Public License version
    2.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    2.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.23 +#
    2.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.25 +# or visit www.oracle.com if you need additional information or have any
    2.26 +# questions.
    2.27 +#
    2.28 +# Error messages for ContextClassloaderLocal utility class
    2.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
    2.30 +
     3.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java	Fri Feb 14 10:53:55 2014 +0100
     3.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/Internalizer.java	Fri Feb 14 11:13:45 2014 +0100
     3.3 @@ -1,5 +1,5 @@
     3.4  /*
     3.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     3.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.8   *
     3.9   * This code is free software; you can redistribute it and/or modify it
    3.10 @@ -60,12 +60,10 @@
    3.11   */
    3.12  public class Internalizer {
    3.13  
    3.14 -    private static final XPathFactory xpf = XmlUtil.newXPathFactory(true);
    3.15 -    private final XPath xpath = xpf.newXPath();
    3.16 +    private final XPath xpath = xpf.get().newXPath();
    3.17      private final DOMForest forest;
    3.18      private final ErrorReceiver errorReceiver;
    3.19  
    3.20 -
    3.21      public Internalizer(DOMForest forest, WsimportOptions options, ErrorReceiver errorReceiver) {
    3.22          this.forest = forest;
    3.23          this.errorReceiver = errorReceiver;
    3.24 @@ -77,6 +75,12 @@
    3.25          }
    3.26      }
    3.27  
    3.28 +    private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
    3.29 +        @Override
    3.30 +        protected XPathFactory initialValue() throws Exception {
    3.31 +            return XPathFactory.newInstance();
    3.32 +        }
    3.33 +    };
    3.34      /**
    3.35       * Validates attributes of a &lt;JAXWS:bindings> element.
    3.36       */
     4.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java	Fri Feb 14 10:53:55 2014 +0100
     4.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/ws/wsdl/parser/JAXWSBindingExtensionHandler.java	Fri Feb 14 11:13:45 2014 +0100
     4.3 @@ -1,5 +1,5 @@
     4.4  /*
     4.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
     4.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     4.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4.8   *
     4.9   * This code is free software; you can redistribute it and/or modify it
    4.10 @@ -54,8 +54,14 @@
    4.11  public class JAXWSBindingExtensionHandler extends AbstractExtensionHandler {
    4.12  
    4.13      // xml security enabled always, xpath used for parsing "part" attribute
    4.14 -    private static final XPathFactory xpf = XmlUtil.newXPathFactory(true);
    4.15 -    private final XPath xpath = xpf.newXPath();
    4.16 +    private static final ContextClassloaderLocal<XPathFactory> xpf = new ContextClassloaderLocal<XPathFactory>() {
    4.17 +        @Override
    4.18 +        protected XPathFactory initialValue() throws Exception {
    4.19 +            return XPathFactory.newInstance();
    4.20 +        }
    4.21 +    };
    4.22 +
    4.23 +    private final XPath xpath = xpf.get().newXPath();
    4.24  
    4.25      public JAXWSBindingExtensionHandler(Map<String, AbstractExtensionHandler> extensionHandlerMap) {
    4.26          super(extensionHandlerMap);
     5.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     5.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
     5.3 @@ -0,0 +1,86 @@
     5.4 +/*
     5.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     5.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     5.7 + *
     5.8 + * This code is free software; you can redistribute it and/or modify it
     5.9 + * under the terms of the GNU General Public License version 2 only, as
    5.10 + * published by the Free Software Foundation.  Oracle designates this
    5.11 + * particular file as subject to the "Classpath" exception as provided
    5.12 + * by Oracle in the LICENSE file that accompanied this code.
    5.13 + *
    5.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    5.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    5.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    5.17 + * version 2 for more details (a copy is included in the LICENSE file that
    5.18 + * accompanied this code).
    5.19 + *
    5.20 + * You should have received a copy of the GNU General Public License version
    5.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    5.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    5.23 + *
    5.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    5.25 + * or visit www.oracle.com if you need additional information or have any
    5.26 + * questions.
    5.27 + */
    5.28 +
    5.29 +package com.sun.tools.internal.xjc.reader.internalizer;
    5.30 +
    5.31 +import java.security.AccessController;
    5.32 +import java.security.PrivilegedAction;
    5.33 +import java.text.MessageFormat;
    5.34 +import java.util.ResourceBundle;
    5.35 +import java.util.WeakHashMap;
    5.36 +
    5.37 +/**
    5.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
    5.39 + */
    5.40 +abstract class ContextClassloaderLocal<V> {
    5.41 +
    5.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
    5.43 +
    5.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
    5.45 +
    5.46 +    public V get() throws Error {
    5.47 +        ClassLoader tccl = getContextClassLoader();
    5.48 +        V instance = CACHE.get(tccl);
    5.49 +        if (instance == null) {
    5.50 +            instance = createNewInstance();
    5.51 +            CACHE.put(tccl, instance);
    5.52 +        }
    5.53 +        return instance;
    5.54 +    }
    5.55 +
    5.56 +    public void set(V instance) {
    5.57 +        CACHE.put(getContextClassLoader(), instance);
    5.58 +    }
    5.59 +
    5.60 +    protected abstract V initialValue() throws Exception;
    5.61 +
    5.62 +    private V createNewInstance() {
    5.63 +        try {
    5.64 +            return initialValue();
    5.65 +        } catch (Exception e) {
    5.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
    5.67 +        }
    5.68 +    }
    5.69 +
    5.70 +    private static String format(String property, Object... args) {
    5.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
    5.72 +        return MessageFormat.format(text, args);
    5.73 +    }
    5.74 +
    5.75 +    private static ClassLoader getContextClassLoader() {
    5.76 +        return (ClassLoader)
    5.77 +                AccessController.doPrivileged(new PrivilegedAction() {
    5.78 +                    public Object run() {
    5.79 +                        ClassLoader cl = null;
    5.80 +                        try {
    5.81 +                            cl = Thread.currentThread().getContextClassLoader();
    5.82 +                        } catch (SecurityException ex) {
    5.83 +                        }
    5.84 +                        return cl;
    5.85 +                    }
    5.86 +                });
    5.87 +    }
    5.88 +}
    5.89 +
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
     6.3 @@ -0,0 +1,27 @@
     6.4 +#
     6.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     6.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 +#
     6.8 +# This code is free software; you can redistribute it and/or modify it
     6.9 +# under the terms of the GNU General Public License version 2 only, as
    6.10 +# published by the Free Software Foundation.  Oracle designates this
    6.11 +# particular file as subject to the "Classpath" exception as provided
    6.12 +# by Oracle in the LICENSE file that accompanied this code.
    6.13 +#
    6.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 +# version 2 for more details (a copy is included in the LICENSE file that
    6.18 +# accompanied this code).
    6.19 +#
    6.20 +# You should have received a copy of the GNU General Public License version
    6.21 +# 2 along with this work; if not, write to the Free Software Foundation,
    6.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 +#
    6.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    6.25 +# or visit www.oracle.com if you need additional information or have any
    6.26 +# questions.
    6.27 +#
    6.28 +# Error messages for ContextClassloaderLocal utility class
    6.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
    6.30 +
     7.1 --- a/src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/Internalizer.java	Fri Feb 14 10:53:55 2014 +0100
     7.2 +++ b/src/share/jaxws_classes/com/sun/tools/internal/xjc/reader/internalizer/Internalizer.java	Fri Feb 14 11:13:45 2014 +0100
     7.3 @@ -1,5 +1,5 @@
     7.4  /*
     7.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
     7.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
     7.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.8   *
     7.9   * This code is free software; you can redistribute it and/or modify it
    7.10 @@ -76,8 +76,6 @@
    7.11  
    7.12      private static final String WSDL_NS = "http://schemas.xmlsoap.org/wsdl/";
    7.13  
    7.14 -    private static XPathFactory xpf = null;
    7.15 -
    7.16      private final XPath xpath;
    7.17  
    7.18      /**
    7.19 @@ -99,12 +97,7 @@
    7.20          this.errorHandler = forest.getErrorHandler();
    7.21          this.forest = forest;
    7.22          this.enableSCD = enableSCD;
    7.23 -        synchronized (this) {
    7.24 -            if (xpf == null) {
    7.25 -                xpf = XmlFactory.createXPathFactory(disableSecureProcessing);
    7.26 -            }
    7.27 -        }
    7.28 -        xpath = xpf.newXPath();
    7.29 +        xpath = XmlFactory.createXPathFactory(disableSecureProcessing).newXPath();
    7.30      }
    7.31  
    7.32      /**
     8.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java	Fri Feb 14 10:53:55 2014 +0100
     8.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/bind/v2/runtime/JAXBContextImpl.java	Fri Feb 14 11:13:45 2014 +0100
     8.3 @@ -129,14 +129,6 @@
     8.4      private final Map<TypeReference,Bridge> bridges = new LinkedHashMap<TypeReference,Bridge>();
     8.5  
     8.6      /**
     8.7 -     * Shared instance of {@link TransformerFactory}.
     8.8 -     * Lock before use, because a {@link TransformerFactory} is not thread-safe
     8.9 -     * whereas {@link JAXBContextImpl} is.
    8.10 -     * Lazily created.
    8.11 -     */
    8.12 -    private volatile static SAXTransformerFactory tf;
    8.13 -
    8.14 -    /**
    8.15       * Shared instance of {@link DocumentBuilder}.
    8.16       * Lock before use. Lazily created.
    8.17       */
    8.18 @@ -705,13 +697,7 @@
    8.19       */
    8.20      static Transformer createTransformer(boolean disableSecureProcessing) {
    8.21          try {
    8.22 -            if (tf==null) {
    8.23 -                synchronized(JAXBContextImpl.class) {
    8.24 -                    if (tf==null) {
    8.25 -                        tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
    8.26 -                    }
    8.27 -                }
    8.28 -            }
    8.29 +            SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
    8.30              return tf.newTransformer();
    8.31          } catch (TransformerConfigurationException e) {
    8.32              throw new Error(e); // impossible
    8.33 @@ -723,13 +709,7 @@
    8.34       */
    8.35      public static TransformerHandler createTransformerHandler(boolean disableSecureProcessing) {
    8.36          try {
    8.37 -            if (tf==null) {
    8.38 -                synchronized(JAXBContextImpl.class) {
    8.39 -                    if (tf==null) {
    8.40 -                        tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
    8.41 -                    }
    8.42 -                }
    8.43 -            }
    8.44 +            SAXTransformerFactory tf = (SAXTransformerFactory)XmlFactory.createTransformerFactory(disableSecureProcessing);
    8.45              return tf.newTransformerHandler();
    8.46          } catch (TransformerConfigurationException e) {
    8.47              throw new Error(e); // impossible
     9.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     9.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
     9.3 @@ -0,0 +1,86 @@
     9.4 +/*
     9.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
     9.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     9.7 + *
     9.8 + * This code is free software; you can redistribute it and/or modify it
     9.9 + * under the terms of the GNU General Public License version 2 only, as
    9.10 + * published by the Free Software Foundation.  Oracle designates this
    9.11 + * particular file as subject to the "Classpath" exception as provided
    9.12 + * by Oracle in the LICENSE file that accompanied this code.
    9.13 + *
    9.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    9.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    9.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    9.17 + * version 2 for more details (a copy is included in the LICENSE file that
    9.18 + * accompanied this code).
    9.19 + *
    9.20 + * You should have received a copy of the GNU General Public License version
    9.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    9.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    9.23 + *
    9.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    9.25 + * or visit www.oracle.com if you need additional information or have any
    9.26 + * questions.
    9.27 + */
    9.28 +
    9.29 +package com.sun.xml.internal.messaging.saaj.soap;
    9.30 +
    9.31 +import java.security.AccessController;
    9.32 +import java.security.PrivilegedAction;
    9.33 +import java.text.MessageFormat;
    9.34 +import java.util.ResourceBundle;
    9.35 +import java.util.WeakHashMap;
    9.36 +
    9.37 +/**
    9.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
    9.39 + */
    9.40 +abstract class ContextClassloaderLocal<V> {
    9.41 +
    9.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
    9.43 +
    9.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
    9.45 +
    9.46 +    public V get() throws Error {
    9.47 +        ClassLoader tccl = getContextClassLoader();
    9.48 +        V instance = CACHE.get(tccl);
    9.49 +        if (instance == null) {
    9.50 +            instance = createNewInstance();
    9.51 +            CACHE.put(tccl, instance);
    9.52 +        }
    9.53 +        return instance;
    9.54 +    }
    9.55 +
    9.56 +    public void set(V instance) {
    9.57 +        CACHE.put(getContextClassLoader(), instance);
    9.58 +    }
    9.59 +
    9.60 +    protected abstract V initialValue() throws Exception;
    9.61 +
    9.62 +    private V createNewInstance() {
    9.63 +        try {
    9.64 +            return initialValue();
    9.65 +        } catch (Exception e) {
    9.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
    9.67 +        }
    9.68 +    }
    9.69 +
    9.70 +    private static String format(String property, Object... args) {
    9.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
    9.72 +        return MessageFormat.format(text, args);
    9.73 +    }
    9.74 +
    9.75 +    private static ClassLoader getContextClassLoader() {
    9.76 +        return (ClassLoader)
    9.77 +                AccessController.doPrivileged(new PrivilegedAction() {
    9.78 +                    public Object run() {
    9.79 +                        ClassLoader cl = null;
    9.80 +                        try {
    9.81 +                            cl = Thread.currentThread().getContextClassLoader();
    9.82 +                        } catch (SecurityException ex) {
    9.83 +                        }
    9.84 +                        return cl;
    9.85 +                    }
    9.86 +                });
    9.87 +    }
    9.88 +}
    9.89 +
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    10.3 @@ -0,0 +1,27 @@
    10.4 +#
    10.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    10.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    10.7 +#
    10.8 +# This code is free software; you can redistribute it and/or modify it
    10.9 +# under the terms of the GNU General Public License version 2 only, as
   10.10 +# published by the Free Software Foundation.  Oracle designates this
   10.11 +# particular file as subject to the "Classpath" exception as provided
   10.12 +# by Oracle in the LICENSE file that accompanied this code.
   10.13 +#
   10.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   10.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   10.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   10.17 +# version 2 for more details (a copy is included in the LICENSE file that
   10.18 +# accompanied this code).
   10.19 +#
   10.20 +# You should have received a copy of the GNU General Public License version
   10.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   10.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   10.23 +#
   10.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   10.25 +# or visit www.oracle.com if you need additional information or have any
   10.26 +# questions.
   10.27 +#
   10.28 +# Error messages for StaticCache utility class
   10.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   10.30 +
    11.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java	Fri Feb 14 10:53:55 2014 +0100
    11.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/messaging/saaj/soap/EnvelopeFactory.java	Fri Feb 14 11:13:45 2014 +0100
    11.3 @@ -1,5 +1,5 @@
    11.4  /*
    11.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
    11.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    11.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    11.8   *
    11.9   * This code is free software; you can redistribute it and/or modify it
   11.10 @@ -25,7 +25,14 @@
   11.11  
   11.12  package com.sun.xml.internal.messaging.saaj.soap;
   11.13  
   11.14 -import java.util.logging.Logger;
   11.15 +import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
   11.16 +import com.sun.xml.internal.messaging.saaj.util.JAXMStreamSource;
   11.17 +import com.sun.xml.internal.messaging.saaj.util.LogDomainConstants;
   11.18 +import com.sun.xml.internal.messaging.saaj.util.ParserPool;
   11.19 +import com.sun.xml.internal.messaging.saaj.util.RejectDoctypeSaxFilter;
   11.20 +import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
   11.21 +import org.xml.sax.InputSource;
   11.22 +import org.xml.sax.XMLReader;
   11.23  
   11.24  import javax.xml.parsers.SAXParser;
   11.25  import javax.xml.soap.SOAPException;
   11.26 @@ -34,14 +41,7 @@
   11.27  import javax.xml.transform.dom.DOMResult;
   11.28  import javax.xml.transform.sax.SAXSource;
   11.29  import javax.xml.transform.stream.StreamSource;
   11.30 -
   11.31 -import org.xml.sax.InputSource;
   11.32 -import org.xml.sax.XMLReader;
   11.33 -
   11.34 -import com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl;
   11.35 -import com.sun.xml.internal.messaging.saaj.util.*;
   11.36 -
   11.37 -import com.sun.xml.internal.messaging.saaj.util.transform.EfficientStreamingTransformer;
   11.38 +import java.util.logging.Logger;
   11.39  
   11.40  /**
   11.41   * EnvelopeFactory creates SOAP Envelope objects using different
   11.42 @@ -50,14 +50,19 @@
   11.43  public class EnvelopeFactory {
   11.44  
   11.45      protected static final Logger
   11.46 -        log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
   11.47 -        "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
   11.48 +            log = Logger.getLogger(LogDomainConstants.SOAP_DOMAIN,
   11.49 +            "com.sun.xml.internal.messaging.saaj.soap.LocalStrings");
   11.50  
   11.51 -    private static ParserPool parserPool = new ParserPool(5);
   11.52 +    private static ContextClassloaderLocal<ParserPool> parserPool =
   11.53 +            new ContextClassloaderLocal<ParserPool>() {
   11.54 +                @Override
   11.55 +                protected ParserPool initialValue() throws Exception {
   11.56 +                    return new ParserPool(5);
   11.57 +                }
   11.58 +            };
   11.59  
   11.60      public static Envelope createEnvelope(Source src, SOAPPartImpl soapPart)
   11.61 -        throws SOAPException
   11.62 -    {
   11.63 +            throws SOAPException {
   11.64          // Insert SAX filter to disallow Document Type Declarations since
   11.65          // they are not legal in SOAP
   11.66          SAXParser saxParser = null;
   11.67 @@ -73,15 +78,15 @@
   11.68                  }
   11.69              }
   11.70              try {
   11.71 -                saxParser = parserPool.get();
   11.72 +                saxParser = parserPool.get().get();
   11.73              } catch (Exception e) {
   11.74                  log.severe("SAAJ0601.util.newSAXParser.exception");
   11.75                  throw new SOAPExceptionImpl(
   11.76 -                    "Couldn't get a SAX parser while constructing a envelope",
   11.77 -                    e);
   11.78 +                        "Couldn't get a SAX parser while constructing a envelope",
   11.79 +                        e);
   11.80              }
   11.81              InputSource is = SAXSource.sourceToInputSource(src);
   11.82 -            if (is.getEncoding()== null && soapPart.getSourceCharsetEncoding() != null) {
   11.83 +            if (is.getEncoding() == null && soapPart.getSourceCharsetEncoding() != null) {
   11.84                  is.setEncoding(soapPart.getSourceCharsetEncoding());
   11.85              }
   11.86              XMLReader rejectFilter;
   11.87 @@ -90,15 +95,15 @@
   11.88              } catch (Exception ex) {
   11.89                  log.severe("SAAJ0510.soap.cannot.create.envelope");
   11.90                  throw new SOAPExceptionImpl(
   11.91 -                    "Unable to create envelope from given source: ",
   11.92 -                    ex);
   11.93 +                        "Unable to create envelope from given source: ",
   11.94 +                        ex);
   11.95              }
   11.96              src = new SAXSource(rejectFilter, is);
   11.97          }
   11.98  
   11.99          try {
  11.100              Transformer transformer =
  11.101 -                EfficientStreamingTransformer.newTransformer();
  11.102 +                    EfficientStreamingTransformer.newTransformer();
  11.103              DOMResult result = new DOMResult(soapPart);
  11.104              transformer.transform(src, result);
  11.105  
  11.106 @@ -110,11 +115,11 @@
  11.107              }
  11.108              log.severe("SAAJ0511.soap.cannot.create.envelope");
  11.109              throw new SOAPExceptionImpl(
  11.110 -                "Unable to create envelope from given source: ",
  11.111 -                ex);
  11.112 +                    "Unable to create envelope from given source: ",
  11.113 +                    ex);
  11.114          } finally {
  11.115              if (saxParser != null) {
  11.116 -                parserPool.returnParser(saxParser);
  11.117 +                parserPool.get().returnParser(saxParser);
  11.118              }
  11.119          }
  11.120      }
    12.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    12.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    12.3 @@ -0,0 +1,86 @@
    12.4 +/*
    12.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    12.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    12.7 + *
    12.8 + * This code is free software; you can redistribute it and/or modify it
    12.9 + * under the terms of the GNU General Public License version 2 only, as
   12.10 + * published by the Free Software Foundation.  Oracle designates this
   12.11 + * particular file as subject to the "Classpath" exception as provided
   12.12 + * by Oracle in the LICENSE file that accompanied this code.
   12.13 + *
   12.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   12.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   12.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   12.17 + * version 2 for more details (a copy is included in the LICENSE file that
   12.18 + * accompanied this code).
   12.19 + *
   12.20 + * You should have received a copy of the GNU General Public License version
   12.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   12.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   12.23 + *
   12.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   12.25 + * or visit www.oracle.com if you need additional information or have any
   12.26 + * questions.
   12.27 + */
   12.28 +
   12.29 +package com.sun.xml.internal.stream.buffer;
   12.30 +
   12.31 +import java.security.AccessController;
   12.32 +import java.security.PrivilegedAction;
   12.33 +import java.text.MessageFormat;
   12.34 +import java.util.ResourceBundle;
   12.35 +import java.util.WeakHashMap;
   12.36 +
   12.37 +/**
   12.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   12.39 + */
   12.40 +abstract class ContextClassloaderLocal<V> {
   12.41 +
   12.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   12.43 +
   12.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   12.45 +
   12.46 +    public V get() throws Error {
   12.47 +        ClassLoader tccl = getContextClassLoader();
   12.48 +        V instance = CACHE.get(tccl);
   12.49 +        if (instance == null) {
   12.50 +            instance = createNewInstance();
   12.51 +            CACHE.put(tccl, instance);
   12.52 +        }
   12.53 +        return instance;
   12.54 +    }
   12.55 +
   12.56 +    public void set(V instance) {
   12.57 +        CACHE.put(getContextClassLoader(), instance);
   12.58 +    }
   12.59 +
   12.60 +    protected abstract V initialValue() throws Exception;
   12.61 +
   12.62 +    private V createNewInstance() {
   12.63 +        try {
   12.64 +            return initialValue();
   12.65 +        } catch (Exception e) {
   12.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   12.67 +        }
   12.68 +    }
   12.69 +
   12.70 +    private static String format(String property, Object... args) {
   12.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   12.72 +        return MessageFormat.format(text, args);
   12.73 +    }
   12.74 +
   12.75 +    private static ClassLoader getContextClassLoader() {
   12.76 +        return (ClassLoader)
   12.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   12.78 +                    public Object run() {
   12.79 +                        ClassLoader cl = null;
   12.80 +                        try {
   12.81 +                            cl = Thread.currentThread().getContextClassLoader();
   12.82 +                        } catch (SecurityException ex) {
   12.83 +                        }
   12.84 +                        return cl;
   12.85 +                    }
   12.86 +                });
   12.87 +    }
   12.88 +}
   12.89 +
    13.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    13.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    13.3 @@ -0,0 +1,27 @@
    13.4 +#
    13.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    13.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    13.7 +#
    13.8 +# This code is free software; you can redistribute it and/or modify it
    13.9 +# under the terms of the GNU General Public License version 2 only, as
   13.10 +# published by the Free Software Foundation.  Oracle designates this
   13.11 +# particular file as subject to the "Classpath" exception as provided
   13.12 +# by Oracle in the LICENSE file that accompanied this code.
   13.13 +#
   13.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   13.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   13.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   13.17 +# version 2 for more details (a copy is included in the LICENSE file that
   13.18 +# accompanied this code).
   13.19 +#
   13.20 +# You should have received a copy of the GNU General Public License version
   13.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   13.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   13.23 +#
   13.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   13.25 +# or visit www.oracle.com if you need additional information or have any
   13.26 +# questions.
   13.27 +#
   13.28 +# Error messages for ContextClassloaderLocal utility class
   13.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   13.30 +
    14.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/XMLStreamBuffer.java	Fri Feb 14 10:53:55 2014 +0100
    14.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/stream/buffer/XMLStreamBuffer.java	Fri Feb 14 11:13:45 2014 +0100
    14.3 @@ -1,5 +1,5 @@
    14.4  /*
    14.5 - * Copyright (c) 2005, 2013, Oracle and/or its affiliates. All rights reserved.
    14.6 + * Copyright (c) 2005, 2014, Oracle and/or its affiliates. All rights reserved.
    14.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    14.8   *
    14.9   * This code is free software; you can redistribute it and/or modify it
   14.10 @@ -370,7 +370,12 @@
   14.11          writeTo(handler, errorHandler, isFragment());
   14.12      }
   14.13  
   14.14 -    private static final TransformerFactory trnsformerFactory = TransformerFactory.newInstance();
   14.15 +    private static final ContextClassloaderLocal<TransformerFactory> trnsformerFactory = new ContextClassloaderLocal<TransformerFactory>() {
   14.16 +        @Override
   14.17 +        protected TransformerFactory initialValue() throws Exception {
   14.18 +            return TransformerFactory.newInstance();
   14.19 +        }
   14.20 +    };
   14.21  
   14.22      /**
   14.23       * Writes out the contents of this buffer as DOM node and append that to the given node.
   14.24 @@ -382,7 +387,7 @@
   14.25       */
   14.26      public final Node writeTo(Node n) throws XMLStreamBufferException {
   14.27          try {
   14.28 -            Transformer t = trnsformerFactory.newTransformer();
   14.29 +            Transformer t = trnsformerFactory.get().newTransformer();
   14.30              t.transform(new XMLStreamBufferSource(this), new DOMResult(n));
   14.31              return n.getLastChild();
   14.32          } catch (TransformerException e) {
    15.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    15.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    15.3 @@ -0,0 +1,86 @@
    15.4 +/*
    15.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    15.7 + *
    15.8 + * This code is free software; you can redistribute it and/or modify it
    15.9 + * under the terms of the GNU General Public License version 2 only, as
   15.10 + * published by the Free Software Foundation.  Oracle designates this
   15.11 + * particular file as subject to the "Classpath" exception as provided
   15.12 + * by Oracle in the LICENSE file that accompanied this code.
   15.13 + *
   15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   15.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   15.17 + * version 2 for more details (a copy is included in the LICENSE file that
   15.18 + * accompanied this code).
   15.19 + *
   15.20 + * You should have received a copy of the GNU General Public License version
   15.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   15.23 + *
   15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   15.25 + * or visit www.oracle.com if you need additional information or have any
   15.26 + * questions.
   15.27 + */
   15.28 +
   15.29 +package com.sun.xml.internal.ws.api.streaming;
   15.30 +
   15.31 +import java.security.AccessController;
   15.32 +import java.security.PrivilegedAction;
   15.33 +import java.text.MessageFormat;
   15.34 +import java.util.ResourceBundle;
   15.35 +import java.util.WeakHashMap;
   15.36 +
   15.37 +/**
   15.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   15.39 + */
   15.40 +abstract class ContextClassloaderLocal<V> {
   15.41 +
   15.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   15.43 +
   15.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   15.45 +
   15.46 +    public V get() throws Error {
   15.47 +        ClassLoader tccl = getContextClassLoader();
   15.48 +        V instance = CACHE.get(tccl);
   15.49 +        if (instance == null) {
   15.50 +            instance = createNewInstance();
   15.51 +            CACHE.put(tccl, instance);
   15.52 +        }
   15.53 +        return instance;
   15.54 +    }
   15.55 +
   15.56 +    public void set(V instance) {
   15.57 +        CACHE.put(getContextClassLoader(), instance);
   15.58 +    }
   15.59 +
   15.60 +    protected abstract V initialValue() throws Exception;
   15.61 +
   15.62 +    private V createNewInstance() {
   15.63 +        try {
   15.64 +            return initialValue();
   15.65 +        } catch (Exception e) {
   15.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   15.67 +        }
   15.68 +    }
   15.69 +
   15.70 +    private static String format(String property, Object... args) {
   15.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   15.72 +        return MessageFormat.format(text, args);
   15.73 +    }
   15.74 +
   15.75 +    private static ClassLoader getContextClassLoader() {
   15.76 +        return (ClassLoader)
   15.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   15.78 +                    public Object run() {
   15.79 +                        ClassLoader cl = null;
   15.80 +                        try {
   15.81 +                            cl = Thread.currentThread().getContextClassLoader();
   15.82 +                        } catch (SecurityException ex) {
   15.83 +                        }
   15.84 +                        return cl;
   15.85 +                    }
   15.86 +                });
   15.87 +    }
   15.88 +}
   15.89 +
    16.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    16.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    16.3 @@ -0,0 +1,27 @@
    16.4 +#
    16.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    16.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    16.7 +#
    16.8 +# This code is free software; you can redistribute it and/or modify it
    16.9 +# under the terms of the GNU General Public License version 2 only, as
   16.10 +# published by the Free Software Foundation.  Oracle designates this
   16.11 +# particular file as subject to the "Classpath" exception as provided
   16.12 +# by Oracle in the LICENSE file that accompanied this code.
   16.13 +#
   16.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   16.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   16.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   16.17 +# version 2 for more details (a copy is included in the LICENSE file that
   16.18 +# accompanied this code).
   16.19 +#
   16.20 +# You should have received a copy of the GNU General Public License version
   16.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   16.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   16.23 +#
   16.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   16.25 +# or visit www.oracle.com if you need additional information or have any
   16.26 +# questions.
   16.27 +#
   16.28 +# Error messages for ContextClassloaderLocal utility class
   16.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   16.30 +
    17.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamReaderFactory.java	Fri Feb 14 10:53:55 2014 +0100
    17.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamReaderFactory.java	Fri Feb 14 11:13:45 2014 +0100
    17.3 @@ -1,5 +1,5 @@
    17.4  /*
    17.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    17.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    17.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    17.8   *
    17.9   * This code is free software; you can redistribute it and/or modify it
   17.10 @@ -63,39 +63,43 @@
   17.11  
   17.12      private static final Logger LOGGER = Logger.getLogger(XMLStreamReaderFactory.class.getName());
   17.13  
   17.14 +    private static final String CLASS_NAME_OF_WSTXINPUTFACTORY = "com.ctc.wstx.stax.WstxInputFactory";
   17.15 +
   17.16      /**
   17.17       * Singleton instance.
   17.18       */
   17.19 -    private static volatile @NotNull XMLStreamReaderFactory theInstance;
   17.20 +    private static volatile ContextClassloaderLocal<XMLStreamReaderFactory> streamReader =
   17.21 +            new ContextClassloaderLocal<XMLStreamReaderFactory>() {
   17.22  
   17.23 -    private static final String CLASS_NAME_OF_WSTXINPUTFACTORY = "com.ctc.wstx.stax.WstxInputFactory";
   17.24 +                @Override
   17.25 +                protected XMLStreamReaderFactory initialValue() {
   17.26  
   17.27 -    static {
   17.28 -        XMLInputFactory xif = getXMLInputFactory();
   17.29 -        XMLStreamReaderFactory f=null;
   17.30 +                    XMLInputFactory xif = getXMLInputFactory();
   17.31 +                    XMLStreamReaderFactory f=null;
   17.32  
   17.33 -        // this system property can be used to disable the pooling altogether,
   17.34 -        // in case someone hits an issue with pooling in the production system.
   17.35 -        if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) {
   17.36 -            f = Zephyr.newInstance(xif);
   17.37 -        }
   17.38 +                    // this system property can be used to disable the pooling altogether,
   17.39 +                    // in case someone hits an issue with pooling in the production system.
   17.40 +                    if(!getProperty(XMLStreamReaderFactory.class.getName()+".noPool")) {
   17.41 +                        f = Zephyr.newInstance(xif);
   17.42 +                    }
   17.43  
   17.44 -        if(f==null) {
   17.45 -            // is this Woodstox?
   17.46 -            if (xif.getClass().getName().equals(CLASS_NAME_OF_WSTXINPUTFACTORY)) {
   17.47 -                f = new Woodstox(xif);
   17.48 -            }
   17.49 -        }
   17.50 +                    if(f==null) {
   17.51 +                        // is this Woodstox?
   17.52 +                        if (xif.getClass().getName().equals(CLASS_NAME_OF_WSTXINPUTFACTORY)) {
   17.53 +                            f = new Woodstox(xif);
   17.54 +                        }
   17.55 +                    }
   17.56  
   17.57 -        if (f==null) {
   17.58 -            f = new Default();
   17.59 -        }
   17.60 +                    if (f==null) {
   17.61 +                        f = new Default();
   17.62 +                    }
   17.63  
   17.64 -        theInstance = f;
   17.65 -        if (LOGGER.isLoggable(Level.FINE)) {
   17.66 -            LOGGER.log(Level.FINE, "XMLStreamReaderFactory instance is = {0}", theInstance);
   17.67 -        }
   17.68 -    }
   17.69 +                    if (LOGGER.isLoggable(Level.FINE)) {
   17.70 +                        LOGGER.log(Level.FINE, "XMLStreamReaderFactory instance is = {0}", f);
   17.71 +                    }
   17.72 +                    return f;
   17.73 +                }
   17.74 +            };
   17.75  
   17.76      private static XMLInputFactory getXMLInputFactory() {
   17.77          XMLInputFactory xif = null;
   17.78 @@ -126,11 +130,11 @@
   17.79          if(f==null) {
   17.80              throw new IllegalArgumentException();
   17.81          }
   17.82 -        theInstance = f;
   17.83 +        streamReader.set(f);
   17.84      }
   17.85  
   17.86      public static XMLStreamReaderFactory get() {
   17.87 -        return theInstance;
   17.88 +        return streamReader.get();
   17.89      }
   17.90  
   17.91      public static XMLStreamReader create(InputSource source, boolean rejectDTDs) {
    18.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Fri Feb 14 10:53:55 2014 +0100
    18.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/api/streaming/XMLStreamWriterFactory.java	Fri Feb 14 11:13:45 2014 +0100
    18.3 @@ -1,5 +1,5 @@
    18.4  /*
    18.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    18.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    18.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    18.8   *
    18.9   * This code is free software; you can redistribute it and/or modify it
   18.10 @@ -62,52 +62,54 @@
   18.11      /**
   18.12       * Singleton instance.
   18.13       */
   18.14 -    private static volatile @NotNull XMLStreamWriterFactory theInstance;
   18.15 +    private static volatile ContextClassloaderLocal<XMLStreamWriterFactory> writerFactory =
   18.16 +            new ContextClassloaderLocal<XMLStreamWriterFactory>() {
   18.17  
   18.18 +        @Override
   18.19 +        protected XMLStreamWriterFactory initialValue() {
   18.20 +            XMLOutputFactory  xof = null;
   18.21 +            if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
   18.22 +                try {
   18.23 +                    xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
   18.24 +                } catch (Exception e) {
   18.25 +                    // Ignore and fallback to default XMLOutputFactory
   18.26 +                }
   18.27 +            }
   18.28 +            if (xof == null) {
   18.29 +                xof = XMLOutputFactory.newInstance();
   18.30 +            }
   18.31  
   18.32 -    static {
   18.33 -        XMLOutputFactory  xof = null;
   18.34 -        if (Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".woodstox")) {
   18.35 -            try {
   18.36 -                xof = (XMLOutputFactory)Class.forName("com.ctc.wstx.stax.WstxOutputFactory").newInstance();
   18.37 -            } catch (Exception e) {
   18.38 -                // Ignore and fallback to default XMLOutputFactory
   18.39 +            XMLStreamWriterFactory f=null;
   18.40 +
   18.41 +            // this system property can be used to disable the pooling altogether,
   18.42 +            // in case someone hits an issue with pooling in the production system.
   18.43 +            if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
   18.44 +                try {
   18.45 +                    Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
   18.46 +                    if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
   18.47 +                        f =  new Zephyr(xof,clazz);
   18.48 +                    }
   18.49 +                } catch (XMLStreamException ex) {
   18.50 +                    Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
   18.51 +                } catch (NoSuchMethodException ex) {
   18.52 +                    Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
   18.53 +                }
   18.54              }
   18.55 +
   18.56 +            if(f==null) {
   18.57 +                // is this Woodstox?
   18.58 +                if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
   18.59 +                    f = new NoLock(xof);
   18.60 +            }
   18.61 +            if (f == null)
   18.62 +                f = new Default(xof);
   18.63 +
   18.64 +            if (LOGGER.isLoggable(Level.FINE)) {
   18.65 +                LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
   18.66 +            }
   18.67 +            return f;
   18.68          }
   18.69 -        if (xof == null) {
   18.70 -            xof = XMLOutputFactory.newInstance();
   18.71 -        }
   18.72 -
   18.73 -        XMLStreamWriterFactory f=null;
   18.74 -
   18.75 -        // this system property can be used to disable the pooling altogether,
   18.76 -        // in case someone hits an issue with pooling in the production system.
   18.77 -        if (!Boolean.getBoolean(XMLStreamWriterFactory.class.getName()+".noPool")) {
   18.78 -            try {
   18.79 -                Class<?> clazz = xof.createXMLStreamWriter(new StringWriter()).getClass();
   18.80 -                if (clazz.getName().startsWith("com.sun.xml.internal.stream.")) {
   18.81 -                    f =  new Zephyr(xof,clazz);
   18.82 -                }
   18.83 -            } catch (XMLStreamException ex) {
   18.84 -                Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
   18.85 -            } catch (NoSuchMethodException ex) {
   18.86 -                Logger.getLogger(XMLStreamWriterFactory.class.getName()).log(Level.INFO, null, ex);
   18.87 -            }
   18.88 -        }
   18.89 -
   18.90 -        if(f==null) {
   18.91 -            // is this Woodstox?
   18.92 -            if(xof.getClass().getName().equals("com.ctc.wstx.stax.WstxOutputFactory"))
   18.93 -                f = new NoLock(xof);
   18.94 -        }
   18.95 -        if (f == null)
   18.96 -            f = new Default(xof);
   18.97 -
   18.98 -        theInstance = f;
   18.99 -        if (LOGGER.isLoggable(Level.FINE)) {
  18.100 -            LOGGER.log(Level.FINE, "XMLStreamWriterFactory instance is = {0}", f);
  18.101 -        }
  18.102 -    }
  18.103 +    };
  18.104  
  18.105      /**
  18.106       * See {@link #create(OutputStream)} for the contract.
  18.107 @@ -170,7 +172,7 @@
  18.108       * Gets the singleton instance.
  18.109       */
  18.110      public static @NotNull XMLStreamWriterFactory get() {
  18.111 -        return theInstance;
  18.112 +        return writerFactory.get();
  18.113      }
  18.114  
  18.115      /**
  18.116 @@ -183,7 +185,7 @@
  18.117      @SuppressWarnings({"null", "ConstantConditions"})
  18.118      public static void set(@NotNull XMLStreamWriterFactory f) {
  18.119          if(f==null) throw new IllegalArgumentException();
  18.120 -        theInstance = f;
  18.121 +        writerFactory.set(f);
  18.122      }
  18.123  
  18.124      /**
    19.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    19.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    19.3 @@ -0,0 +1,86 @@
    19.4 +/*
    19.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    19.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    19.7 + *
    19.8 + * This code is free software; you can redistribute it and/or modify it
    19.9 + * under the terms of the GNU General Public License version 2 only, as
   19.10 + * published by the Free Software Foundation.  Oracle designates this
   19.11 + * particular file as subject to the "Classpath" exception as provided
   19.12 + * by Oracle in the LICENSE file that accompanied this code.
   19.13 + *
   19.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   19.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   19.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   19.17 + * version 2 for more details (a copy is included in the LICENSE file that
   19.18 + * accompanied this code).
   19.19 + *
   19.20 + * You should have received a copy of the GNU General Public License version
   19.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   19.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   19.23 + *
   19.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   19.25 + * or visit www.oracle.com if you need additional information or have any
   19.26 + * questions.
   19.27 + */
   19.28 +
   19.29 +package com.sun.xml.internal.ws.commons.xmlutil;
   19.30 +
   19.31 +import java.security.AccessController;
   19.32 +import java.security.PrivilegedAction;
   19.33 +import java.text.MessageFormat;
   19.34 +import java.util.ResourceBundle;
   19.35 +import java.util.WeakHashMap;
   19.36 +
   19.37 +/**
   19.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   19.39 + */
   19.40 +abstract class ContextClassloaderLocal<V> {
   19.41 +
   19.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   19.43 +
   19.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   19.45 +
   19.46 +    public V get() throws Error {
   19.47 +        ClassLoader tccl = getContextClassLoader();
   19.48 +        V instance = CACHE.get(tccl);
   19.49 +        if (instance == null) {
   19.50 +            instance = createNewInstance();
   19.51 +            CACHE.put(tccl, instance);
   19.52 +        }
   19.53 +        return instance;
   19.54 +    }
   19.55 +
   19.56 +    public void set(V instance) {
   19.57 +        CACHE.put(getContextClassLoader(), instance);
   19.58 +    }
   19.59 +
   19.60 +    protected abstract V initialValue() throws Exception;
   19.61 +
   19.62 +    private V createNewInstance() {
   19.63 +        try {
   19.64 +            return initialValue();
   19.65 +        } catch (Exception e) {
   19.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   19.67 +        }
   19.68 +    }
   19.69 +
   19.70 +    private static String format(String property, Object... args) {
   19.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   19.72 +        return MessageFormat.format(text, args);
   19.73 +    }
   19.74 +
   19.75 +    private static ClassLoader getContextClassLoader() {
   19.76 +        return (ClassLoader)
   19.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   19.78 +                    public Object run() {
   19.79 +                        ClassLoader cl = null;
   19.80 +                        try {
   19.81 +                            cl = Thread.currentThread().getContextClassLoader();
   19.82 +                        } catch (SecurityException ex) {
   19.83 +                        }
   19.84 +                        return cl;
   19.85 +                    }
   19.86 +                });
   19.87 +    }
   19.88 +}
   19.89 +
    20.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    20.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    20.3 @@ -0,0 +1,27 @@
    20.4 +#
    20.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    20.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    20.7 +#
    20.8 +# This code is free software; you can redistribute it and/or modify it
    20.9 +# under the terms of the GNU General Public License version 2 only, as
   20.10 +# published by the Free Software Foundation.  Oracle designates this
   20.11 +# particular file as subject to the "Classpath" exception as provided
   20.12 +# by Oracle in the LICENSE file that accompanied this code.
   20.13 +#
   20.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   20.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   20.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   20.17 +# version 2 for more details (a copy is included in the LICENSE file that
   20.18 +# accompanied this code).
   20.19 +#
   20.20 +# You should have received a copy of the GNU General Public License version
   20.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   20.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   20.23 +#
   20.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   20.25 +# or visit www.oracle.com if you need additional information or have any
   20.26 +# questions.
   20.27 +#
   20.28 +# Error messages for ContextClassloaderLocal utility class
   20.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   20.30 +
    21.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/Converter.java	Fri Feb 14 10:53:55 2014 +0100
    21.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/commons/xmlutil/Converter.java	Fri Feb 14 11:13:45 2014 +0100
    21.3 @@ -53,7 +53,12 @@
    21.4          // prevents instantiation
    21.5      }
    21.6      private static final Logger LOGGER = Logger.getLogger(Converter.class);
    21.7 -    private static final XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    21.8 +    private static final ContextClassloaderLocal<XMLOutputFactory> xmlOutputFactory = new ContextClassloaderLocal<XMLOutputFactory>() {
    21.9 +        @Override
   21.10 +        protected XMLOutputFactory initialValue() throws Exception {
   21.11 +            return XMLOutputFactory.newInstance();
   21.12 +        }
   21.13 +    };
   21.14      private static final AtomicBoolean logMissingStaxUtilsWarning = new AtomicBoolean(false);
   21.15  
   21.16      /**
   21.17 @@ -110,7 +115,7 @@
   21.18              stringOut = new StringWriter();
   21.19              XMLStreamWriter writer = null;
   21.20              try {
   21.21 -                writer = xmlOutputFactory.createXMLStreamWriter(stringOut);
   21.22 +                writer = xmlOutputFactory.get().createXMLStreamWriter(stringOut);
   21.23                  if (createIndenter) {
   21.24                      writer = createIndenter(writer);
   21.25                  }
   21.26 @@ -143,7 +148,7 @@
   21.27  
   21.28          try {
   21.29              if (message != null) {
   21.30 -                XMLStreamWriter xsw = xmlOutputFactory.createXMLStreamWriter(baos, encoding);
   21.31 +                XMLStreamWriter xsw = xmlOutputFactory.get().createXMLStreamWriter(baos, encoding);
   21.32                  try {
   21.33                      message.writeTo(xsw);
   21.34                  } finally {
    22.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    22.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    22.3 @@ -0,0 +1,86 @@
    22.4 +/*
    22.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    22.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    22.7 + *
    22.8 + * This code is free software; you can redistribute it and/or modify it
    22.9 + * under the terms of the GNU General Public License version 2 only, as
   22.10 + * published by the Free Software Foundation.  Oracle designates this
   22.11 + * particular file as subject to the "Classpath" exception as provided
   22.12 + * by Oracle in the LICENSE file that accompanied this code.
   22.13 + *
   22.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   22.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   22.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   22.17 + * version 2 for more details (a copy is included in the LICENSE file that
   22.18 + * accompanied this code).
   22.19 + *
   22.20 + * You should have received a copy of the GNU General Public License version
   22.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   22.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   22.23 + *
   22.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   22.25 + * or visit www.oracle.com if you need additional information or have any
   22.26 + * questions.
   22.27 + */
   22.28 +
   22.29 +package com.sun.xml.internal.ws.developer;
   22.30 +
   22.31 +import java.security.AccessController;
   22.32 +import java.security.PrivilegedAction;
   22.33 +import java.text.MessageFormat;
   22.34 +import java.util.ResourceBundle;
   22.35 +import java.util.WeakHashMap;
   22.36 +
   22.37 +/**
   22.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   22.39 + */
   22.40 +abstract class ContextClassloaderLocal<V> {
   22.41 +
   22.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   22.43 +
   22.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   22.45 +
   22.46 +    public V get() throws Error {
   22.47 +        ClassLoader tccl = getContextClassLoader();
   22.48 +        V instance = CACHE.get(tccl);
   22.49 +        if (instance == null) {
   22.50 +            instance = createNewInstance();
   22.51 +            CACHE.put(tccl, instance);
   22.52 +        }
   22.53 +        return instance;
   22.54 +    }
   22.55 +
   22.56 +    public void set(V instance) {
   22.57 +        CACHE.put(getContextClassLoader(), instance);
   22.58 +    }
   22.59 +
   22.60 +    protected abstract V initialValue() throws Exception;
   22.61 +
   22.62 +    private V createNewInstance() {
   22.63 +        try {
   22.64 +            return initialValue();
   22.65 +        } catch (Exception e) {
   22.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   22.67 +        }
   22.68 +    }
   22.69 +
   22.70 +    private static String format(String property, Object... args) {
   22.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   22.72 +        return MessageFormat.format(text, args);
   22.73 +    }
   22.74 +
   22.75 +    private static ClassLoader getContextClassLoader() {
   22.76 +        return (ClassLoader)
   22.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   22.78 +                    public Object run() {
   22.79 +                        ClassLoader cl = null;
   22.80 +                        try {
   22.81 +                            cl = Thread.currentThread().getContextClassLoader();
   22.82 +                        } catch (SecurityException ex) {
   22.83 +                        }
   22.84 +                        return cl;
   22.85 +                    }
   22.86 +                });
   22.87 +    }
   22.88 +}
   22.89 +
    23.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    23.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    23.3 @@ -0,0 +1,27 @@
    23.4 +#
    23.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    23.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    23.7 +#
    23.8 +# This code is free software; you can redistribute it and/or modify it
    23.9 +# under the terms of the GNU General Public License version 2 only, as
   23.10 +# published by the Free Software Foundation.  Oracle designates this
   23.11 +# particular file as subject to the "Classpath" exception as provided
   23.12 +# by Oracle in the LICENSE file that accompanied this code.
   23.13 +#
   23.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   23.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   23.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   23.17 +# version 2 for more details (a copy is included in the LICENSE file that
   23.18 +# accompanied this code).
   23.19 +#
   23.20 +# You should have received a copy of the GNU General Public License version
   23.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   23.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   23.23 +#
   23.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   23.25 +# or visit www.oracle.com if you need additional information or have any
   23.26 +# questions.
   23.27 +#
   23.28 +# Error messages for ContextClassloaderLocal utility class
   23.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   23.30 +
    24.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/MemberSubmissionEndpointReference.java	Fri Feb 14 10:53:55 2014 +0100
    24.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/developer/MemberSubmissionEndpointReference.java	Fri Feb 14 11:13:45 2014 +0100
    24.3 @@ -1,5 +1,5 @@
    24.4  /*
    24.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    24.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    24.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    24.8   *
    24.9   * This code is free software; you can redistribute it and/or modify it
   24.10 @@ -64,7 +64,12 @@
   24.11  @XmlType(name = "EndpointReferenceType", namespace = MemberSubmissionEndpointReference.MSNS)
   24.12  public final class MemberSubmissionEndpointReference extends EndpointReference implements MemberSubmissionAddressingConstants {
   24.13  
   24.14 -    private final static JAXBContext msjc = MemberSubmissionEndpointReference.getMSJaxbContext();
   24.15 +    private final static ContextClassloaderLocal<JAXBContext> msjc = new ContextClassloaderLocal<JAXBContext>() {
   24.16 +        @Override
   24.17 +        protected JAXBContext initialValue() throws Exception {
   24.18 +            return MemberSubmissionEndpointReference.getMSJaxbContext();
   24.19 +        }
   24.20 +    };
   24.21  
   24.22      public MemberSubmissionEndpointReference() {
   24.23      }
   24.24 @@ -86,7 +91,7 @@
   24.25          }
   24.26  
   24.27          try {
   24.28 -            Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.createUnmarshaller();
   24.29 +            Unmarshaller unmarshaller = MemberSubmissionEndpointReference.msjc.get().createUnmarshaller();
   24.30              MemberSubmissionEndpointReference epr = unmarshaller.unmarshal(source,MemberSubmissionEndpointReference.class).getValue();
   24.31  
   24.32              this.addr = epr.addr;
   24.33 @@ -106,7 +111,7 @@
   24.34      @Override
   24.35      public void writeTo(Result result) {
   24.36          try {
   24.37 -            Marshaller marshaller = MemberSubmissionEndpointReference.msjc.createMarshaller();
   24.38 +            Marshaller marshaller = MemberSubmissionEndpointReference.msjc.get().createMarshaller();
   24.39              //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
   24.40              marshaller.marshal(this, result);
   24.41          } catch (JAXBException e) {
    25.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    25.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    25.3 @@ -0,0 +1,86 @@
    25.4 +/*
    25.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    25.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    25.7 + *
    25.8 + * This code is free software; you can redistribute it and/or modify it
    25.9 + * under the terms of the GNU General Public License version 2 only, as
   25.10 + * published by the Free Software Foundation.  Oracle designates this
   25.11 + * particular file as subject to the "Classpath" exception as provided
   25.12 + * by Oracle in the LICENSE file that accompanied this code.
   25.13 + *
   25.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   25.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   25.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   25.17 + * version 2 for more details (a copy is included in the LICENSE file that
   25.18 + * accompanied this code).
   25.19 + *
   25.20 + * You should have received a copy of the GNU General Public License version
   25.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   25.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   25.23 + *
   25.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   25.25 + * or visit www.oracle.com if you need additional information or have any
   25.26 + * questions.
   25.27 + */
   25.28 +
   25.29 +package com.sun.xml.internal.ws.policy.sourcemodel.attach;
   25.30 +
   25.31 +import java.security.AccessController;
   25.32 +import java.security.PrivilegedAction;
   25.33 +import java.text.MessageFormat;
   25.34 +import java.util.ResourceBundle;
   25.35 +import java.util.WeakHashMap;
   25.36 +
   25.37 +/**
   25.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   25.39 + */
   25.40 +abstract class ContextClassloaderLocal<V> {
   25.41 +
   25.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   25.43 +
   25.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   25.45 +
   25.46 +    public V get() throws Error {
   25.47 +        ClassLoader tccl = getContextClassLoader();
   25.48 +        V instance = CACHE.get(tccl);
   25.49 +        if (instance == null) {
   25.50 +            instance = createNewInstance();
   25.51 +            CACHE.put(tccl, instance);
   25.52 +        }
   25.53 +        return instance;
   25.54 +    }
   25.55 +
   25.56 +    public void set(V instance) {
   25.57 +        CACHE.put(getContextClassLoader(), instance);
   25.58 +    }
   25.59 +
   25.60 +    protected abstract V initialValue() throws Exception;
   25.61 +
   25.62 +    private V createNewInstance() {
   25.63 +        try {
   25.64 +            return initialValue();
   25.65 +        } catch (Exception e) {
   25.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   25.67 +        }
   25.68 +    }
   25.69 +
   25.70 +    private static String format(String property, Object... args) {
   25.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   25.72 +        return MessageFormat.format(text, args);
   25.73 +    }
   25.74 +
   25.75 +    private static ClassLoader getContextClassLoader() {
   25.76 +        return (ClassLoader)
   25.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   25.78 +                    public Object run() {
   25.79 +                        ClassLoader cl = null;
   25.80 +                        try {
   25.81 +                            cl = Thread.currentThread().getContextClassLoader();
   25.82 +                        } catch (SecurityException ex) {
   25.83 +                        }
   25.84 +                        return cl;
   25.85 +                    }
   25.86 +                });
   25.87 +    }
   25.88 +}
   25.89 +
    26.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    26.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    26.3 @@ -0,0 +1,27 @@
    26.4 +#
    26.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    26.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    26.7 +#
    26.8 +# This code is free software; you can redistribute it and/or modify it
    26.9 +# under the terms of the GNU General Public License version 2 only, as
   26.10 +# published by the Free Software Foundation.  Oracle designates this
   26.11 +# particular file as subject to the "Classpath" exception as provided
   26.12 +# by Oracle in the LICENSE file that accompanied this code.
   26.13 +#
   26.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   26.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   26.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   26.17 +# version 2 for more details (a copy is included in the LICENSE file that
   26.18 +# accompanied this code).
   26.19 +#
   26.20 +# You should have received a copy of the GNU General Public License version
   26.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   26.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   26.23 +#
   26.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   26.25 +# or visit www.oracle.com if you need additional information or have any
   26.26 +# questions.
   26.27 +#
   26.28 +# Error messages for ContextClassloaderLocal utility class
   26.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   26.30 +
    27.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ExternalAttachmentsUnmarshaller.java	Fri Feb 14 10:53:55 2014 +0100
    27.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/policy/sourcemodel/attach/ExternalAttachmentsUnmarshaller.java	Fri Feb 14 11:13:45 2014 +0100
    27.3 @@ -1,5 +1,5 @@
    27.4  /*
    27.5 - * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
    27.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    27.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    27.8   *
    27.9   * This code is free software; you can redistribute it and/or modify it
   27.10 @@ -83,7 +83,13 @@
   27.11      private static final QName POLICY = new QName("http://www.w3.org/ns/ws-policy", "Policy");
   27.12      private static final QName URI = new QName("http://www.w3.org/ns/ws-policy", "URI");
   27.13      private static final QName POLICIES = new QName(PolicyConstants.SUN_MANAGEMENT_NAMESPACE, "Policies");
   27.14 -    private static final XMLInputFactory XML_INPUT_FACTORY = XMLInputFactory.newInstance();
   27.15 +    private static final ContextClassloaderLocal<XMLInputFactory> XML_INPUT_FACTORY = new ContextClassloaderLocal<XMLInputFactory>() {
   27.16 +        @Override
   27.17 +        protected XMLInputFactory initialValue() throws Exception {
   27.18 +            return XMLInputFactory.newInstance();
   27.19 +        }
   27.20 +    };
   27.21 +
   27.22      private static final PolicyModelUnmarshaller POLICY_UNMARSHALLER = PolicyModelUnmarshaller.getXmlUnmarshaller();
   27.23  
   27.24      private final Map<URI, Policy> map = new HashMap<URI, Policy>();
   27.25 @@ -93,7 +99,7 @@
   27.26      public static Map<URI, Policy> unmarshal(final Reader source) throws PolicyException {
   27.27          LOGGER.entering(source);
   27.28          try {
   27.29 -            XMLEventReader reader = XML_INPUT_FACTORY.createXMLEventReader(source);
   27.30 +            XMLEventReader reader = XML_INPUT_FACTORY.get().createXMLEventReader(source);
   27.31              ExternalAttachmentsUnmarshaller instance = new ExternalAttachmentsUnmarshaller();
   27.32              final Map<URI, Policy> map = instance.unmarshal(reader, null);
   27.33              LOGGER.exiting(map);
    28.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    28.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    28.3 @@ -0,0 +1,86 @@
    28.4 +/*
    28.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    28.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    28.7 + *
    28.8 + * This code is free software; you can redistribute it and/or modify it
    28.9 + * under the terms of the GNU General Public License version 2 only, as
   28.10 + * published by the Free Software Foundation.  Oracle designates this
   28.11 + * particular file as subject to the "Classpath" exception as provided
   28.12 + * by Oracle in the LICENSE file that accompanied this code.
   28.13 + *
   28.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   28.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   28.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   28.17 + * version 2 for more details (a copy is included in the LICENSE file that
   28.18 + * accompanied this code).
   28.19 + *
   28.20 + * You should have received a copy of the GNU General Public License version
   28.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   28.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   28.23 + *
   28.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   28.25 + * or visit www.oracle.com if you need additional information or have any
   28.26 + * questions.
   28.27 + */
   28.28 +
   28.29 +package com.sun.xml.internal.ws.spi;
   28.30 +
   28.31 +import java.security.AccessController;
   28.32 +import java.security.PrivilegedAction;
   28.33 +import java.text.MessageFormat;
   28.34 +import java.util.ResourceBundle;
   28.35 +import java.util.WeakHashMap;
   28.36 +
   28.37 +/**
   28.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   28.39 + */
   28.40 +abstract class ContextClassloaderLocal<V> {
   28.41 +
   28.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   28.43 +
   28.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   28.45 +
   28.46 +    public V get() throws Error {
   28.47 +        ClassLoader tccl = getContextClassLoader();
   28.48 +        V instance = CACHE.get(tccl);
   28.49 +        if (instance == null) {
   28.50 +            instance = createNewInstance();
   28.51 +            CACHE.put(tccl, instance);
   28.52 +        }
   28.53 +        return instance;
   28.54 +    }
   28.55 +
   28.56 +    public void set(V instance) {
   28.57 +        CACHE.put(getContextClassLoader(), instance);
   28.58 +    }
   28.59 +
   28.60 +    protected abstract V initialValue() throws Exception;
   28.61 +
   28.62 +    private V createNewInstance() {
   28.63 +        try {
   28.64 +            return initialValue();
   28.65 +        } catch (Exception e) {
   28.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   28.67 +        }
   28.68 +    }
   28.69 +
   28.70 +    private static String format(String property, Object... args) {
   28.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   28.72 +        return MessageFormat.format(text, args);
   28.73 +    }
   28.74 +
   28.75 +    private static ClassLoader getContextClassLoader() {
   28.76 +        return (ClassLoader)
   28.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   28.78 +                    public Object run() {
   28.79 +                        ClassLoader cl = null;
   28.80 +                        try {
   28.81 +                            cl = Thread.currentThread().getContextClassLoader();
   28.82 +                        } catch (SecurityException ex) {
   28.83 +                        }
   28.84 +                        return cl;
   28.85 +                    }
   28.86 +                });
   28.87 +    }
   28.88 +}
   28.89 +
    29.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    29.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    29.3 @@ -0,0 +1,27 @@
    29.4 +#
    29.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    29.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    29.7 +#
    29.8 +# This code is free software; you can redistribute it and/or modify it
    29.9 +# under the terms of the GNU General Public License version 2 only, as
   29.10 +# published by the Free Software Foundation.  Oracle designates this
   29.11 +# particular file as subject to the "Classpath" exception as provided
   29.12 +# by Oracle in the LICENSE file that accompanied this code.
   29.13 +#
   29.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   29.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   29.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   29.17 +# version 2 for more details (a copy is included in the LICENSE file that
   29.18 +# accompanied this code).
   29.19 +#
   29.20 +# You should have received a copy of the GNU General Public License version
   29.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   29.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   29.23 +#
   29.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   29.25 +# or visit www.oracle.com if you need additional information or have any
   29.26 +# questions.
   29.27 +#
   29.28 +# Error messages for StaticCache utility class
   29.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   29.30 +
    30.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ProviderImpl.java	Fri Feb 14 10:53:55 2014 +0100
    30.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/spi/ProviderImpl.java	Fri Feb 14 11:13:45 2014 +0100
    30.3 @@ -1,5 +1,5 @@
    30.4  /*
    30.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    30.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    30.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    30.8   *
    30.9   * This code is free software; you can redistribute it and/or modify it
   30.10 @@ -80,7 +80,12 @@
   30.11   */
   30.12  public class ProviderImpl extends Provider {
   30.13  
   30.14 -    private final static JAXBContext eprjc = getEPRJaxbContext();
   30.15 +    private final static ContextClassloaderLocal<JAXBContext> eprjc = new ContextClassloaderLocal<JAXBContext>() {
   30.16 +        @Override
   30.17 +        protected JAXBContext initialValue() throws Exception {
   30.18 +            return getEPRJaxbContext();
   30.19 +        }
   30.20 +    };
   30.21  
   30.22      /**
   30.23       * Convenient singleton instance.
   30.24 @@ -148,7 +153,7 @@
   30.25          return AccessController.doPrivileged(new PrivilegedAction<EndpointReference>() {
   30.26              public EndpointReference run() {
   30.27                  try {
   30.28 -                    Unmarshaller unmarshaller = eprjc.createUnmarshaller();
   30.29 +                    Unmarshaller unmarshaller = eprjc.get().createUnmarshaller();
   30.30                      return (EndpointReference) unmarshaller.unmarshal(eprInfoset);
   30.31                  } catch (JAXBException e) {
   30.32                      throw new WebServiceException("Error creating Marshaller or marshalling.", e);
    31.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    31.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    31.3 @@ -0,0 +1,86 @@
    31.4 +/*
    31.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    31.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    31.7 + *
    31.8 + * This code is free software; you can redistribute it and/or modify it
    31.9 + * under the terms of the GNU General Public License version 2 only, as
   31.10 + * published by the Free Software Foundation.  Oracle designates this
   31.11 + * particular file as subject to the "Classpath" exception as provided
   31.12 + * by Oracle in the LICENSE file that accompanied this code.
   31.13 + *
   31.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   31.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   31.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   31.17 + * version 2 for more details (a copy is included in the LICENSE file that
   31.18 + * accompanied this code).
   31.19 + *
   31.20 + * You should have received a copy of the GNU General Public License version
   31.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   31.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   31.23 + *
   31.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   31.25 + * or visit www.oracle.com if you need additional information or have any
   31.26 + * questions.
   31.27 + */
   31.28 +
   31.29 +package com.sun.xml.internal.ws.util.xml;
   31.30 +
   31.31 +import java.security.AccessController;
   31.32 +import java.security.PrivilegedAction;
   31.33 +import java.text.MessageFormat;
   31.34 +import java.util.ResourceBundle;
   31.35 +import java.util.WeakHashMap;
   31.36 +
   31.37 +/**
   31.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   31.39 + */
   31.40 +abstract class ContextClassloaderLocal<V> {
   31.41 +
   31.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   31.43 +
   31.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   31.45 +
   31.46 +    public V get() throws Error {
   31.47 +        ClassLoader tccl = getContextClassLoader();
   31.48 +        V instance = CACHE.get(tccl);
   31.49 +        if (instance == null) {
   31.50 +            instance = createNewInstance();
   31.51 +            CACHE.put(tccl, instance);
   31.52 +        }
   31.53 +        return instance;
   31.54 +    }
   31.55 +
   31.56 +    public void set(V instance) {
   31.57 +        CACHE.put(getContextClassLoader(), instance);
   31.58 +    }
   31.59 +
   31.60 +    protected abstract V initialValue() throws Exception;
   31.61 +
   31.62 +    private V createNewInstance() {
   31.63 +        try {
   31.64 +            return initialValue();
   31.65 +        } catch (Exception e) {
   31.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   31.67 +        }
   31.68 +    }
   31.69 +
   31.70 +    private static String format(String property, Object... args) {
   31.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   31.72 +        return MessageFormat.format(text, args);
   31.73 +    }
   31.74 +
   31.75 +    private static ClassLoader getContextClassLoader() {
   31.76 +        return (ClassLoader)
   31.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   31.78 +                    public Object run() {
   31.79 +                        ClassLoader cl = null;
   31.80 +                        try {
   31.81 +                            cl = Thread.currentThread().getContextClassLoader();
   31.82 +                        } catch (SecurityException ex) {
   31.83 +                        }
   31.84 +                        return cl;
   31.85 +                    }
   31.86 +                });
   31.87 +    }
   31.88 +}
   31.89 +
    32.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    32.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    32.3 @@ -0,0 +1,27 @@
    32.4 +#
    32.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    32.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    32.7 +#
    32.8 +# This code is free software; you can redistribute it and/or modify it
    32.9 +# under the terms of the GNU General Public License version 2 only, as
   32.10 +# published by the Free Software Foundation.  Oracle designates this
   32.11 +# particular file as subject to the "Classpath" exception as provided
   32.12 +# by Oracle in the LICENSE file that accompanied this code.
   32.13 +#
   32.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   32.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   32.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   32.17 +# version 2 for more details (a copy is included in the LICENSE file that
   32.18 +# accompanied this code).
   32.19 +#
   32.20 +# You should have received a copy of the GNU General Public License version
   32.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   32.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   32.23 +#
   32.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   32.25 +# or visit www.oracle.com if you need additional information or have any
   32.26 +# questions.
   32.27 +#
   32.28 +# Error messages for StaticCache utility class
   32.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   32.30 +
    33.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java	Fri Feb 14 10:53:55 2014 +0100
    33.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/ws/util/xml/XmlUtil.java	Fri Feb 14 11:13:45 2014 +0100
    33.3 @@ -1,5 +1,5 @@
    33.4  /*
    33.5 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
    33.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    33.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    33.8   *
    33.9   * This code is free software; you can redistribute it and/or modify it
   33.10 @@ -215,20 +215,28 @@
   33.11          }
   33.12      }
   33.13  
   33.14 -    static final TransformerFactory transformerFactory = newTransformerFactory();
   33.15 +    static final ContextClassloaderLocal<TransformerFactory> transformerFactory = new ContextClassloaderLocal<TransformerFactory>() {
   33.16 +        @Override
   33.17 +        protected TransformerFactory initialValue() throws Exception {
   33.18 +            return TransformerFactory.newInstance();
   33.19 +        }
   33.20 +    };
   33.21  
   33.22 -    static final SAXParserFactory saxParserFactory = newSAXParserFactory(true);
   33.23 -
   33.24 -    static {
   33.25 -        saxParserFactory.setNamespaceAware(true);
   33.26 -    }
   33.27 +    static final ContextClassloaderLocal<SAXParserFactory> saxParserFactory = new ContextClassloaderLocal<SAXParserFactory>() {
   33.28 +        @Override
   33.29 +        protected SAXParserFactory initialValue() throws Exception {
   33.30 +            SAXParserFactory factory = SAXParserFactory.newInstance();
   33.31 +            factory.setNamespaceAware(true);
   33.32 +            return factory;
   33.33 +        }
   33.34 +    };
   33.35  
   33.36      /**
   33.37       * Creates a new identity transformer.
   33.38       */
   33.39      public static Transformer newTransformer() {
   33.40          try {
   33.41 -            return transformerFactory.newTransformer();
   33.42 +            return transformerFactory.get().newTransformer();
   33.43          } catch (TransformerConfigurationException tex) {
   33.44              throw new IllegalStateException("Unable to create a JAXP transformer");
   33.45          }
   33.46 @@ -243,9 +251,9 @@
   33.47              // work around a bug in JAXP in JDK6u4 and earlier where the namespace processing
   33.48              // is not turned on by default
   33.49              StreamSource ssrc = (StreamSource) src;
   33.50 -            TransformerHandler th = ((SAXTransformerFactory) transformerFactory).newTransformerHandler();
   33.51 +            TransformerHandler th = ((SAXTransformerFactory) transformerFactory.get()).newTransformerHandler();
   33.52              th.setResult(result);
   33.53 -            XMLReader reader = saxParserFactory.newSAXParser().getXMLReader();
   33.54 +            XMLReader reader = saxParserFactory.get().newSAXParser().getXMLReader();
   33.55              reader.setContentHandler(th);
   33.56              reader.setProperty(LEXICAL_HANDLER_PROPERTY, th);
   33.57              reader.parse(toInputSource(ssrc));
    34.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    34.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/xsom/util/ContextClassloaderLocal.java	Fri Feb 14 11:13:45 2014 +0100
    34.3 @@ -0,0 +1,86 @@
    34.4 +/*
    34.5 + * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    34.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    34.7 + *
    34.8 + * This code is free software; you can redistribute it and/or modify it
    34.9 + * under the terms of the GNU General Public License version 2 only, as
   34.10 + * published by the Free Software Foundation.  Oracle designates this
   34.11 + * particular file as subject to the "Classpath" exception as provided
   34.12 + * by Oracle in the LICENSE file that accompanied this code.
   34.13 + *
   34.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
   34.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   34.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   34.17 + * version 2 for more details (a copy is included in the LICENSE file that
   34.18 + * accompanied this code).
   34.19 + *
   34.20 + * You should have received a copy of the GNU General Public License version
   34.21 + * 2 along with this work; if not, write to the Free Software Foundation,
   34.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   34.23 + *
   34.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   34.25 + * or visit www.oracle.com if you need additional information or have any
   34.26 + * questions.
   34.27 + */
   34.28 +
   34.29 +package com.sun.xml.internal.xsom.util;
   34.30 +
   34.31 +import java.security.AccessController;
   34.32 +import java.security.PrivilegedAction;
   34.33 +import java.text.MessageFormat;
   34.34 +import java.util.ResourceBundle;
   34.35 +import java.util.WeakHashMap;
   34.36 +
   34.37 +/**
   34.38 + * Simple utility ensuring that the value is cached only in case it is non-internal implementation
   34.39 + */
   34.40 +abstract class ContextClassloaderLocal<V> {
   34.41 +
   34.42 +    private static final String FAILED_TO_CREATE_NEW_INSTANCE = "FAILED_TO_CREATE_NEW_INSTANCE";
   34.43 +
   34.44 +    private WeakHashMap<ClassLoader, V> CACHE = new WeakHashMap<ClassLoader, V>();
   34.45 +
   34.46 +    public V get() throws Error {
   34.47 +        ClassLoader tccl = getContextClassLoader();
   34.48 +        V instance = CACHE.get(tccl);
   34.49 +        if (instance == null) {
   34.50 +            instance = createNewInstance();
   34.51 +            CACHE.put(tccl, instance);
   34.52 +        }
   34.53 +        return instance;
   34.54 +    }
   34.55 +
   34.56 +    public void set(V instance) {
   34.57 +        CACHE.put(getContextClassLoader(), instance);
   34.58 +    }
   34.59 +
   34.60 +    protected abstract V initialValue() throws Exception;
   34.61 +
   34.62 +    private V createNewInstance() {
   34.63 +        try {
   34.64 +            return initialValue();
   34.65 +        } catch (Exception e) {
   34.66 +            throw new Error(format(FAILED_TO_CREATE_NEW_INSTANCE, getClass().getName()), e);
   34.67 +        }
   34.68 +    }
   34.69 +
   34.70 +    private static String format(String property, Object... args) {
   34.71 +        String text = ResourceBundle.getBundle(ContextClassloaderLocal.class.getName()).getString(property);
   34.72 +        return MessageFormat.format(text, args);
   34.73 +    }
   34.74 +
   34.75 +    private static ClassLoader getContextClassLoader() {
   34.76 +        return (ClassLoader)
   34.77 +                AccessController.doPrivileged(new PrivilegedAction() {
   34.78 +                    public Object run() {
   34.79 +                        ClassLoader cl = null;
   34.80 +                        try {
   34.81 +                            cl = Thread.currentThread().getContextClassLoader();
   34.82 +                        } catch (SecurityException ex) {
   34.83 +                        }
   34.84 +                        return cl;
   34.85 +                    }
   34.86 +                });
   34.87 +    }
   34.88 +}
   34.89 +
    35.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    35.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/xsom/util/ContextClassloaderLocal.properties	Fri Feb 14 11:13:45 2014 +0100
    35.3 @@ -0,0 +1,27 @@
    35.4 +#
    35.5 +# Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
    35.6 +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    35.7 +#
    35.8 +# This code is free software; you can redistribute it and/or modify it
    35.9 +# under the terms of the GNU General Public License version 2 only, as
   35.10 +# published by the Free Software Foundation.  Oracle designates this
   35.11 +# particular file as subject to the "Classpath" exception as provided
   35.12 +# by Oracle in the LICENSE file that accompanied this code.
   35.13 +#
   35.14 +# This code is distributed in the hope that it will be useful, but WITHOUT
   35.15 +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
   35.16 +# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
   35.17 +# version 2 for more details (a copy is included in the LICENSE file that
   35.18 +# accompanied this code).
   35.19 +#
   35.20 +# You should have received a copy of the GNU General Public License version
   35.21 +# 2 along with this work; if not, write to the Free Software Foundation,
   35.22 +# Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
   35.23 +#
   35.24 +# Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
   35.25 +# or visit www.oracle.com if you need additional information or have any
   35.26 +# questions.
   35.27 +#
   35.28 +# Error messages for ContextClassloaderLocal utility class
   35.29 +FAILED_TO_CREATE_NEW_INSTANCE=Failed to create new instance of {0}
   35.30 +
    36.1 --- a/src/share/jaxws_classes/com/sun/xml/internal/xsom/util/DomAnnotationParserFactory.java	Fri Feb 14 10:53:55 2014 +0100
    36.2 +++ b/src/share/jaxws_classes/com/sun/xml/internal/xsom/util/DomAnnotationParserFactory.java	Fri Feb 14 11:13:45 2014 +0100
    36.3 @@ -1,5 +1,5 @@
    36.4  /*
    36.5 - * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
    36.6 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
    36.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
    36.8   *
    36.9   * This code is free software; you can redistribute it and/or modify it
   36.10 @@ -63,10 +63,15 @@
   36.11      }
   36.12  
   36.13      public AnnotationParser create(boolean disableSecureProcessing) {
   36.14 -        return new AnnotationParserImpl();
   36.15 +        return new AnnotationParserImpl(disableSecureProcessing);
   36.16      }
   36.17  
   36.18 -    private static final SAXTransformerFactory stf = (SAXTransformerFactory) SAXTransformerFactory.newInstance();
   36.19 +    private static final ContextClassloaderLocal<SAXTransformerFactory> stf = new ContextClassloaderLocal<SAXTransformerFactory>() {
   36.20 +        @Override
   36.21 +        protected SAXTransformerFactory initialValue() throws Exception {
   36.22 +            return (SAXTransformerFactory) SAXTransformerFactory.newInstance();
   36.23 +        }
   36.24 +    };
   36.25  
   36.26      private static class AnnotationParserImpl extends AnnotationParser {
   36.27  
   36.28 @@ -82,8 +87,9 @@
   36.29  
   36.30          AnnotationParserImpl(boolean disableSecureProcessing) {
   36.31              try {
   36.32 -                transformer = stf.newTransformerHandler();
   36.33 -                stf.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, disableSecureProcessing);
   36.34 +                SAXTransformerFactory factory = stf.get();
   36.35 +                factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, disableSecureProcessing);
   36.36 +                transformer = factory.newTransformerHandler();
   36.37              } catch (TransformerConfigurationException e) {
   36.38                  throw new Error(e); // impossible
   36.39              }

mercurial