KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > codegen > OptionSet


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  *
22  */

23 package org.enhydra.tool.codegen;
24
25 // Toolbox imports
26
import org.enhydra.tool.common.ResUtil;
27
28 // Standard imports
29
import java.util.ArrayList JavaDoc;
30 import java.util.Arrays JavaDoc;
31 import java.util.ResourceBundle JavaDoc;
32
33 /**
34  * An OptionSet is a utility class for working with GeneratorOptions
35  */

36 public class OptionSet {
37     public static ResourceBundle JavaDoc res = ResourceBundle.getBundle("org.enhydra.tool.codegen.Res"); // nores
38
//
39
private GeneratorOption[] options = new GeneratorOption[0];
40
41     /**
42      * Create an empty option set.
43      */

44     public OptionSet() {}
45
46     /**
47      * Get the generator option that has the specified option name.
48      *
49      * @returns
50      * A GeneratorOption that has the specified name.
51      *
52      * @throws GeneratorException
53      * Thrown if the no GeneratorOption exists in the current set with
54      * the specified name.
55      *
56      */

57     public GeneratorOption lookup(String JavaDoc name) throws GeneratorException {
58         GeneratorOption option = null;
59
60         for (int i = 0; i < options.length; i++) {
61             if (options[i].getName().equalsIgnoreCase(name)) {
62                 option = options[i];
63                 break;
64             }
65         }
66         if (option == null) {
67             throw new GeneratorException(
68               ResUtil.format(res.getString("Unable_to_lookup"), name));
69         }
70         return option;
71     }
72
73     /**
74      * Remove the generator option that has the specified option name.
75      *
76      * @throws GeneratorException
77      * Thrown if the no GeneratorOption exists in the current set with
78      * the specified name.
79      */

80     public void delete(String JavaDoc name) throws GeneratorException {
81         throw new GeneratorException("OptionSet:delete() not implemented"); // nores
82
}
83
84     /**
85      * Add a new generator option.
86      *
87      * @throws GeneratorException
88      * Thrown if the no GeneratorOption exists in the current set with
89      * the specified name.
90      *
91      */

92     public void add(GeneratorOption newOp) throws GeneratorException {
93         ArrayList JavaDoc list = null;
94         list = new ArrayList JavaDoc(Arrays.asList(options));
95         list.add(newOp);
96         list.trimToSize();
97         options = new GeneratorOption[list.size()];
98         options = (GeneratorOption[]) list.toArray(options);
99     }
100
101     /**
102      * Convert the option set into an array of individual
103      * GeneratorOption objects.
104      *
105      * @return
106      * The options as an GeneratorOption array.
107      */

108     public GeneratorOption[] toArray() {
109         return options;
110     }
111
112 }
113
Popular Tags