Merge
This commit is contained in:
commit
4d46f7fca4
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -41,6 +41,8 @@ import javax.xml.bind.JAXBElement;
|
|||||||
import javax.xml.bind.Unmarshaller;
|
import javax.xml.bind.Unmarshaller;
|
||||||
import javax.xml.stream.XMLInputFactory;
|
import javax.xml.stream.XMLInputFactory;
|
||||||
import javax.xml.ws.WebServiceException;
|
import javax.xml.ws.WebServiceException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
@ -64,6 +66,7 @@ import java.util.logging.Level;
|
|||||||
// TODO Move the logic of this class directly into MetroConfig class.
|
// TODO Move the logic of this class directly into MetroConfig class.
|
||||||
class MetroConfigLoader {
|
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 static final Logger LOGGER = Logger.getLogger(MetroConfigLoader.class);
|
||||||
|
|
||||||
private MetroConfigName defaultTubesConfigNames;
|
private MetroConfigName defaultTubesConfigNames;
|
||||||
@ -122,11 +125,10 @@ class MetroConfigLoader {
|
|||||||
defaultFileName = defaultTubesConfigNames.getDefaultFileName();
|
defaultFileName = defaultTubesConfigNames.getDefaultFileName();
|
||||||
}
|
}
|
||||||
this.defaultConfigUrl = locateResource(defaultFileName, loaders);
|
this.defaultConfigUrl = locateResource(defaultFileName, loaders);
|
||||||
if (defaultConfigUrl == null) {
|
if (defaultConfigUrl != null) {
|
||||||
throw LOGGER.logSevereException(new IllegalStateException(TubelineassemblyMessages.MASM_0001_DEFAULT_CFG_FILE_NOT_FOUND(defaultFileName)));
|
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);
|
this.defaultConfig = MetroConfigLoader.loadMetroConfig(defaultConfigUrl);
|
||||||
if (defaultConfig == null) {
|
if (defaultConfig == null) {
|
||||||
throw LOGGER.logSevereException(new IllegalStateException(TubelineassemblyMessages.MASM_0003_DEFAULT_CFG_FILE_NOT_LOADED(defaultFileName)));
|
throw LOGGER.logSevereException(new IllegalStateException(TubelineassemblyMessages.MASM_0003_DEFAULT_CFG_FILE_NOT_LOADED(defaultFileName)));
|
||||||
@ -235,17 +237,35 @@ class MetroConfigLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static MetroConfig loadMetroConfig(@NotNull URL resourceUrl) {
|
private static MetroConfig loadMetroConfig(@NotNull URL resourceUrl) {
|
||||||
MetroConfig result = null;
|
try (InputStream is = getConfigInputStream(resourceUrl)) {
|
||||||
try {
|
|
||||||
JAXBContext jaxbContext = createJAXBContext();
|
JAXBContext jaxbContext = createJAXBContext();
|
||||||
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
|
||||||
XMLInputFactory factory = XmlUtil.newXMLInputFactory(true);
|
XMLInputFactory factory = XmlUtil.newXMLInputFactory(true);
|
||||||
final JAXBElement<MetroConfig> configElement = unmarshaller.unmarshal(factory.createXMLStreamReader(resourceUrl.openStream()), MetroConfig.class);
|
JAXBElement<MetroConfig> configElement = unmarshaller.unmarshal(factory.createXMLStreamReader(is), MetroConfig.class);
|
||||||
result = configElement.getValue();
|
return configElement.getValue();
|
||||||
} catch (Exception e) {
|
} 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 {
|
private static JAXBContext createJAXBContext() throws Exception {
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -181,7 +181,7 @@ public final class ConfigReader {
|
|||||||
/**
|
/**
|
||||||
* Lazily parsed schema for the binding file.
|
* 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);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -25,14 +25,23 @@
|
|||||||
|
|
||||||
package com.sun.tools.internal.xjc;
|
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.Schema;
|
||||||
import javax.xml.validation.SchemaFactory;
|
import javax.xml.validation.SchemaFactory;
|
||||||
import javax.xml.validation.ValidatorHandler;
|
import javax.xml.validation.ValidatorHandler;
|
||||||
|
|
||||||
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
import com.sun.xml.internal.bind.v2.util.XmlFactory;
|
||||||
import javax.xml.XMLConstants;
|
import javax.xml.XMLConstants;
|
||||||
|
|
||||||
|
import org.w3c.dom.ls.LSInput;
|
||||||
|
import org.w3c.dom.ls.LSResourceResolver;
|
||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
|
|
||||||
import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
|
import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
|
||||||
@ -47,30 +56,170 @@ import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
|
|||||||
*/
|
*/
|
||||||
public final class SchemaCache {
|
public final class SchemaCache {
|
||||||
|
|
||||||
|
private final boolean createResolver;
|
||||||
|
private final String resourceName;
|
||||||
|
private final Class<?> clazz;
|
||||||
|
|
||||||
private Schema schema;
|
private Schema schema;
|
||||||
|
|
||||||
private final URL source;
|
public SchemaCache(String resourceName, Class<?> classToResolveResources) {
|
||||||
|
this(resourceName, classToResolveResources, false);
|
||||||
|
}
|
||||||
|
|
||||||
public SchemaCache(URL source) {
|
public SchemaCache(String resourceName, Class<?> classToResolveResources, boolean createResolver) {
|
||||||
this.source = source;
|
this.resourceName = resourceName;
|
||||||
|
this.createResolver = createResolver;
|
||||||
|
this.clazz = classToResolveResources;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValidatorHandler newValidator() {
|
public ValidatorHandler newValidator() {
|
||||||
synchronized(this) {
|
if (schema==null) {
|
||||||
if(schema==null) {
|
synchronized (this) {
|
||||||
try {
|
if (schema == null) {
|
||||||
// do not disable secure processing - these are well-known schemas
|
|
||||||
SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
|
ResourceResolver resourceResolver = null;
|
||||||
schema = allowExternalAccess(sf, "file", false).newSchema(source);
|
try (InputStream is = clazz.getResourceAsStream(resourceName)) {
|
||||||
} catch (SAXException e) {
|
|
||||||
// we make sure that the schema is correct before we ship.
|
StreamSource source = new StreamSource(is);
|
||||||
throw new AssertionError(e);
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
ValidatorHandler handler = schema.newValidatorHandler();
|
class ResourceResolver implements LSResourceResolver {
|
||||||
return handler;
|
|
||||||
|
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 ...
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -289,7 +289,7 @@ public class BindInfo
|
|||||||
/**
|
/**
|
||||||
* Lazily parsed schema for the binding file.
|
* 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.
|
* Parses an InputSource into dom4j Document.
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -353,5 +353,5 @@ public final class BindInfo implements Iterable<BIDeclaration> {
|
|||||||
/**
|
/**
|
||||||
* Lazily parsed schema for the binding file.
|
* 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);
|
||||||
}
|
}
|
||||||
|
@ -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.
|
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||||
*
|
*
|
||||||
* This code is free software; you can redistribute it and/or modify it
|
* This code is free software; you can redistribute it and/or modify it
|
||||||
@ -39,6 +39,8 @@ import org.xml.sax.Locator;
|
|||||||
import org.xml.sax.SAXException;
|
import org.xml.sax.SAXException;
|
||||||
import org.xml.sax.SAXParseException;
|
import org.xml.sax.SAXParseException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -81,20 +83,18 @@ public class ParserContext {
|
|||||||
this.owner = owner;
|
this.owner = owner;
|
||||||
this.parser = parser;
|
this.parser = parser;
|
||||||
|
|
||||||
try {
|
try (InputStream is = ParserContext.class.getResourceAsStream("datatypes.xsd")) {
|
||||||
parse(new InputSource(ParserContext.class.getResource("datatypes.xsd").toExternalForm()));
|
InputSource source = new InputSource(is);
|
||||||
|
source.setSystemId("datatypes.xsd");
|
||||||
|
parse(source);
|
||||||
|
|
||||||
SchemaImpl xs = (SchemaImpl)
|
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.addSimpleType(schemaSet.anySimpleType,true);
|
||||||
xs.addComplexType(schemaSet.anyType,true);
|
xs.addComplexType(schemaSet.anyType,true);
|
||||||
} catch( SAXException e ) {
|
} catch( SAXException | IOException e ) {
|
||||||
// this must be a bug of XSOM
|
// this must be a bug of XSOM
|
||||||
if(e.getException()!=null)
|
throw new InternalError(e.getMessage());
|
||||||
e.getException().printStackTrace();
|
|
||||||
else
|
|
||||||
e.printStackTrace();
|
|
||||||
throw new InternalError();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user