< prev index next >
src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/SchemaCache.java
Print this page
@@ -1,7 +1,7 @@
/*
- * 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
@@ -23,18 +23,19 @@
* questions.
*/
package com.sun.tools.internal.xjc;
-import java.net.URL;
-
+import javax.xml.transform.Source;
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.LSResourceResolver;
import org.xml.sax.SAXException;
import static com.sun.xml.internal.bind.v2.util.XmlFactory.allowExternalAccess;
/**
@@ -46,30 +47,39 @@
* @author Kohsuke Kawaguchi
*/
public final class SchemaCache {
private Schema schema;
+ private Source source;
+ private LSResourceResolver resourceResolver;
- private final URL source;
+ public SchemaCache(Source source) {
+ this(source, null);
+ }
- public SchemaCache(URL source) {
+ public SchemaCache(Source source, LSResourceResolver resourceResolver) {
this.source = source;
+ this.resourceResolver = resourceResolver;
}
public ValidatorHandler newValidator() {
- synchronized(this) {
if(schema==null) {
+ 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);
+ SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
+ schemaFactory.setResourceResolver(resourceResolver);
+ schema = schemaFactory.newSchema(source);
} catch (SAXException e) {
// we make sure that the schema is correct before we ship.
throw new AssertionError(e);
}
}
}
+ }
ValidatorHandler handler = schema.newValidatorHandler();
return handler;
}
< prev index next >