/** * Returns the property value as {@link Long} type. */ default long getLongProperty(String name, long defaultValue) { return getProperty(name, Long.class, defaultValue); }
public static Map<String, Object> extractMap(AppConfig config) { Map<String, Object> map = new LinkedHashMap<>(); config.getPropertyNames().forEach(key -> { String value = config.getProperty(key); extractMap(map, key, value); }); return map; }
/** * Returns the property value as {@link Boolean} type. */ default boolean getBooleanProperty(String name,boolean defaultValue) { return getProperty(name, Boolean.class, defaultValue); }
public static Map<String, Object> extractMap(AppConfig config) { Map<String, Object> map = new LinkedHashMap<>(); config.getPropertyNames().forEach(key -> { String value = config.getProperty(key); extractMap(map, key, value); }); return map; }
/** * Returns the property value as {@link Integer} type. */ default int getIntProperty(String name,int defaultValue) { return getProperty(name, Integer.class, defaultValue); }
public static Map<String, Object> extractMap(AppConfig config, Map<String, String> extraConfig, String prefix) { Map<String, String> props = new LinkedHashMap<>(); final String keyPrefix = prefix.endsWith(".") ? prefix : prefix + "."; config.getPropertyNames().forEach(key -> { if(key.startsWith(keyPrefix)) { props.put(key.substring(keyPrefix.length()), config.getProperty(key)); } }); if(null != extraConfig) { extraConfig.forEach((key, value) -> { if (key.startsWith(keyPrefix)) { props.put(key.substring(keyPrefix.length()), value); } }); } Map<String, Object> map = new LinkedHashMap<>(); props.forEach((k, v) -> { extractMap(map, k, v); }); return map; }
/** * Returns the property value as {@link Double} type. */ default double getDoubleProperty(String name, double defaultValue) { return getProperty(name, Double.class, defaultValue); }
public static Map<String, Object> extractMap(AppConfig config, Map<String, String> extraConfig, String prefix) { Map<String, String> props = new LinkedHashMap<>(); final String keyPrefix = prefix.endsWith(".") ? prefix : prefix + "."; config.getPropertyNames().forEach(key -> { if(key.startsWith(keyPrefix)) { props.put(key.substring(keyPrefix.length()), config.getProperty(key)); } }); if(null != extraConfig) { extraConfig.forEach((key, value) -> { if (key.startsWith(keyPrefix)) { props.put(key.substring(keyPrefix.length()), value); } }); } Map<String, Object> map = new LinkedHashMap<>(); props.forEach((k, v) -> { extractMap(map, k, v); }); return map; }
@Override public Object getProperty(String name) { if(null != Global.config()) { if(LeapConfigSupport.skip.get() != null) { return null; } try { LeapConfigSupport.skip.set(Boolean.TRUE); return Global.config().getProperty(name); }finally{ LeapConfigSupport.skip.remove(); } } return null; } }
protected boolean initHomeDirectoryFromConfig() throws Throwable { String homeDirectory = config.getProperty(AppConfig.PROPERTY_HOME); if(!Strings.isEmpty(homeDirectory)){ dir = Resources.createFileResource(homeDirectory); return true; }else { return false; } }
protected Object resolveConfigProperty(String key, Class<?> type, Type genericType) { String prop = appContext.getConfig().getProperty(key); if(null != prop){ if(!Strings.isEmpty(prop = prop.trim())) { try { return Converts.convert(prop, type, genericType); } catch (Exception e) { throw new BeanCreationException("Error resolve property for type '" + type + "' using config key '" + key + "', " + e.getMessage(), e); } } } return null; }
private boolean isPluginEnabled(Plugin plugin, String prefix) { String enabled = config.getProperty(prefix + ".enabled"); if(Strings.isEmpty(enabled)) { return plugin.isDefaultEnabled(); }else { return Converts.toBoolean(enabled); } } }
void load(AppConfig config) { this.config = config; this.basePackage = config.getBasePackage() + "."; Boolean redefineProp = config.getProperty("instrument.redefine", Boolean.class); if(null == redefineProp) { redefine = testing; }else{ redefine = redefineProp; } instrumentation.init(config); loadAllClasses(); }
public Features init(Map<String, String> props) { String p = props.get(KEY_PREFIX); if(Strings.isEmpty(p)) { p = config.getProperty(KEY_PREFIX); } if(!Strings.isEmpty(p)) { Collections2.addAll(enables, Strings.split(p, ",")); } for(Feature feature : beans) { String name = feature.checkEnabled(); if(!Strings.isEmpty(name)) { enables.add(name); } } Map<String, Object> map = ConfigUtils.extractMap(config, props, KEY_PREFIX); if(!map.isEmpty()) { map.forEach((k,v) -> { if(Converts.toBoolean(v)) { enables.add(k); }else { enables.remove(k); } }); } return this; }
public void configure() { if(!endpoints.isEmpty()) { endpoints.forEach(r -> app.routes().remove(r)); } Map<String, Object> map = ConfigUtils.extractMap(app.config(), CONF_PREFIX); if(null == map || map.isEmpty()) { return; } config = Converts.convert(map, OAuth2ServerConfig.class); if(!config.isEnabled()) { return; } //clients config.getClients().forEach((id, c) -> { c.setId(id); validator.validate(CONF_PREFIX + ".clients." + id, c); }); //url int port = app.config().getIntProperty("server.port", 8080); String contextPath = app.config().getProperty("server.context-path", ""); this.url = (config.isSsl() ? "https:" : "http") + "://localhost:" + port + contextPath; //gen key pair if(null == keyPair) { keyPair = RSA.generateKeyPair(); signer = new RsaSigner(keyPair.getPrivateKey()); verifier = new RsaVerifier(keyPair.getPublicKey()); } //create endpoint createEndpoints(app.routes()); }
String prop = config.getProperty(key);
if(not == Converts.toBoolean(config.getProperty(property))){ return not;
if(null != property && !property.test(Converts.toBoolean(config.getProperty(property.value)))) { return false;