changeset 598:b5878b03d1b2 jdk9-b68

Merge
author lana
date Thu, 04 Jun 2015 18:49:20 -0700
parents 722bc62e23de (current diff) 769bb20850bd (diff)
children 53993d421b2b 884d98e00032
files
diffstat 6 files changed, 211 insertions(+), 42 deletions(-) [+]
line wrap: on
line diff
--- a/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/assembler/MetroConfigLoader.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/java.xml.ws/share/classes/com/sun/xml/internal/ws/assembler/MetroConfigLoader.java	Thu Jun 04 18:49:20 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -41,6 +41,8 @@
 import javax.xml.bind.Unmarshaller;
 import javax.xml.stream.XMLInputFactory;
 import javax.xml.ws.WebServiceException;
+import java.io.IOException;
+import java.io.InputStream;
 import java.lang.reflect.Method;
 import java.net.MalformedURLException;
 import java.net.URI;
@@ -64,6 +66,7 @@
 // TODO Move the logic of this class directly into MetroConfig class.
 class MetroConfigLoader {
 
+    private static final String JAXWS_TUBES_JDK_XML_RESOURCE = "jaxws-tubes-default.xml";
     private static final Logger LOGGER = Logger.getLogger(MetroConfigLoader.class);
 
     private MetroConfigName defaultTubesConfigNames;
@@ -122,11 +125,10 @@
             defaultFileName = defaultTubesConfigNames.getDefaultFileName();
         }
         this.defaultConfigUrl = locateResource(defaultFileName, loaders);
