KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > sendopts > OptionProcessor


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
20 package org.netbeans.spi.sendopts;
21
22 import java.util.Map JavaDoc;
23 import java.util.Set JavaDoc;
24 import org.netbeans.api.sendopts.CommandException;
25
26 /** A subclass of this class shall be registered in
27  * <code>META-INF/services/org.netbeans.spi.sendopts.OptionProcessor</code>
28  * file (see <a HREF="@org-openide-util@/org/openide/util/Lookup.html">Lookup</a>
29  * for description of how to do it and why)
30  * in order to register it for participation on handling
31  * and processing of command line options initiated by
32  * {@link org.netbeans.api.sendopts.CommandLine#getDefault}'s
33  * {@link org.netbeans.api.sendopts.CommandLine#process}.
34  * When the {@link Option}s provided by this processor are found
35  * on the command line and are consistent, this processor's {@link #process}
36  * method is going to be called to handle their values and invoke an action.
37  * <p>
38  * The usual pattern for writing a subclass of processor is:
39  * <pre>
40  * public class MyProcessor extends OptionProcessor {
41  * private Option option1 = ...;
42  * private Option option2 = ...;
43  * private Option option3 = ...;
44  *
45  * protected Set<Option> getOptions() {
46  * Set<Option> set = new HashSet<Option>();
47  * set.add(option1);
48  * set.add(option2);
49  * set.add(option3);
50  * return set;
51  * }
52  *
53  * protected void process(<a HREF="Env.html">Env</a> env, Map&lt;<a HREF="Option.html">Option</a>,String[]&gt; values)
54  * throws {@link CommandException} {
55  * if (values.containKey(option1) { ... }
56  * if (values.containKey(option2) { ... }
57  * if (values.containKey(option3) { ... }
58  * }
59  * }
60  * </pre>
61  *
62  * @author Jaroslav Tulach
63  */

64 public abstract class OptionProcessor {
65     /** Constructor for subclasses.
66      */

67     protected OptionProcessor() {
68     }
69     
70     /** Method to override in subclasses to create
71      * the right set of {@link Option}s.
72      * See the factory methods that are part of the {@link Option}'s javadoc
73      * or read the <a HREF="@TOP@/architecture-summary.html#answer-usecases">
74      * usecases</a> for the sendopts API.
75      * <p>
76      *
77      * @return a set of options this processor is interested in, if during
78      * processing at least on of the options appears on command line
79      * the {@link OptionProcessor#process} method will be invoked to
80      * handle such option and its values
81      */

82     protected abstract Set JavaDoc<Option> getOptions();
83     
84     
85     /** Called by the sendopts parsing infrastructure as a result of
86      * {@link org.netbeans.api.sendopts.CommandLine#process}. The method shall read the values
87      * associated with the option(s) this {@link OptionProcessor} defines
88      * and invoke an action to handle them. While doing this it can
89      * communicate with external world using its environment (see {@link Env}).
90      * Such environment provides access to current user directory, standard
91      * output and error streams, as well standard input stream. In case
92      * the processing of options fails, the code shall thrown {@link CommandException}.
93      *
94      * @param env the environment to communicate with
95      * @param optionValues map of all options that appeared on command line with their values
96      * @exception CommandException in case the processing fails1
97      */

98     protected abstract void process(Env env, Map JavaDoc<Option,String JavaDoc[]> optionValues)
99     throws CommandException;
100 }
101
Popular Tags