/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps, true); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
/** * Constructor. * * @param ps * The property store containing all the settings for this object. * @throws IOException */ public Config(PropertyStore ps) throws IOException { super(ps, true); name = getStringProperty(CONFIG_name, "Configuration.cfg"); store = getInstanceProperty(CONFIG_store, ConfigStore.class, ConfigFileStore.DEFAULT); configMap = store.getMap(name); configMap.register(this); serializer = getInstanceProperty(CONFIG_serializer, WriterSerializer.class, SimpleJsonSerializer.DEFAULT); parser = getInstanceProperty(CONFIG_parser, ReaderParser.class, JsonParser.DEFAULT); beanSession = parser.createBeanSession(); encoder = getInstanceProperty(CONFIG_encoder, ConfigEncoder.class, ConfigXorEncoder.INSTANCE); varSession = getInstanceProperty(CONFIG_varResolver, VarResolver.class, VarResolver.DEFAULT) .builder() .vars(ConfigVar.class) .contextObject(ConfigVar.SESSION_config, this) .build() .createSession(); binaryLineLength = getIntegerProperty(CONFIG_binaryLineLength, -1); binaryFormat = getProperty(CONFIG_binaryFormat, BinaryFormat.class, BinaryFormat.BASE64); multiLineValuesOnSeparateLines = getBooleanProperty(CONFIG_multiLineValuesOnSeparateLines, false); readOnly = getBooleanProperty(CONFIG_readOnly, false); }
@Test public void testResolvingWithOverride() throws Exception { Config cf = init(); cf.set("a", "$A{X}"); cf.set("b", "$B{X}"); cf.set("c", "$A{$B{X}}"); cf.set("d", "$B{$A{X}}"); cf.set("e", "$D{X}"); VarResolver vr = new VarResolverBuilder().defaultVars().vars(ALVar.class, BLVar.class).build(); cf = cf.resolving(vr.createSession()); assertEquals("aXa", cf.getString("a")); assertEquals("bXb", cf.getString("b")); assertEquals("abXba", cf.getString("c")); assertEquals("baXab", cf.getString("d")); assertEquals("$D{X}", cf.getString("e")); // Create new resolver that addx $C and overrides $A VarResolver vr2 = vr.builder().vars(AUVar.class, DUVar.class).build(); // true == augment by adding existing as parent to the new resolver cf = cf.resolving(vr2.createSession()); assertEquals("AXA", cf.getString("a")); assertEquals("bXb", cf.getString("b")); assertEquals("AbXbA", cf.getString("c")); assertEquals("bAXAb", cf.getString("d")); assertEquals("DXD", cf.getString("e")); }