modules/fxpackager/src/main/java/com/oracle/bundlers/BundlerParamInfo.java

Print this page




   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 com.oracle.bundlers;
  27 
  28 import java.util.Map;

  29 import java.util.function.Function;
  30 
  31 public class BundlerParamInfo<T> {
  32 
  33     /**
  34      * The user friendly name of the parameter
  35      */
  36     String name;
  37 
  38     /**
  39      * A more verbose description of the parameter
  40      */
  41     String description;
  42 
  43     /**
  44      * The command line and hashmap name of the parameter
  45      */
  46     String id;
  47 
  48     /**


  52 
  53     /**
  54      * If the parameter is not set, what parameter the bundler will fall back on to use
  55      */
  56     String[] fallbackIDs;
  57 
  58     /**
  59      * If the value is not set, and no fallback value is found, the parameter uses the value returned by the producer.
  60      */
  61     Function<Map<String, ? super Object>, T> defaultValueFunction;
  62 
  63     /**
  64      * Does the parameter require the user or tool to set a value?  i.e. if the parameter is
  65      * not set will it cause the bundler to fail?
  66      */
  67     boolean requiresUserSetting;
  68 
  69     /**
  70      * An optional string converter for command line arguments.
  71      */
  72     Function<String, T> stringConverter;

  73 
  74     public String getName() {
  75         return name;
  76     }
  77 
  78     public void setName(String name) {
  79         this.name = name;
  80     }
  81 
  82     public String getDescription() {
  83         return description;
  84     }
  85 
  86     public void setDescription(String description) {
  87         this.description = description;
  88     }
  89 
  90     public String getID() {
  91         return id;
  92     }


 110     public void setFallbackIDs(String[] fallbackID) {
 111         this.fallbackIDs = fallbackID;
 112     }
 113 
 114     public Function<Map<String, ? super Object>, T> getDefaultValueFunction() {
 115         return defaultValueFunction;
 116     }
 117 
 118     public void setDefaultValueFunction(Function<Map<String, ? super Object>, T> defaultValueFunction) {
 119         this.defaultValueFunction = defaultValueFunction;
 120     }
 121 
 122     public boolean isRequiresUserSetting() {
 123         return requiresUserSetting;
 124     }
 125 
 126     public void setRequiresUserSetting(boolean requiresUserSetting) {
 127         this.requiresUserSetting = requiresUserSetting;
 128     }
 129 
 130     public Function<String, T> getStringConverter() {

 131         return stringConverter;
 132     }
 133 
 134     public void setStringConverter(Function<String, T> stringConverter) {

 135         this.stringConverter = stringConverter;
 136     }
 137 
 138     @SuppressWarnings("unchecked")
 139     public final T fetchFrom(Map<String, ? super Object> params) {
 140         Object o = params.get(getID());
 141         if (o instanceof String && getStringConverter() != null) {
 142             return getStringConverter().apply((String)o);

 143         }
 144 
 145         Class klass = getValueType();
 146         if (klass.isInstance(o)) {
 147             return (T) o;
 148         }
 149         if (o != null) {
 150             throw new IllegalArgumentException("Param " + getID() + " should be of type " + getValueType() + " but is a " + o.getClass());
 151         }
 152         if (params.containsKey(getID())) {
 153             // explicit nulls are allowed
 154             return null;
 155         }
 156 
 157         if (getFallbackIDs() != null) {
 158             for (String fallback: getFallbackIDs()) {
 159                 o = params.get(fallback);
 160                 if (klass.isInstance(o)) {
 161                     return (T) o;
 162                 }


   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 com.oracle.bundlers;
  27 
  28 import java.util.Map;
  29 import java.util.function.BiFunction;

  30 import java.util.function.Function;
  31 
  32 public class BundlerParamInfo<T> {
  33 
  34     /**
  35      * The user friendly name of the parameter
  36      */
  37     String name;
  38 
  39     /**
  40      * A more verbose description of the parameter
  41      */
  42     String description;
  43 
  44     /**
  45      * The command line and hashmap name of the parameter
  46      */
  47     String id;
  48 
  49     /**


  53 
  54     /**
  55      * If the parameter is not set, what parameter the bundler will fall back on to use
  56      */
  57     String[] fallbackIDs;
  58 
  59     /**
  60      * If the value is not set, and no fallback value is found, the parameter uses the value returned by the producer.
  61      */
  62     Function<Map<String, ? super Object>, T> defaultValueFunction;
  63 
  64     /**
  65      * Does the parameter require the user or tool to set a value?  i.e. if the parameter is
  66      * not set will it cause the bundler to fail?
  67      */
  68     boolean requiresUserSetting;
  69 
  70     /**
  71      * An optional string converter for command line arguments.
  72      */
  73     BiFunction<String, Map<String, ? super Object>, T> stringConverter;

  74 
  75     public String getName() {
  76         return name;
  77     }
  78 
  79     public void setName(String name) {
  80         this.name = name;
  81     }
  82 
  83     public String getDescription() {
  84         return description;
  85     }
  86 
  87     public void setDescription(String description) {
  88         this.description = description;
  89     }
  90 
  91     public String getID() {
  92         return id;
  93     }


 111     public void setFallbackIDs(String[] fallbackID) {
 112         this.fallbackIDs = fallbackID;
 113     }
 114 
 115     public Function<Map<String, ? super Object>, T> getDefaultValueFunction() {
 116         return defaultValueFunction;
 117     }
 118 
 119     public void setDefaultValueFunction(Function<Map<String, ? super Object>, T> defaultValueFunction) {
 120         this.defaultValueFunction = defaultValueFunction;
 121     }
 122 
 123     public boolean isRequiresUserSetting() {
 124         return requiresUserSetting;
 125     }
 126 
 127     public void setRequiresUserSetting(boolean requiresUserSetting) {
 128         this.requiresUserSetting = requiresUserSetting;
 129     }
 130 
 131     public BiFunction<String, Map<String, ? super Object>,T> getStringConverter() {

 132         return stringConverter;
 133     }
 134 
 135     public void setStringConverter(BiFunction<String, Map<String, ? super Object>, T> stringConverter) {

 136         this.stringConverter = stringConverter;
 137     }
 138 
 139     @SuppressWarnings("unchecked")
 140     public final T fetchFrom(Map<String, ? super Object> params) {
 141         Object o = params.get(getID());
 142         if (o instanceof String && getStringConverter() != null) {
 143             return getStringConverter().apply((String)o, params);

 144         }
 145 
 146         Class klass = getValueType();
 147         if (klass.isInstance(o)) {
 148             return (T) o;
 149         }
 150         if (o != null) {
 151             throw new IllegalArgumentException("Param " + getID() + " should be of type " + getValueType() + " but is a " + o.getClass());
 152         }
 153         if (params.containsKey(getID())) {
 154             // explicit nulls are allowed
 155             return null;
 156         }
 157 
 158         if (getFallbackIDs() != null) {
 159             for (String fallback: getFallbackIDs()) {
 160                 o = params.get(fallback);
 161                 if (klass.isInstance(o)) {
 162                     return (T) o;
 163                 }