325N/A/*
325N/A * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
325N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
325N/A *
325N/A * This code is free software; you can redistribute it and/or modify it
325N/A * under the terms of the GNU General Public License version 2 only, as
325N/A * published by the Free Software Foundation. Oracle designates this
325N/A * particular file as subject to the "Classpath" exception as provided
325N/A * by Oracle in the LICENSE file that accompanied this code.
325N/A *
325N/A * This code is distributed in the hope that it will be useful, but WITHOUT
325N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
325N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
325N/A * version 2 for more details (a copy is included in the LICENSE file that
325N/A * accompanied this code).
325N/A *
325N/A * You should have received a copy of the GNU General Public License version
325N/A * 2 along with this work; if not, write to the Free Software Foundation,
325N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
325N/A *
325N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
325N/A * or visit www.oracle.com if you need additional information or have any
325N/A * questions.
325N/A */
325N/A
325N/Apackage com.sun.tools.internal.xjc;
325N/A
325N/Aimport java.lang.reflect.InvocationTargetException;
325N/Aimport java.lang.reflect.Method;
325N/A
325N/A/**
325N/A * A shabby driver to invoke XJC1 or XJC2 depending on the command line switch.
325N/A *
325N/A * <p>
325N/A * This class is compiled with -source 1.2 so that we can report a nice user-friendly
325N/A * "you require Tiger" error message.
325N/A *
325N/A * @author Kohsuke Kawaguchi
325N/A */
325N/Apublic class XJCFacade {
325N/A
325N/A public static void main(String[] args) throws Throwable {
325N/A String v = "2.0"; // by default, we go 2.0
325N/A
325N/A for( int i=0; i<args.length; i++ ) {
325N/A if(args[i].equals("-source")) {
325N/A if(i+1<args.length) {
325N/A v = parseVersion(args[i+1]);
325N/A }
325N/A }
325N/A }
325N/A
325N/A try {
325N/A ClassLoader cl = ClassLoaderBuilder.createProtectiveClassLoader(XJCFacade.class.getClassLoader(), v);
325N/A
325N/A Class driver = cl.loadClass("com.sun.tools.internal.xjc.Driver");
325N/A Method mainMethod = driver.getDeclaredMethod("main", new Class[]{String[].class});
325N/A try {
325N/A mainMethod.invoke(null,new Object[]{args});
325N/A } catch (IllegalAccessException e) {
325N/A throw e;
325N/A } catch (InvocationTargetException e) {
325N/A if(e.getTargetException()!=null)
325N/A throw e.getTargetException();
325N/A }
325N/A } catch (UnsupportedClassVersionError e) {
325N/A System.err.println("XJC requires JDK 5.0 or later. Please download it from http://java.sun.com/j2se/1.5/");
325N/A }
325N/A }
325N/A
325N/A private static String parseVersion(String version) {
325N/A if(version.equals("1.0"))
325N/A return version;
325N/A // if we don't recognize the version number, we'll go to 2.0 RI
325N/A // anyway. It's easier to report an error message there,
325N/A // than in here.
325N/A return "2.0";
325N/A }
325N/A}