6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.jpackage.internal;
27
28 import java.util.Map;
29 import java.util.function.BiFunction;
30 import java.util.function.Function;
31
32 /**
33 * BundlerParamInfo<T>
34 *
35 * A BundlerParamInfo encapsulates an individual bundler parameter of type <T>.
36 */
37 class BundlerParamInfo<T> {
38
39 /**
40 * The command line and hashmap name of the parameter
41 */
42 String id;
43
44 /**
45 * Type of the parameter
46 */
53
54 /**
55 * If the value is not set, and no fallback value is found,
56 * the parameter uses the value returned by the producer.
57 */
58 Function<Map<String, ? super Object>, T> defaultValueFunction;
59
60 /**
61 * An optional string converter for command line arguments.
62 */
63 BiFunction<String, Map<String, ? super Object>, T> stringConverter;
64
65 String getID() {
66 return id;
67 }
68
69 Class<T> getValueType() {
70 return valueType;
71 }
72
73 void setValueType(Class<T> valueType) {
74 this.valueType = valueType;
75 }
76
77 boolean getIsDefaultValue() {
78 return isDefaultValue;
79 }
80
81 Function<Map<String, ? super Object>, T> getDefaultValueFunction() {
82 return defaultValueFunction;
83 }
84
85 void setDefaultValueFunction(
86 Function<Map<String, ? super Object>, T> defaultValueFunction) {
87 this.defaultValueFunction = defaultValueFunction;
88 }
89
90 BiFunction<String, Map<String, ? super Object>,T>
91 getStringConverter() {
92 return stringConverter;
93 }
94
95 void setStringConverter(BiFunction<String,
96 Map<String, ? super Object>, T> stringConverter) {
97 this.stringConverter = stringConverter;
98 }
99
100 @SuppressWarnings("unchecked")
101 final T fetchFrom(Map<String, ? super Object> params) {
102 return fetchFrom(params, true);
103 }
104
105 @SuppressWarnings("unchecked")
106 final T fetchFrom(Map<String, ? super Object> params,
107 boolean invokeDefault) {
108 Object o = params.get(getID());
109 if (o instanceof String && getStringConverter() != null) {
110 return getStringConverter().apply((String)o, params);
111 }
112
113 Class<T> klass = getValueType();
114 if (klass.isInstance(o)) {
115 return (T) o;
116 }
117 if (o != null) {
|
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
23 * questions.
24 */
25
26 package jdk.incubator.jpackage.internal;
27
28 import java.util.Map;
29 import java.util.function.BiFunction;
30 import java.util.function.Function;
31
32 /**
33 * BundlerParamInfo<T>
34 *
35 * A BundlerParamInfo encapsulates an individual bundler parameter of type <T>.
36 */
37 class BundlerParamInfo<T> {
38
39 /**
40 * The command line and hashmap name of the parameter
41 */
42 String id;
43
44 /**
45 * Type of the parameter
46 */
53
54 /**
55 * If the value is not set, and no fallback value is found,
56 * the parameter uses the value returned by the producer.
57 */
58 Function<Map<String, ? super Object>, T> defaultValueFunction;
59
60 /**
61 * An optional string converter for command line arguments.
62 */
63 BiFunction<String, Map<String, ? super Object>, T> stringConverter;
64
65 String getID() {
66 return id;
67 }
68
69 Class<T> getValueType() {
70 return valueType;
71 }
72
73 boolean getIsDefaultValue() {
74 return isDefaultValue;
75 }
76
77 Function<Map<String, ? super Object>, T> getDefaultValueFunction() {
78 return defaultValueFunction;
79 }
80
81 BiFunction<String, Map<String, ? super Object>,T>
82 getStringConverter() {
83 return stringConverter;
84 }
85
86 @SuppressWarnings("unchecked")
87 final T fetchFrom(Map<String, ? super Object> params) {
88 return fetchFrom(params, true);
89 }
90
91 @SuppressWarnings("unchecked")
92 final T fetchFrom(Map<String, ? super Object> params,
93 boolean invokeDefault) {
94 Object o = params.get(getID());
95 if (o instanceof String && getStringConverter() != null) {
96 return getStringConverter().apply((String)o, params);
97 }
98
99 Class<T> klass = getValueType();
100 if (klass.isInstance(o)) {
101 return (T) o;
102 }
103 if (o != null) {
|