1/* 2 * Copyright (c) 1997, 2014, 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 26package com.sun.tools.internal.jxc.ap; 27 28import java.io.File; 29import java.util.ArrayList; 30import java.util.List; 31 32import com.sun.tools.internal.xjc.BadCommandLineException; 33 34/** 35 * This stores the invocation configuration for 36 * SchemaGenerator 37 * 38 * @author Bhakti Mehta 39 */ 40public class Options { 41 42 public static final String DISABLE_XML_SECURITY = "-disableXmlSecurity"; 43 44 // honor CLASSPATH environment variable, but it will be overrided by -cp 45 public String classpath = System.getenv("CLASSPATH"); 46 47 public File targetDir = null; 48 49 public File episodeFile = null; 50 51 private boolean disableXmlSecurity = false; 52 53 // encoding is not required for JDK5, 6, but JDK 7 javac is much more strict - see issue 6859289 54 public String encoding = null; 55 56 public final List<String> arguments = new ArrayList<String>(); 57 58 public void parseArguments(String[] args) throws BadCommandLineException { 59 for (int i = 0 ; i <args.length; i++) { 60 if (args[i].charAt(0)== '-') { 61 i += parseArgument(args, i); 62 } else { 63 arguments.add(args[i]); 64 } 65 } 66 } 67 68 private int parseArgument( String[] args, int i ) throws BadCommandLineException { 69 if (args[i].equals("-d")) { 70 if (i == args.length - 1) 71 throw new BadCommandLineException( 72 (Messages.OPERAND_MISSING.format(args[i]))); 73 targetDir = new File(args[++i]); 74 if( !targetDir.exists() ) 75 throw new BadCommandLineException( 76 Messages.NON_EXISTENT_FILE.format(targetDir)); 77 return 1; 78 } 79 80 if (args[i].equals("-episode")) { 81 if (i == args.length - 1) 82 throw new BadCommandLineException( 83 (Messages.OPERAND_MISSING.format(args[i]))); 84 episodeFile = new File(args[++i]); 85 return 1; 86 } 87 88 if (args[i].equals(DISABLE_XML_SECURITY)) { 89 disableXmlSecurity = true; 90 return 0; 91 } 92 93 if (args[i].equals("-encoding")) { 94 if (i == args.length - 1) 95 throw new BadCommandLineException( 96 (Messages.OPERAND_MISSING.format(args[i]))); 97 encoding = args[++i]; 98 return 1; 99 } 100 101 if (args[i].equals("-cp") || args[i].equals("-classpath")) { 102 if (i == args.length - 1) 103 throw new BadCommandLineException( 104 (Messages.OPERAND_MISSING.format(args[i]))); 105 classpath = args[++i]; 106 107 return 1; 108 } 109 110 throw new BadCommandLineException( 111 Messages.UNRECOGNIZED_PARAMETER.format(args[i])); 112 } 113 114 /** 115 * @return the disableXmlSecurity 116 */ 117 public boolean isDisableXmlSecurity() { 118 return disableXmlSecurity; 119 } 120 121 122 123} 124