01: /*
02: * Copyright 2006 Sun Microsystems, Inc. All Rights Reserved.
03: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
04: *
05: * This code is free software; you can redistribute it and/or modify it
06: * under the terms of the GNU General Public License version 2 only, as
07: * published by the Free Software Foundation. Sun designates this
08: * particular file as subject to the "Classpath" exception as provided
09: * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
22: * CA 95054 USA or visit www.sun.com if you need additional information or
23: * have any questions.
24: */
25:
26: package com.sun.tools.internal.jxc.apt;
27:
28: import java.io.File;
29: import java.util.ArrayList;
30: import java.util.List;
31:
32: import com.sun.tools.internal.xjc.BadCommandLineException;
33:
34: /**
35: * This stores the invocation configuration for
36: * SchemaGenerator
37: *
38: * @author Bhakti Mehta
39: */
40: public class Options {
41:
42: // honor CLASSPATH environment variable, but it will be overrided by -cp
43: public String classpath = System.getenv("CLASSPATH");
44:
45: public File targetDir = null;
46:
47: public final List<String> arguments = new ArrayList<String>();
48:
49: public void parseArguments(String[] args)
50: throws BadCommandLineException {
51: for (int i = 0; i < args.length; i++) {
52: if (args[i].charAt(0) == '-') {
53: int j = parseArgument(args, i);
54: if (j == 0)
55: throw new BadCommandLineException(
56: Messages.UNRECOGNIZED_PARAMETER
57: .format(args[i]));
58: i += j;
59: } else {
60: arguments.add(args[i]);
61: }
62: }
63: }
64:
65: private int parseArgument(String[] args, int i)
66: throws BadCommandLineException {
67: if (args[i].equals("-d")) {
68: if (i == args.length - 1)
69: throw new BadCommandLineException(
70: (Messages.NO_FILE_SPECIFIED.format()));
71: targetDir = new File(args[++i]);
72: if (!targetDir.exists())
73: throw new BadCommandLineException(
74: Messages.NON_EXISTENT_FILE.format(targetDir));
75: return 1;
76: }
77:
78: if (args[i].equals("-cp") || args[i].equals("-classpath")) {
79: if (i == args.length - 1)
80: throw new BadCommandLineException(
81: (Messages.NO_CLASSPATH_SPECIFIED.format()));
82: classpath = args[++i];
83:
84: return 1;
85: }
86:
87: return 0;
88:
89: }
90:
91: }
|