001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.spi.sendopts;
043:
044: /** Factory method that composes individual options into groups.
045: * In some situations it is useful and sometimes even necessary to
046: * enforce certain relationships among options provided by some,
047: * potentially different modules. Factory methods defined here in allow such
048: * compositions as they take multiple options and convert them
049: * into one group option.
050: * <p>
051: * The following table gives short overview of the behaviour of different
052: * factory methods. Supposed <b>n</b> individual options were passed as
053: * arguments to each method. The <em>Min</em> and <em>Max</em> shown the
054: * number that is needed for the group option to be "consistent":
055: *
056: * <table border=1>
057: * <theader>
058: * <td>Method</td>
059: * <td>Min</td>
060: * <td>Max</td>
061: * </theader>
062: *
063: * <tr>
064: * <td>{@link OptionGroups#allOf}</td>
065: * <td>n</td>
066: * <td>n</td>
067: * </tr>
068: *
069: * <tr>
070: * <td>{@link OptionGroups#oneOf}</td>
071: * <td>1</td>
072: * <td>1</td>
073: * </tr>
074: *
075: * <tr>
076: * <td>{@link OptionGroups#someOf}</td>
077: * <td>1</td>
078: * <td>n</td>
079: * </tr>
080: *
081: * <tr>
082: * <td>{@link OptionGroups#anyOf}</td>
083: * <td>0</td>
084: * <td>n</td>
085: * </tr>
086: * </table>
087: *
088: * <p>
089: * Please note that the {@link OptionGroups#anyOf} is in fact always consistent,
090: * regardless any number of the given options appears on the command line or not.
091: * As such it serves slightly different purpose than the other methods listed
092: * in the table.
093: * <p>
094: * More detailed description of the behaviour of each method is given in
095: * their appropriate javadoc.
096: *
097: * @author Jaroslav Tulach
098: */
099: public final class OptionGroups {
100: private OptionGroups() {
101: }
102:
103: /** Combines a set of multiple options into one compound one. Useful
104: * for {@link OptionProcessor} that want to process more than one
105: * option and want to do all the logic of choosing which options can
106: * be used together with others by themselves. The newly created
107: * options will be contained in the map passed to
108: * {@link OptionProcessor#process} method if at least one of the
109: * parameters appeared on the command line. The value associated with
110: * the compound option is always going to be <code>new String[0]</code>, however
111: * the map will contain all options that appeared and their values which
112: * can then be processed one by one.
113: *
114: * @param options the sub options to check on the command line
115: * @return compound option that <q>is activated</q> if at least one of the
116: * options appears on the command line
117: */
118: public static Option someOf(Option... options) {
119: return new Option(2, options);
120: }
121:
122: /** A voluntary selector that allows any of the specified options to appear
123: * on the command line, but if they do not appear, the command line is
124: * still consistent. If at least one of the given sub options appears on
125: * the command line, the map passed to
126: * {@link OptionProcessor#process} will contain the returned compound option
127: * with associated value of <code>new String[0]</code>.
128: *
129: * @param options the sub options to check on the command line
130: * @return compound option that <q>is activated</q> if at least one of the
131: * options appears on the command line
132: */
133: public static Option anyOf(Option... options) {
134: return new Option(3, options);
135: }
136:
137: /** Creates a selector option that forces exactly one of the sub options
138: * to appear on the command line. If more than
139: * one of the options appears on the command line, then an error is
140: * reported by the infrastructure. If none of the sub options is present
141: * than this selector option is not also present.
142: * If present in the {@link OptionProcessor#process}'s
143: * map, then the selector option is always associated with <code>new String[0]</code>
144: * value, however there is also one of the sub options, with its associated
145: * value.
146: *
147: * @param options the options to select one from
148: * @return the selector option
149: */
150: public static Option oneOf(Option... options) {
151: return new Option(0, options);
152: }
153:
154: /** Creates a compound option that forces all of the sub options
155: * to appear on the command line. If less of them is present, an error
156: * is reported by the infrastructure.
157: * If present in the {@link OptionProcessor#process}'s
158: * map, then the compound option is always associated with <code>new String[0]</code>
159: * value, however there are all the sub options, with their associated
160: * values.
161: *
162: * @param options the options to select one from
163: * @return the selector option
164: */
165: public static Option allOf(Option... options) {
166: return new Option(1, options);
167: }
168: }
|