/** * Returns the url for logging. */ public static String getUrl(Resource r) { if(null == r) { return null; } return getUrl(r.getURLString()); }
protected void putProperty(AppPropertyContext context, Resource resource, String key, String value, boolean override) { if(!override && context.hasProperty(key)) { AppProperty prop = context.getProperty(key); if(null != prop) { if(prop.isOverride()) { log.debug("Skip {} at {}, a override one already exists", key, LogUtils.getUrl(resource)); return; } throw new AppConfigException("Found duplicate property '" + key + "' in resources : [" + prop.getSource() + "]" + ", " + LogUtils.getUrl(resource)); }else { throw new AppConfigException("Found duplicate property '" + key + "' in '" + LogUtils.getUrl(resource) + "', the array property with same name already exists!"); } } context.putProperty(resource, key, value, override); }
public void load(AppResource[] resources) { Args.notNull(resources, "resources"); for (AppResource ar : resources) { Resource resource = ar.getResource(); if (log.isDebugEnabled()) { if (AppResources.isFrameworkAndCoreResource(resource.getURLString())) { log.trace("Load beans : {}", LogUtils.getUrl(resource)); } else { log.debug("Load beans : {}", LogUtils.getUrl(resource)); } } //todo : use AppResource's default override? readDefinitions(container, resource, ar.isDefaultOverride()); } }
protected void loadProperties(ConfigContext context, AppResource... resources) { for(AppResource ar : resources){ try{ Resource resource = ar.getResource(); String resourceUrl = resource.getURL().toString(); if(log.isDebugEnabled()){ if(AppResources.isFrameworkAndCoreResource(resourceUrl)) { log.trace("Load properties : {}", LogUtils.getUrl(resource)); }else{ log.debug("Load properties : {}", LogUtils.getUrl(resource)); } } if(context.resources.contains(resourceUrl)){ throw new AppConfigException("Cycle importing detected of '" + resourceUrl + "', please check your config : " + resourceUrl); } context.resources.add(resourceUrl); context.setDefaultOverride(ar.isDefaultOverride()); for(AppPropertyReader reader : propertyReaders) { if(reader.readProperties(context, resource)) { break; } } context.resetDefaultOverride(); }catch(IOException e) { throw new AppConfigException("I/O Exception",e); } } }
private void loadConfig(ConfigContext context, AppResource... resources){ for(AppResource ar : resources){ try{ Resource resource = ar.getResource(); String resourceUrl = resource.getURL().toString(); if(log.isDebugEnabled()){ if(AppResources.isFrameworkAndCoreResource(resourceUrl)) { log.trace("Load config : {}", LogUtils.getUrl(resource)); }else{ log.debug("Load config : {}", LogUtils.getUrl(resource)); } } if(context.resources.contains(resourceUrl)){ throw new AppConfigException("Cycle importing detected of '" + resourceUrl + "', please check your config : " + resourceUrl); } context.resources.add(resourceUrl); context.setDefaultOverride(ar.isDefaultOverride()); for(AppConfigReader reader : configReaders) { if(reader.readConfig(context, resource)) { break; } } context.resetDefaultOverride(); }catch(IOException e) { throw new AppConfigException("I/O Exception",e); } } }
protected PrintProperty toPrintProperty(AppProperty p) { PrintProperty pp = new PrintProperty(); String value = protectSecret(p.getName(), p.getUnprocessedValue()); pp.name = p.getName(); pp.value = Strings.abbreviateMiddle(value, "...", 50); pp.value = Strings.replace(pp.value, "\r", "\\r"); pp.value = Strings.replace(pp.value, "\n", "\\n"); if(null == p.getSource()) { pp.source = "(n/a)"; }else if(p.getSource() instanceof Resource) { pp.source = LogUtils.getUrl((Resource)p.getSource()); }else if(p.getSource() instanceof Class) { pp.source = ((Class) p.getSource()).getSimpleName(); }else if(p.getSource() instanceof String) { pp.source = (String)p.getSource(); }else { pp.source = p.getSource().getClass().getSimpleName(); } pp.source = Strings.abbreviatePrefix(pp.source, 10, 80, "..."); pp.system = p.isSystem(); return pp; }