src/share/jaxws_classes/com/sun/tools/internal/xjc/Options.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, 2013, 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
43 import java.util.Date; 43 import java.util.Date;
44 import java.util.Enumeration; 44 import java.util.Enumeration;
45 import java.util.HashSet; 45 import java.util.HashSet;
46 import java.util.List; 46 import java.util.List;
47 import java.util.Set; 47 import java.util.Set;
48 import java.util.regex.Matcher;
49 import java.util.regex.Pattern;
50 48
51 import com.sun.codemodel.internal.CodeWriter; 49 import com.sun.codemodel.internal.CodeWriter;
52 import com.sun.codemodel.internal.JPackage; 50 import com.sun.codemodel.internal.JPackage;
51 import com.sun.codemodel.internal.JResourceFile;
53 import com.sun.codemodel.internal.writer.FileCodeWriter; 52 import com.sun.codemodel.internal.writer.FileCodeWriter;
54 import com.sun.codemodel.internal.writer.PrologCodeWriter; 53 import com.sun.codemodel.internal.writer.PrologCodeWriter;
54 import com.sun.istack.internal.tools.DefaultAuthenticator;
55 import com.sun.org.apache.xml.internal.resolver.CatalogManager; 55 import com.sun.org.apache.xml.internal.resolver.CatalogManager;
56 import com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver; 56 import com.sun.org.apache.xml.internal.resolver.tools.CatalogResolver;
57 import com.sun.tools.internal.xjc.api.ClassNameAllocator; 57 import com.sun.tools.internal.xjc.api.ClassNameAllocator;
58 import com.sun.tools.internal.xjc.api.SpecVersion; 58 import com.sun.tools.internal.xjc.api.SpecVersion;
59 import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory; 59 import com.sun.tools.internal.xjc.generator.bean.field.FieldRendererFactory;
104 104
105 /** Encoding to be used by generated java sources, null for platform default. */ 105 /** Encoding to be used by generated java sources, null for platform default. */
106 public String encoding; 106 public String encoding;
107 107
108 /** 108 /**
109 * If true XML security features when parsing XML documents will be disabled.
110 * The default value is false.
111 *
112 * Boolean
113 * @since 2.2.6
114 */
115 public boolean disableXmlSecurity;
116
117 /**
109 * Check the source schemas with extra scrutiny. 118 * Check the source schemas with extra scrutiny.
110 * The exact meaning depends on the schema language. 119 * The exact meaning depends on the schema language.
111 */ 120 */
112 public boolean strictCheck =true; 121 public boolean strictCheck =true;
113 122
150 /** 159 /**
151 * Generates output for the specified version of the runtime. 160 * Generates output for the specified version of the runtime.
152 */ 161 */
153 public SpecVersion target = SpecVersion.LATEST; 162 public SpecVersion target = SpecVersion.LATEST;
154 163
155 private boolean is2_2 = true;
156 164
157 public Options() { 165 public Options() {
158 if (is2_2) { 166 try {
159 try { 167 Class.forName("javax.xml.bind.JAXBPermission");
160 Class.forName("javax.xml.bind.JAXBPermission"); 168 } catch (ClassNotFoundException cnfe) {
161 } catch (ClassNotFoundException cnfe) { 169 target = SpecVersion.V2_1;
162 is2_2 = false;
163 }
164 if (!is2_2) {
165 target = SpecVersion.V2_1;
166 } else {
167 target = SpecVersion.LATEST;
168 }
169 } 170 }
170 } 171 }
171 172
172 /** 173 /**
173 * Target directory when producing files. 174 * Target directory when producing files.
211 private final List<InputSource> bindFiles = new ArrayList<InputSource>(); 212 private final List<InputSource> bindFiles = new ArrayList<InputSource>();
212 213
213 // Proxy setting. 214 // Proxy setting.
214 private String proxyHost = null; 215 private String proxyHost = null;
215 private String proxyPort = null; 216 private String proxyPort = null;
216 private String proxyUser = null; 217 public String proxyAuth = null;
217 private String proxyPassword = null;
218 218
219 /** 219 /**
220 * {@link Plugin}s that are enabled in this compilation. 220 * {@link Plugin}s that are enabled in this compilation.
221 */ 221 */
222 public final List<Plugin> activePlugins = new ArrayList<Plugin>(); 222 public final List<Plugin> activePlugins = new ArrayList<Plugin>();
457 public final List<URL> classpaths = new ArrayList<URL>(); 457 public final List<URL> classpaths = new ArrayList<URL>();
458 /** 458 /**
459 * Gets a classLoader that can load classes specified via the 459 * Gets a classLoader that can load classes specified via the
460 * -classpath option. 460 * -classpath option.
461 */ 461 */
462 public URLClassLoader getUserClassLoader( ClassLoader parent ) { 462 public ClassLoader getUserClassLoader( ClassLoader parent ) {
463 if (classpaths.isEmpty())
464 return parent;
463 return new URLClassLoader( 465 return new URLClassLoader(
464 classpaths.toArray(new URL[classpaths.size()]),parent); 466 classpaths.toArray(new URL[classpaths.size()]),parent);
465 } 467 }
466 468
467 469
540 } 542 }
541 if (args[i].equals("-enableIntrospection")) { 543 if (args[i].equals("-enableIntrospection")) {
542 enableIntrospection = true; 544 enableIntrospection = true;
543 return 1; 545 return 1;
544 } 546 }
547 if (args[i].equals("-disableXmlSecurity")) {
548 disableXmlSecurity = true;
549 return 1;
550 }
545 if (args[i].equals("-contentForWildcard")) { 551 if (args[i].equals("-contentForWildcard")) {
546 contentForWildcard = true; 552 contentForWildcard = true;
547 return 1; 553 return 1;
548 } 554 }
549 if (args[i].equals("-XautoNameResolution")) { 555 if (args[i].equals("-XautoNameResolution")) {
635 addCatalog(catalogFile); 641 addCatalog(catalogFile);
636 } catch (IOException e) { 642 } catch (IOException e) {
637 throw new BadCommandLineException( 643 throw new BadCommandLineException(
638 Messages.format(Messages.FAILED_TO_PARSE,catalogFile,e.getMessage()),e); 644 Messages.format(Messages.FAILED_TO_PARSE,catalogFile,e.getMessage()),e);
639 } 645 }
640 return 2;
641 }
642 if (args[i].equals("-source")) {
643 String version = requireArgument("-source",args,++i);
644 //For source 1.0 the 1.0 Driver is loaded
645 //Hence anything other than 2.0 is defaulted to
646 //2.0
647 if( !version.equals("2.0") && !version.equals("2.1") )
648 throw new BadCommandLineException(
649 Messages.format(Messages.DEFAULT_VERSION));
650 return 2; 646 return 2;
651 } 647 }
652 if( args[i].equals("-Xtest-class-name-allocator") ) { 648 if( args[i].equals("-Xtest-class-name-allocator") ) {
653 classNameAllocator = new ClassNameAllocator() { 649 classNameAllocator = new ClassNameAllocator() {
654 public String assignClassName(String packageName, String className) { 650 public String assignClassName(String packageName, String className) {
701 697
702 return 0; // unrecognized 698 return 0; // unrecognized
703 } 699 }
704 700
705 private void parseProxy(String text) throws BadCommandLineException { 701 private void parseProxy(String text) throws BadCommandLineException {
706 // syntax is [user[:password]@]proxyHost:proxyPort 702 int i = text.lastIndexOf('@');
707 String token = "([^@:]+)"; 703 int j = text.lastIndexOf(':');
708 Pattern p = Pattern.compile("(?:"+token+"(?:\\:"+token+")?\\@)?"+token+"(?:\\:"+token+")"); 704
709 705 if (i > 0) {
710 Matcher matcher = p.matcher(text); 706 proxyAuth = text.substring(0, i);
711 if(!matcher.matches()) 707 if (j > i) {
712 throw new BadCommandLineException(Messages.format(Messages.ILLEGAL_PROXY,text)); 708 proxyHost = text.substring(i + 1, j);
713 709 proxyPort = text.substring(j + 1);
714 proxyUser = matcher.group(1); 710 } else {
715 proxyPassword = matcher.group(2); 711 proxyHost = text.substring(i + 1);
716 proxyHost = matcher.group(3); 712 proxyPort = "80";
717 proxyPort = matcher.group(4); 713 }
714 } else {
715 //no auth info
716 if (j < 0) {
717 //no port
718 proxyHost = text;
719 proxyPort = "80";
720 } else {
721 proxyHost = text.substring(0, j);
722 proxyPort = text.substring(j + 1);
723 }
724 }
718 try { 725 try {
719 Integer.valueOf(proxyPort); 726 Integer.valueOf(proxyPort);
720 } catch (NumberFormatException e) { 727 } catch (NumberFormatException e) {
721 throw new BadCommandLineException(Messages.format(Messages.ILLEGAL_PROXY,text)); 728 throw new BadCommandLineException(Messages.format(Messages.ILLEGAL_PROXY,text));
722 } 729 }
809 Messages.format(Messages.MISSING_PROXYHOST)); 816 Messages.format(Messages.MISSING_PROXYHOST));
810 } else { 817 } else {
811 throw new BadCommandLineException( 818 throw new BadCommandLineException(
812 Messages.format(Messages.MISSING_PROXYPORT)); 819 Messages.format(Messages.MISSING_PROXYPORT));
813 } 820 }
814 if(proxyUser!=null) 821 if (proxyAuth != null) {
815 System.setProperty("http.proxyUser", proxyUser); 822 DefaultAuthenticator.getAuthenticator().setProxyAuth(proxyAuth);
816 if(proxyPassword!=null) 823 }
817 System.setProperty("http.proxyPassword", proxyPassword);
818
819 } 824 }
820 825
821 if (grammars.isEmpty()) 826 if (grammars.isEmpty())
822 throw new BadCommandLineException( 827 throw new BadCommandLineException(
823 Messages.format(Messages.MISSING_GRAMMAR)); 828 Messages.format(Messages.MISSING_GRAMMAR));

mercurial