src/jdk/nashorn/internal/runtime/options/Options.java

Print this page




 482         }
 483     }
 484 
 485     private static OptionTemplate getOptionTemplate(final String key) {
 486         for (final OptionTemplate t : Options.validOptions) {
 487             if (t.matches(key)) {
 488                 return t;
 489             }
 490         }
 491         return null;
 492     }
 493 
 494     private static Option<?> createOption(final OptionTemplate t, final String value) {
 495         switch (t.getType()) {
 496         case "string":
 497             // default value null
 498             return new Option<>(value);
 499         case "timezone":
 500             // default value "TimeZone.getDefault()"
 501             return new Option<>(TimeZone.getTimeZone(value));


 502         case "keyvalues":
 503             return new KeyValueOption(value);
 504         case "log":
 505             final KeyValueOption kv = new KeyValueOption(value);
 506             Logging.initialize(kv.getValues());
 507             return kv;
 508         case "boolean":
 509             return new Option<>(value != null && Boolean.parseBoolean(value));
 510         case "integer":
 511             try {
 512                 return new Option<>((value == null) ? 0 : Integer.parseInt(value));
 513             } catch (final NumberFormatException nfe) {
 514                 throw new IllegalOptionException(t);
 515             }
 516         case "properties":
 517             //swallow the properties and set them
 518             initProps(new KeyValueOption(value));
 519             return null;
 520         default:
 521             break;




 482         }
 483     }
 484 
 485     private static OptionTemplate getOptionTemplate(final String key) {
 486         for (final OptionTemplate t : Options.validOptions) {
 487             if (t.matches(key)) {
 488                 return t;
 489             }
 490         }
 491         return null;
 492     }
 493 
 494     private static Option<?> createOption(final OptionTemplate t, final String value) {
 495         switch (t.getType()) {
 496         case "string":
 497             // default value null
 498             return new Option<>(value);
 499         case "timezone":
 500             // default value "TimeZone.getDefault()"
 501             return new Option<>(TimeZone.getTimeZone(value));
 502         case "locale":
 503             return new Option<>(Locale.forLanguageTag(value));
 504         case "keyvalues":
 505             return new KeyValueOption(value);
 506         case "log":
 507             final KeyValueOption kv = new KeyValueOption(value);
 508             Logging.initialize(kv.getValues());
 509             return kv;
 510         case "boolean":
 511             return new Option<>(value != null && Boolean.parseBoolean(value));
 512         case "integer":
 513             try {
 514                 return new Option<>((value == null) ? 0 : Integer.parseInt(value));
 515             } catch (final NumberFormatException nfe) {
 516                 throw new IllegalOptionException(t);
 517             }
 518         case "properties":
 519             //swallow the properties and set them
 520             initProps(new KeyValueOption(value));
 521             return null;
 522         default:
 523             break;