< prev index next >

src/jdk.xml.bind/share/classes/com/sun/tools/internal/jxc/ConfigReader.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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.jxc;
  27 
  28 import com.sun.tools.internal.jxc.ap.Options;
  29 import java.io.File;
  30 import java.io.IOException;

  31 import java.util.Collection;
  32 import java.util.HashMap;
  33 import java.util.HashSet;
  34 import java.util.List;
  35 import java.util.Map;
  36 import java.util.Set;
  37 import java.util.regex.Matcher;
  38 import java.util.regex.Pattern;
  39 
  40 import javax.xml.bind.SchemaOutputResolver;
  41 import javax.xml.parsers.ParserConfigurationException;
  42 import javax.xml.parsers.SAXParserFactory;
  43 import javax.xml.transform.Result;
  44 import javax.xml.transform.stream.StreamResult;

  45 import javax.xml.validation.ValidatorHandler;
  46 
  47 import javax.annotation.processing.ProcessingEnvironment;
  48 import javax.lang.model.element.TypeElement;
  49 import com.sun.tools.internal.jxc.gen.config.Config;
  50 import com.sun.tools.internal.jxc.gen.config.Schema;
  51 import com.sun.tools.internal.xjc.SchemaCache;
  52 import com.sun.tools.internal.xjc.api.Reference;
  53 import com.sun.tools.internal.xjc.util.ForkContentHandler;
  54 
  55 import com.sun.xml.internal.bind.v2.util.XmlFactory;
  56 import org.xml.sax.ErrorHandler;
  57 import org.xml.sax.InputSource;
  58 import org.xml.sax.SAXException;
  59 import org.xml.sax.XMLReader;
  60 
  61 
  62 /**
  63  * This reads the config files passed by the user to annotation processing
  64  * and obtains a list of classes that need to be included


 164 
 165     /**
 166      * This will  check if the qualified name matches the pattern
 167      *
 168      * @param qualifiedName
 169      *      The qualified name of the TypeDeclaration
 170      * @param pattern
 171      *       The  pattern obtained from the users input
 172      *
 173      */
 174     private boolean checkPatternMatch(String qualifiedName, Pattern pattern) {
 175         Matcher matcher = pattern.matcher(qualifiedName);
 176         return matcher.matches();
 177     }
 178 
 179 
 180 
 181     /**
 182      * Lazily parsed schema for the binding file.
 183      */
 184     private static SchemaCache configSchema = new SchemaCache(Config.class.getResource("config.xsd"));
 185 






 186 
 187     /**
 188      * Parses an xml config file and returns a Config object.
 189      *
 190      * @param xmlFile
 191      *        The xml config file which is passed by the user to annotation processing
 192      * @return
 193      *        A non null Config object
 194      */
 195     private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
 196         XMLReader reader;
 197         try {
 198             SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
 199             reader = factory.newSAXParser().getXMLReader();
 200         } catch (ParserConfigurationException e) {
 201             // in practice this will never happen
 202             throw new Error(e);
 203         }
 204         NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
 205 


   1 /*
   2  * Copyright (c) 1997, 2015, 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
  23  * questions.
  24  */
  25 
  26 package com.sun.tools.internal.jxc;
  27 
  28 import com.sun.tools.internal.jxc.ap.Options;
  29 import java.io.File;
  30 import java.io.IOException;
  31 import java.io.InputStream;
  32 import java.util.Collection;
  33 import java.util.HashMap;
  34 import java.util.HashSet;
  35 import java.util.List;
  36 import java.util.Map;
  37 import java.util.Set;
  38 import java.util.regex.Matcher;
  39 import java.util.regex.Pattern;
  40 
  41 import javax.xml.bind.SchemaOutputResolver;
  42 import javax.xml.parsers.ParserConfigurationException;
  43 import javax.xml.parsers.SAXParserFactory;
  44 import javax.xml.transform.Result;
  45 import javax.xml.transform.stream.StreamResult;
  46 import javax.xml.transform.stream.StreamSource;
  47 import javax.xml.validation.ValidatorHandler;
  48 
  49 import javax.annotation.processing.ProcessingEnvironment;
  50 import javax.lang.model.element.TypeElement;
  51 import com.sun.tools.internal.jxc.gen.config.Config;
  52 import com.sun.tools.internal.jxc.gen.config.Schema;
  53 import com.sun.tools.internal.xjc.SchemaCache;
  54 import com.sun.tools.internal.xjc.api.Reference;
  55 import com.sun.tools.internal.xjc.util.ForkContentHandler;
  56 
  57 import com.sun.xml.internal.bind.v2.util.XmlFactory;
  58 import org.xml.sax.ErrorHandler;
  59 import org.xml.sax.InputSource;
  60 import org.xml.sax.SAXException;
  61 import org.xml.sax.XMLReader;
  62 
  63 
  64 /**
  65  * This reads the config files passed by the user to annotation processing
  66  * and obtains a list of classes that need to be included


 166 
 167     /**
 168      * This will  check if the qualified name matches the pattern
 169      *
 170      * @param qualifiedName
 171      *      The qualified name of the TypeDeclaration
 172      * @param pattern
 173      *       The  pattern obtained from the users input
 174      *
 175      */
 176     private boolean checkPatternMatch(String qualifiedName, Pattern pattern) {
 177         Matcher matcher = pattern.matcher(qualifiedName);
 178         return matcher.matches();
 179     }
 180 
 181 
 182 
 183     /**
 184      * Lazily parsed schema for the binding file.
 185      */
 186     private static SchemaCache configSchema = new SchemaCache(newStreamSource("config.xsd"));
 187 
 188     private static StreamSource newStreamSource(String systemId) {
 189         InputStream is = Config.class.getResourceAsStream(systemId);
 190         StreamSource schema = new StreamSource(is);
 191         schema.setSystemId(systemId);
 192         return schema;
 193     }
 194 
 195     /**
 196      * Parses an xml config file and returns a Config object.
 197      *
 198      * @param xmlFile
 199      *        The xml config file which is passed by the user to annotation processing
 200      * @return
 201      *        A non null Config object
 202      */
 203     private Config parseAndGetConfig (File xmlFile, ErrorHandler errorHandler, boolean disableSecureProcessing) throws SAXException, IOException {
 204         XMLReader reader;
 205         try {
 206             SAXParserFactory factory = XmlFactory.createParserFactory(disableSecureProcessing);
 207             reader = factory.newSAXParser().getXMLReader();
 208         } catch (ParserConfigurationException e) {
 209             // in practice this will never happen
 210             throw new Error(e);
 211         }
 212         NGCCRuntimeEx runtime = new NGCCRuntimeEx(errorHandler);
 213 


< prev index next >