2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.spi.sendopts;
46
import org.netbeans.api.sendopts.CommandException;
48
/** A subclass of this class shall be registered in
49
* <code>META-INF/services/org.netbeans.spi.sendopts.OptionProcessor</code>
50
* file (see <a href="@org-openide-util@/org/openide/util/Lookup.html">Lookup</a>
51
* for description of how to do it and why)
52
* in order to register it for participation on handling
53
* and processing of command line options initiated by
54
* {@link org.netbeans.api.sendopts.CommandLine#getDefault}'s
55
* {@link org.netbeans.api.sendopts.CommandLine#process}.
56
* When the {@link Option}s provided by this processor are found
57
* on the command line and are consistent, this processor's {@link #process}
58
* method is going to be called to handle their values and invoke an action.
60
* The usual pattern for writing a subclass of processor is:
62
* public class MyProcessor extends OptionProcessor {
63
* private Option option1 = ...;
64
* private Option option2 = ...;
65
* private Option option3 = ...;
67
* protected Set<Option> getOptions() {
68
* Set<Option> set = new HashSet<Option>();
75
* protected void process(<a href="Env.html">Env</a> env, Map<<a href="Option.html">Option</a>,String[]> values)
76
* throws {@link CommandException} {
77
* if (values.containKey(option1) { ... }
78
* if (values.containKey(option2) { ... }
79
* if (values.containKey(option3) { ... }
84
* @author Jaroslav Tulach
86
public abstract class OptionProcessor {
87
/** Constructor for subclasses.
89
protected OptionProcessor() {
92
/** Method to override in subclasses to create
93
* the right set of {@link Option}s.
94
* See the factory methods that are part of the {@link Option}'s javadoc
95
* or read the <a href="@TOP@/architecture-summary.html#answer-usecases">
96
* usecases</a> for the sendopts API.
99
* @return a set of options this processor is interested in, if during
100
* processing at least on of the options appears on command line
101
* the {@link OptionProcessor#process} method will be invoked to
102
* handle such option and its values
104
protected abstract Set<Option> getOptions();
107
/** Called by the sendopts parsing infrastructure as a result of
108
* {@link org.netbeans.api.sendopts.CommandLine#process}. The method shall read the values
109
* associated with the option(s) this {@link OptionProcessor} defines
110
* and invoke an action to handle them. While doing this it can
111
* communicate with external world using its environment (see {@link Env}).
112
* Such environment provides access to current user directory, standard
113
* output and error streams, as well standard input stream. In case
114
* the processing of options fails, the code shall thrown {@link CommandException}.
116
* @param env the environment to communicate with
117
* @param optionValues map of all options that appeared on command line with their values
118
* @exception CommandException in case the processing fails1
120
protected abstract void process(Env env, Map<Option,String[]> optionValues)
121
throws CommandException;