< prev index next >

jaxws/src/jdk.xml.bind/share/classes/com/sun/tools/internal/xjc/SchemaCache.java

Print this page


   1 /*
   2  * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  77             synchronized (this) {
  78                 if (schema == null) {
  79 
  80                     ResourceResolver resourceResolver = null;
  81                     try (InputStream is = clazz.getResourceAsStream(resourceName)) {
  82 
  83                         StreamSource source = new StreamSource(is);
  84                         source.setSystemId(resourceName);
  85                         // do not disable secure processing - these are well-known schemas
  86 
  87                         SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
  88                         SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
  89 
  90                         if (createResolver) {
  91                             resourceResolver = new ResourceResolver(clazz);
  92                             schemaFactory.setResourceResolver(resourceResolver);
  93                         }
  94                         schema = schemaFactory.newSchema(source);
  95 
  96                     } catch (IOException | SAXException e) {
  97                         throw new InternalError(e);


  98                     } finally {
  99                         if (resourceResolver != null) resourceResolver.closeStreams();
 100                     }
 101                 }
 102             }
 103         }
 104         return schema.newValidatorHandler();
 105     }
 106 
 107     class ResourceResolver implements LSResourceResolver {
 108 
 109         private List<InputStream> streamsToClose = Collections.synchronizedList(new ArrayList<InputStream>());
 110         private Class<?> clazz;
 111 
 112         ResourceResolver(Class<?> clazz) {
 113             this.clazz = clazz;
 114         }
 115 
 116         @Override
 117         public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {


 204     }
 205 
 206     @Override
 207     public String getEncoding() {
 208         return null;
 209     }
 210 
 211     @Override
 212     public void setEncoding(String encoding) {
 213     }
 214 
 215     @Override
 216     public boolean getCertifiedText() {
 217         return false;
 218     }
 219 
 220     @Override
 221     public void setCertifiedText(boolean certifiedText) {
 222     }
 223 }
 224 
 225 
   1 /*
   2  * Copyright (c) 1997, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  77             synchronized (this) {
  78                 if (schema == null) {
  79 
  80                     ResourceResolver resourceResolver = null;
  81                     try (InputStream is = clazz.getResourceAsStream(resourceName)) {
  82 
  83                         StreamSource source = new StreamSource(is);
  84                         source.setSystemId(resourceName);
  85                         // do not disable secure processing - these are well-known schemas
  86 
  87                         SchemaFactory sf = XmlFactory.createSchemaFactory(XMLConstants.W3C_XML_SCHEMA_NS_URI, false);
  88                         SchemaFactory schemaFactory = allowExternalAccess(sf, "file", false);
  89 
  90                         if (createResolver) {
  91                             resourceResolver = new ResourceResolver(clazz);
  92                             schemaFactory.setResourceResolver(resourceResolver);
  93                         }
  94                         schema = schemaFactory.newSchema(source);
  95 
  96                     } catch (IOException | SAXException e) {
  97                         InternalError ie = new InternalError(e.getMessage());
  98                         ie.initCause(e);
  99                         throw ie;
 100                     } finally {
 101                         if (resourceResolver != null) resourceResolver.closeStreams();
 102                     }
 103                 }
 104             }
 105         }
 106         return schema.newValidatorHandler();
 107     }
 108 
 109     class ResourceResolver implements LSResourceResolver {
 110 
 111         private List<InputStream> streamsToClose = Collections.synchronizedList(new ArrayList<InputStream>());
 112         private Class<?> clazz;
 113 
 114         ResourceResolver(Class<?> clazz) {
 115             this.clazz = clazz;
 116         }
 117 
 118         @Override
 119         public LSInput resolveResource(String type, String namespaceURI, String publicId, String systemId, String baseURI) {


 206     }
 207 
 208     @Override
 209     public String getEncoding() {
 210         return null;
 211     }
 212 
 213     @Override
 214     public void setEncoding(String encoding) {
 215     }
 216 
 217     @Override
 218     public boolean getCertifiedText() {
 219         return false;
 220     }
 221 
 222     @Override
 223     public void setCertifiedText(boolean certifiedText) {
 224     }
 225 }


< prev index next >