private boolean isArgDefined(String argName) { return !this.root.getNode(NODE_ARGS, argName).isVirtual(); } }
private boolean isArgDefined(String argName) { return !this.root.getNode(NODE_ARGS, argName).isVirtual(); } }
@Override public CompletableFuture<Boolean> hasRankLadder(String ladder) { return completedFuture(!getRankLaddersNode().getNode(ladder.toLowerCase()).isVirtual()); }
@Override public CompletableFuture<Boolean> isRegistered(String type, String identifier) { return completedFuture(!getSubjectsNode().getNode(type, identifier).isVirtual()); }
private T getValueInternal(ConfigurationNode configurationNode) { ConfigurationNode node = configurationNode.getNode(key); if(node.isVirtual()) { this.modified = true; } if(comment != null && node instanceof CommentedConfigurationNode) { ((CommentedConfigurationNode)node).setComment(comment); } try { if(typeToken != null) return node.getValue(typeToken, defaultValue); else return node.getValue(new TypeToken<T>(defaultValue.getClass()){}, defaultValue); } catch(Exception e) { return defaultValue; } }
public void deserializeFrom(Object instance, ConfigurationNode node) throws ObjectMappingException { TypeSerializer<?> serial = node.getOptions().getSerializers().get(this.fieldType); if (serial == null) { throw new ObjectMappingException("No TypeSerializer found for field " + field.getName() + " of type " + this.fieldType); } Object newVal = node.isVirtual() ? null : serial.deserialize(this.fieldType, node); try { if (newVal == null) { Object existingVal = field.get(instance); if (existingVal != null) { serializeTo(instance, node); } } else { field.set(instance, newVal); } } catch (IllegalAccessException e) { throw new ObjectMappingException("Unable to deserialize field " + field.getName(), e); } }
public void deserializeFrom(Object instance, ConfigurationNode node) throws ObjectMappingException { TypeSerializer<?> serial = node.getOptions().getSerializers().get(this.fieldType); if (serial == null) { throw new ObjectMappingException("No TypeSerializer found for field " + field.getName() + " of type " + this.fieldType); } Object newVal = node.isVirtual() ? null : serial.deserialize(this.fieldType, node); try { if (newVal == null) { Object existingVal = field.get(instance); if (existingVal != null) { serializeTo(instance, node); } } else { field.set(instance, newVal); } } catch (IllegalAccessException e) { throw new ObjectMappingException("Unable to deserialize field " + field.getName(), e); } }
public void deserializeFrom(Object instance, ConfigurationNode node) throws ObjectMappingException { TypeSerializer<?> serial = node.getOptions().getSerializers().get(this.fieldType); if (serial == null) { throw new ObjectMappingException("No TypeSerializer found for field " + field.getName() + " of type " + this.fieldType); } Object newVal = node.isVirtual() ? null : serial.deserialize(this.fieldType, node); try { if (newVal == null) { Object existingVal = field.get(instance); if (existingVal != null) { serializeTo(instance, node); } } else { field.set(instance, newVal); } } catch (IllegalAccessException e) { throw new ObjectMappingException("Unable to deserialize field " + field.getName(), e); } }
} else { node = node.getNode(path[i]); if (node.isVirtual()) { return;
} else { node = node.getNode(path[i]); if (node.isVirtual()) { return;
.addAction(new Object[]{"subjects", "group", WILDCARD_OBJECT}, (nodePath, configurationNode) -> { for (ConfigurationNode child : configurationNode.getChildrenList()) { if (child.getNode(FileSubjectData.KEY_CONTEXTS).isVirtual() || child.getNode(FileSubjectData.KEY_CONTEXTS).getChildrenMap().isEmpty()) { ConfigurationNode optionsNode = child.getNode("options"); if (optionsNode.isVirtual()) { return null; if (!rank.isVirtual()) { final String rankLadder = optionsNode.getNode("rank-ladder").getString("default"); List<Map.Entry<String, Integer>> tempVals = convertedRanks.get(rankLadder.toLowerCase());
} else { node = node.getNode(path[i]); if (node.isVirtual()) { return;
public static FilePermissionsExConfiguration fromLoader(ConfigurationLoader<?> loader) throws IOException { ConfigurationNode node = loader.load(); ConfigurationNode fallbackConfig; try { fallbackConfig = FilePermissionsExConfiguration.loadDefaultConfiguration(); } catch (IOException e) { throw new Error("PEX's default configuration could not be loaded!", e); } ConfigTransformations.versions().apply(node); node.mergeValuesFrom(fallbackConfig); ConfigurationNode defBackendNode = node.getNode("default-backend"); if (defBackendNode.isVirtual() || defBackendNode.getValue() == null) { // Set based on whether or not the H2 backend is available defBackendNode.setValue("default-file"); /*try { Class.forName("org.h2.Driver"); defBackendNode.setValue("default"); } catch (ClassNotFoundException e) { defBackendNode.setValue("default-file"); }*/ } FilePermissionsExConfiguration config = new FilePermissionsExConfiguration(loader, node); config.load(); return config; }
@Test public void testSettingNullRemoves() { ConfigurationNode root = SimpleConfigurationNode.root(); ConfigurationNode child = root.getNode("child").setValue("a"); assertFalse(child.isVirtual()); assertSame(child, root.getNode("child")); child.setValue(null); assertTrue(child.isVirtual()); assertNotSame(child, root.getNode("child")); }
@Test public void testNodeCreation() { ConfigurationNode config = SimpleConfigurationNode.root(); ConfigurationNode uncreatedNode = config.getNode("uncreated", "node"); assertTrue(uncreatedNode.isVirtual()); // Just in case uncreatedNode.setValue("test string for cool people"); assertFalse(uncreatedNode.isVirtual()); assertEquals("test string for cool people", uncreatedNode.getValue()); ConfigurationNode fetchedAfterCreation = config.getNode("uncreated", "node"); assertEquals(uncreatedNode, fetchedAfterCreation); assertEquals(uncreatedNode, config.getNode("uncreated").getNode("node")); }
@Test public void testMapSerializerRemovesDeletedKeys() throws ObjectMappingException { final TypeToken<Map<String, Integer>> mapStringIntType = new TypeToken<Map<String, Integer>>() {}; final TypeSerializer<Map<String, Integer>> mapStringIntSerializer = SERIALIZERS.get(mapStringIntType); final ConfigurationNode value = SimpleConfigurationNode.root(); value.getNode("fish").setValue(5); value.getNode("bugs").setValue("124880"); value.getNode("time").setValue("-1"); @SuppressWarnings("unchecked") final Map<String, Integer> deserialized = mapStringIntSerializer.deserialize(mapStringIntType, value); deserialized.remove("fish"); mapStringIntSerializer.serialize(mapStringIntType, deserialized, value); assertTrue(value.getNode("fish").isVirtual()); assertFalse(value.getNode("bugs").isVirtual()); }
@Test public void testMoveNode() { final ConfigurationTransformation transform = ConfigurationTransformation.builder() .addAction(p("old", "path"), new TransformAction() { @Nullable @Override public Object[] visitPath(@NonNull NodePath inputPath, @NonNull ConfigurationNode valueAtPath) { return p("new", "path"); } }).build(); ConfigurationNode node = SimpleConfigurationNode.root(); final Object nodeValue = new Object(); node.getNode("old", "path").setValue(nodeValue); transform.apply(node); assertTrue(node.getNode("old", "path").isVirtual()); assertEquals(nodeValue, node.getNode("new", "path").getValue()); }
@Test public void testUnattachedNodesTemporary() { ConfigurationNode config = SimpleConfigurationNode.root(); ConfigurationNode node = config.getNode("some", "node"); assertTrue(node.isVirtual()); assertNull(node.getValue()); assertFalse(node.hasListChildren()); assertFalse(node.hasMapChildren()); ConfigurationNode node2 = config.getNode("some", "node"); assertNotSame(node, node2); ConfigurationNode node3 = config.getNode("some").getNode("node"); assertNotSame(node, node3); }
for (Object[] path : unsortedKeys) { ConfigurationNode child = node.getNode(path); if (child.isVirtual()) { child.setValue("meaningless test value");
@Test public void testSimpleCopy() { ConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("test").setValue(5); node.getNode("section", "val1").setValue(true); node.getNode("section", "val2").setValue("TEST"); ConfigurationNode list = node.getNode("section2", "alist"); list.getAppendedNode().setValue("value1"); list.getAppendedNode().setValue("value2"); ConfigurationNode copy = node.copy(); assertNotSame(node, copy); assertEquals(node, copy); assertFalse(node.isVirtual()); assertFalse(copy.isVirtual()); assertEquals(5, copy.getNode("test").getValue()); assertEquals(true, copy.getNode("section", "val1").getValue()); assertEquals("TEST", copy.getNode("section", "val2").getValue()); assertEquals(ImmutableList.of("value1", "value2"), copy.getNode("section2", "alist").getValue()); // change value on original node.getNode("section", "val2").setValue("NOT TEST"); // test it's still the same on copy assertEquals("TEST", copy.getNode("section", "val2").getValue()); // change value on copy copy.getNode("section", "val2").setValue("zzz"); // test it's still the same on original assertEquals("NOT TEST", node.getNode("section", "val2").getValue()); }