KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > sendopts > HandlerImpl


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 package org.netbeans.modules.sendopts;
20
21 import java.io.File JavaDoc;
22 import java.io.InputStream JavaDoc;
23 import java.io.OutputStream JavaDoc;
24 import java.io.PrintStream JavaDoc;
25 import java.io.PrintWriter JavaDoc;
26 import org.netbeans.api.sendopts.CommandException;
27 import org.netbeans.api.sendopts.CommandLine;
28 import org.openide.util.NbBundle;
29
30 /**
31  * Bridge between the CLIHandler that can be unit tested
32  * @author Jaroslav Tulach
33  */

34 final class HandlerImpl extends Object JavaDoc {
35     static int execute(String JavaDoc[] arr, InputStream JavaDoc is, OutputStream JavaDoc os, OutputStream JavaDoc err, File JavaDoc pwd) {
36         try {
37             CommandLine.getDefault().process(
38                 arr, is, os, err, pwd
39                 );
40             for (int i = 0; i < arr.length; i++) {
41                 arr[i] = null;
42             }
43             return 0;
44         } catch (CommandException ex) {
45             PrintStream JavaDoc ps = new PrintStream JavaDoc(err);
46             ps.println(ex.getLocalizedMessage());
47             // XXX pst is not useful, only in verbose mode
48
// the question is how to turn that mode on
49
// ex.printStackTrace(ps);
50
return ex.getExitCode();
51         }
52     }
53     
54     static void usage(PrintWriter JavaDoc w) {
55         w.print(NbBundle.getMessage(HandlerImpl.class, "MSG_OptionsHeader")); // NOI18N
56
CommandLine.getDefault().usage(w);
57         w.println();
58     }
59 }
60
Popular Tags