src/share/jaxws_classes/com/sun/tools/internal/jxc/ConfigReader.java

changeset 368
0989ad8c0860
parent 286
f50545b5e2f1
child 637
9c07ef4934dd
equal deleted inserted replaced
366:8c0b6bccfe47 368:0989ad8c0860
1 /* 1 /*
2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this 7 * published by the Free Software Foundation. Oracle designates this
23 * questions. 23 * questions.
24 */ 24 */
25 25
26 package com.sun.tools.internal.jxc; 26 package com.sun.tools.internal.jxc;
27 27
28 import com.sun.tools.internal.jxc.ap.Options;
28 import java.io.File; 29 import java.io.File;
29 import java.io.IOException; 30 import java.io.IOException;
30 import java.util.Collection; 31 import java.util.Collection;
31 import java.util.HashMap; 32 import java.util.HashMap;
32 import java.util.HashSet; 33 import java.util.HashSet;
49 import com.sun.tools.internal.jxc.gen.config.Schema; 50 import com.sun.tools.internal.jxc.gen.config.Schema;
50 import com.sun.tools.internal.xjc.SchemaCache; 51 import com.sun.tools.internal.xjc.SchemaCache;
51 import com.sun.tools.internal.xjc.api.Reference; 52 import com.sun.tools.internal.xjc.api.Reference;
52 import com.sun.tools.internal.xjc.util.ForkContentHandler; 53 import com.sun.tools.internal.xjc.util.ForkContentHandler;
53 54
55 import com.sun.xml.internal.bind.v2.util.XmlFactory;
54 import org.xml.sax.ErrorHandler; 56 import org.xml.sax.ErrorHandler;
55 import org.xml.sax.InputSource; 57 import org.xml.sax.InputSource;
56 import org.xml.sax.SAXException; 58 import org.xml.sax.SAXException;
57 import org.xml.sax.XMLReader; 59 import org.xml.sax.XMLReader;
58 60
92 * @throws IOException 94 * @throws IOException
93 * If any IO errors occur. 95 * If any IO errors occur.
94 */ 96 */
95 public ConfigReader(ProcessingEnvironment env, Collection<? extends TypeElement> classes, File xmlFile, ErrorHandler errorHandler) throws SAXException, IOException { 97 public ConfigReader(ProcessingEnvironment env, Collection<? extends TypeElement> classes, File xmlFile, ErrorHandler errorHandler) throws SAXException, IOException {
96 this.env = env; 98 this.env = env;
97 Config config = parseAndGetConfig(xmlFile,errorHandler); 99 Config config = parseAndGetConfig(xmlFile, errorHandler, env.getOptions().containsKey(Options.DISABLE_XML_SECURITY));
98 checkAllClasses(config,classes); 100 checkAllClasses(config,classes);
99 String path = xmlFile.getAbsolutePath(); 101 String path = xmlFile.getAbsolutePath();
100 String xmlPath = path.substring(0,path.lastIndexOf(File.separatorChar)); 102 String xmlPath = path.substring(0,path.lastIndexOf(File.separatorChar));
101 schemaOutputResolver = createSchemaOutputResolver(config,xmlPath); 103 schemaOutputResolver = createSchemaOutputResolver(config,xmlPath);
102 104
148 return schemaOutputResolver; 150 return schemaOutputResolver;
149 } 151 }
150 152
151 private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) { 153 private SchemaOutputResolver createSchemaOutputResolver(Config config, String xmlpath) {
152 File baseDir = new File(xmlpath, config.getBaseDir().getPath()); 154 File baseDir = new File(xmlpath, config.getBaseDir().getPath());
153 SchemaOutputResolverImpl schemaOutputResolver = new SchemaOutputResolverImpl (baseDir); 155 SchemaOutputResolverImpl outResolver = new SchemaOutputResolverImpl (baseDir);
154 156
155 for( Schema schema : (List<Schema>)config.getSchema() ) { 157 for( Schema schema : (List<Schema>)config.getSchema() ) {
156 String namespace = schema.getNamespace(); 158 String namespace = schema.getNamespace();
157 File location = schema.getLocation(); 159 File location = schema.getLocation();
158 schemaOutputResolver.addSchemaInfo(namespace,location); 160 outResolver.addSchemaInfo(namespace,location);
159 } 161 }
160 return schemaOutputResolver; 162 return outResolver;
161 } 163 }
162 164
163 /** 165 /**
164 * This will check if the qualified name matches the pattern 166 * This will check if the qualified name matches the pattern
165 * 167 *
188 * @param xmlFile 190 * @param xmlFile
189 * The xml config file which is passed by the user to annotation processing 191 * The xml config file which is passed by the user to annotation processing
190 * @return 192 * @return
191 * A non null Config object 193 * A non null Config object
192 */ 194 */
193 private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler) throws SAXException, IOException { 195 private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
194 XMLReader reader; 196 XMLReader reader;
195 try { 197 try {
196 SAXParserFactory factory = SAXParserFactory.newInstance(); 198 SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
197 factory.setNamespaceAware(true);
198 reader = factory.newSAXParser().getXMLReader(); 199 reader = factory.newSAXParser().getXMLReader();
199 } catch (ParserConfigurationException e) { 200 } catch (ParserConfigurationException e) {
200 // in practice this will never happen 201 // in practice this will never happen
201 throw new Error(e); 202 throw new Error(e);
202 } 203 }

mercurial