/** @deprecated attempts to call get with this syntax are probably mistakes; get(key, defaultValue) is fine but * Map is unlikely the key, much more likely they meant getFirst(flags, key). */ @Deprecated public String get(Map flags, String key) { LOG.warn("Discouraged use of 'BrooklynProperties.get(Map,String)' (ambiguous); use getFirst(Map,String) or get(String) -- assuming the former"); LOG.debug("Trace for discouraged use of 'BrooklynProperties.get(Map,String)'", new Throwable("Arguments: "+flags+" "+key)); return getFirst(flags, key); }
/** returns the value of the first key which is defined * <p> * takes the following flags: * 'warnIfNone', 'failIfNone' (both taking a boolean (to use default message) or a string (which is the message)); * and 'defaultIfNone' (a default value to return if there is no such property); defaults to no warning and null response */ @Override public String getFirst(String ...keys) { return getFirst(MutableMap.of(), keys); } @Override
private static BrooklynStorageFactory loadBrooklynStorageFactory(BrooklynProperties properties){ String clazzName = properties.getFirst(BrooklynStorageFactory.class.getName()); if(clazzName == null){ clazzName = InMemoryBrooklynStorageFactory.class.getName(); } Class<?> clazz; try{ //todo: which classloader should we use? clazz = LocalManagementContext.class.getClassLoader().loadClass(clazzName); }catch(ClassNotFoundException e){ throw new IllegalStateException(format("Could not load class [%s]",clazzName),e); } Object instance; try { instance = clazz.newInstance(); } catch (InstantiationException e) { throw new IllegalStateException(format("Could not instantiate class [%s]",clazzName),e); } catch (IllegalAccessException e) { throw new IllegalStateException(format("Could not instantiate class [%s]",clazzName),e); } if(!(instance instanceof BrooklynStorageFactory)){ throw new IllegalStateException(format("Class [%s] not an instantiate of class [%s]",clazzName, BrooklynStorageFactory .class.getName())); } return (BrooklynStorageFactory)instance; }