-        if (defaultConfigUrl == null) {
-            throw LOGGER.logSevereException(new IllegalStateException(TubelineassemblyMessages.MASM_0001_DEFAULT_CFG_FILE_NOT_FOUND(defaultFileName)));
+        if (defaultConfigUrl != null) {
+            LOGGER.config(TubelineassemblyMessages.MASM_0002_DEFAULT_CFG_FILE_LOCATED(defaultFileName, defaultConfigUrl));
         }
 
-        LOGGER.config(TubelineassemblyMessages.MASM_0002_DEFAULT_CFG_FILE_LOCATED(defaultFileName, defaultConfigUrl));
         this.defaultConfig = MetroConfigLoader.loadMetroConfig(defaultConfigUrl);
         if (defaultConfig == null) {
             throw LOGGER.logSevereException(new IllegalStateException(TubelineassemblyMessages.MASM_0003_DEFAULT_CFG_FILE_NOT_LOADED(defaultFileName)));
@@ -235,17 +237,35 @@
     }
 
     private static MetroConfig loadMetroConfig(@NotNull URL resourceUrl) {
-        MetroConfig result = null;
-        try {
+        try (InputStream is = getConfigInputStream(resourceUrl)) {
             JAXBContext jaxbContext = createJAXBContext();
             Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
             XMLInputFactory factory = XmlUtil.newXMLInputFactory(true);
-            final JAXBElement<MetroConfig> configElement = unmarshaller.unmarshal(factory.createXMLStreamReader(resourceUrl.openStream()), MetroConfig.class);
-            result = configElement.getValue();
+            JAXBElement<MetroConfig> configElement = unmarshaller.unmarshal(factory.createXMLStreamReader(is), MetroConfig.class);
+            return configElement.getValue();
         } catch (Exception e) {
-            LOGGER.warning(TubelineassemblyMessages.MASM_0010_ERROR_READING_CFG_FILE_FROM_LOCATION(resourceUrl.toString()), e);
+            String message = TubelineassemblyMessages.MASM_0010_ERROR_READING_CFG_FILE_FROM_LOCATION(
+                    resourceUrl != null ? resourceUrl.toString() : null);
+            InternalError error = new InternalError(message);
+            LOGGER.logException(error, e, Level.SEVERE);
+            throw error;
         }
-        return result;
+    }
+
+    private static InputStream getConfigInputStream(URL resourceUrl) throws IOException {
+        InputStream is;
+        if (resourceUrl != null) {
+            is = resourceUrl.openStream();
+        } else {
+            is = MetroConfigLoader.class.getResourceAsStream(JAXWS_TUBES_JDK_XML_RESOURCE);
+
+            if (is == null)
+                throw LOGGER.logSevereException(
+                        new IllegalStateException(
+                                TubelineassemblyMessages.MASM_0001_DEFAULT_CFG_FILE_NOT_FOUND(JAXWS_TUBES_JDK_XML_RESOURCE)));
+        }
+
+        return is;
     }
 
     private static JAXBContext createJAXBContext() throws Exception {
--- a/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ConfigReader.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ConfigReader.java	Thu Jun 04 18:49:20 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -181,7 +181,7 @@
     /**
      * Lazily parsed schema for the binding file.
      */
-    private static SchemaCache configSchema = new SchemaCache(Config.class.getResource("config.xsd"));
+    private static SchemaCache configSchema = new SchemaCache("config.xsd", Config.class);
 
 
     /**
--- a/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/SchemaCache.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/SchemaCache.java	Thu Jun 04 18:49:20 2015 -0700
@@ -25,14 +25,23 @@
 
 package com.sun.tools.internal.xjc;
 
-import java.net.URL;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
 
+import javax.xml.transform.stream.StreamSource;
 import javax.xml.validation.Schema;
 import javax.xml.validation.SchemaFactory;
 import javax.xml.validation.ValidatorHandler;
 
 import com.sun.xml.internal.bind.v2.util.XmlFactory;
 import javax.xml.XMLConstants;
+
+import org.w3c.dom.ls.LSInput;
+import org.w3c.dom.ls.LSResourceResolver;
 import org.xml.sax.SAXException;
 
 import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
@@ -47,30 +56,170 @@
  */
 public final class SchemaCache {
 
+    private final boolean createResolver;
+    private final String resourceName;
+    private final Class<?> clazz;
+
     private Schema schema;
 
-    private final URL source;
+    public SchemaCache(String resourceName, Class<?> classToResolveResources) {
+        this(resourceName, classToResolveResources, false);
+    }
 
-    public SchemaCache(URL source) {
-        this.source = source;
+    public SchemaCache(String resourceName, Class<?> classToResolveResources, boolean createResolver) {
+        this.resourceName = resourceName;
+        this.createResolver = createResolver;
+        this.clazz = classToResolveResources;
     }
 
     public ValidatorHandler newValidator() {
-        synchronized(this) {
-            if(schema==null) {
-                try {
-                    // do not disable secure processing - these are well-known schemas
-                    SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
-                    schema = allowExternalAccess(sf, "file", false).newSchema(source);
-                } catch (SAXException e) {
-                    // we make sure that the schema is correct before we ship.
-                    throw new AssertionError(e);
+        if (schema==null) {
+            synchronized (this) {
+                if (schema == null) {
+
+                    ResourceResolver resourceResolver = null;
+                    try (InputStream is = clazz.getResourceAsStream(resourceName)) {
+
+                        StreamSource source = new StreamSource(is);
+                        source.setSystemId(resourceName);
+                        // do not disable secure processing - these are well-known schemas
+
+                        SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
+                        SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
+
+                        if (createResolver) {
+                            resourceResolver = new ResourceResolver(clazz);
+                            schemaFactory.setResourceResolver(resourceResolver);
+                        }
+                        schema = schemaFactory.newSchema(source);
+
+                    } catch (IOException | SAXException e) {
+                        throw new InternalError(e);
+                    } finally {
+                        if (resourceResolver != null) resourceResolver.closeStreams();
+                    }
+                }
+            }
+        }
+        return schema.newValidatorHandler();
+    }
+
+    class ResourceResolver implements LSResourceResolver {
+
+        private List<InputStream> streamsToClose = Collections.synchronizedList(new ArrayList<InputStream>());
+        private Class<?> clazz;
+
+        ResourceResolver(Class<?> clazz) {
+            this.clazz = clazz;
+        }
+
+        @Override
+        public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {
+            // XSOM passes the namespace URI to the publicID parameter.
+            // we do the same here .
+            InputStream is = clazz.getResourceAsStream(systemId);
+            streamsToClose.add(is);
+            return new Input(is, publicId, systemId);
+        }
+
+        void closeStreams() {
+            for (InputStream is : streamsToClose) {
+                if (is != null) {
+                    try {
+                        is.close();
+                    } catch (IOException e) {
+                        // nothing to do ...
+                    }
                 }
             }
         }
-
-        ValidatorHandler handler = schema.newValidatorHandler();
-        return handler;
     }
 
 }
+
+class Input implements LSInput {
+
+    private InputStream is;
+    private String publicId;
+    private String systemId;
+
+    public Input(InputStream is, String publicId, String systemId) {
+        this.is = is;
+        this.publicId = publicId;
+        this.systemId = systemId;
+    }
+
+    @Override
+    public Reader getCharacterStream() {
+        return null;
+    }
+
+    @Override
+    public void setCharacterStream(Reader characterStream) {
+    }
+
+    @Override
+    public InputStream getByteStream() {
+        return is;
+    }
+
+    @Override
+    public void setByteStream(InputStream byteStream) {
+    }
+
+    @Override
+    public String getStringData() {
+        return null;
+    }
+
+    @Override
+    public void setStringData(String stringData) {
+    }
+
+    @Override
+    public String getSystemId() {
+        return systemId;
+    }
+
+    @Override
+    public void setSystemId(String systemId) {
+    }
+
+    @Override
+    public String getPublicId() {
+        return publicId;
+    }
+
+    @Override
+    public void setPublicId(String publicId) {
+    }
+
+    @Override
+    public String getBaseURI() {
+        return null;
+    }
+
+    @Override
+    public void setBaseURI(String baseURI) {
+    }
+
+    @Override
+    public String getEncoding() {
+        return null;
+    }
+
+    @Override
+    public void setEncoding(String encoding) {
+    }
+
+    @Override
+    public boolean getCertifiedText() {
+        return false;
+    }
+
+    @Override
+    public void setCertifiedText(boolean certifiedText) {
+    }
+}
+
+
--- a/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/dtd/bindinfo/BindInfo.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/dtd/bindinfo/BindInfo.java	Thu Jun 04 18:49:20 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -289,7 +289,7 @@
     /**
      * Lazily parsed schema for the binding file.
      */
-    private static SchemaCache bindingFileSchema = new SchemaCache(BindInfo.class.getResource("bindingfile.xsd"));
+    private static SchemaCache bindingFileSchema = new SchemaCache("bindingfile.xsd", BindInfo.class);
 
     /**
      * Parses an InputSource into dom4j Document.
--- a/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/BindInfo.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/reader/xmlschema/bindinfo/BindInfo.java	Thu Jun 04 18:49:20 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -353,5 +353,5 @@
     /**
      * Lazily parsed schema for the binding file.
      */
-    public static final SchemaCache bindingFileSchema = new SchemaCache(BindInfo.class.getResource("binding.xsd"));
+    public static SchemaCache bindingFileSchema = new SchemaCache("binding.xsd", BindInfo.class, true);
 }
--- a/src/jdk.xml.bind/share/classes/com/sun/xml/internal/xsom/impl/parser/ParserContext.java	Thu Jun 04 09:31:49 2015 -0700
+++ b/src/jdk.xml.bind/share/classes/com/sun/xml/internal/xsom/impl/parser/ParserContext.java	Thu Jun 04 18:49:20 2015 -0700
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 1997, 2015, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -39,6 +39,8 @@
 import org.xml.sax.SAXException;
 import org.xml.sax.SAXParseException;
 
+import java.io.IOException;
+import java.io.InputStream;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -81,20 +83,18 @@
         this.owner = owner;
         this.parser = parser;
 
-        try {
-            parse(new InputSource(ParserContext.class.getResource("datatypes.xsd").toExternalForm()));
+        try (InputStream is = ParserContext.class.getResourceAsStream("datatypes.xsd")) {
+            InputSource source = new InputSource(is);
+            source.setSystemId("datatypes.xsd");
+            parse(source);
 
             SchemaImpl xs = (SchemaImpl)
-                schemaSet.getSchema("http://www.w3.org/2001/XMLSchema");
+                    schemaSet.getSchema("http://www.w3.org/2001/XMLSchema");
             xs.addSimpleType(schemaSet.anySimpleType,true);
             xs.addComplexType(schemaSet.anyType,true);
-        } catch( SAXException e ) {
+        } catch( SAXException | IOException e ) {
             // this must be a bug of XSOM
-            if(e.getException()!=null)
-                e.getException().printStackTrace();
-            else
-                e.printStackTrace();
-            throw new InternalError();
+            throw new InternalError(e.getMessage());
         }
     }