From 555d4d9ea8803f8263dd00af5c37a290a6432358 Mon Sep 17 00:00:00 2001 From: Tim Butram Date: Tue, 22 May 2012 15:25:24 -0400 Subject: [PATCH 1/5] Upgraded to new Version of SnakeYAML. Fixed tagging errors in YamlReaderWriter --- .classpath | 4 --- build.xml | 16 +++++------ src/plugins/Library/io/YamlReaderWriter.java | 28 +++++++++++++------- 3 files changed, 26 insertions(+), 22 deletions(-) diff --git a/.classpath b/.classpath index 6d50dd6a..3c097fbc 100644 --- a/.classpath +++ b/.classpath @@ -3,9 +3,5 @@ - - - - diff --git a/build.xml b/build.xml index abac33c6..81634d4f 100644 --- a/build.xml +++ b/build.xml @@ -64,15 +64,15 @@ - - - + + + - - - - + + + + @@ -234,7 +234,7 @@ - + diff --git a/src/plugins/Library/io/YamlReaderWriter.java b/src/plugins/Library/io/YamlReaderWriter.java index 4c3118e6..88c13f5e 100644 --- a/src/plugins/Library/io/YamlReaderWriter.java +++ b/src/plugins/Library/io/YamlReaderWriter.java @@ -15,6 +15,7 @@ import org.yaml.snakeyaml.representer.Represent; import org.yaml.snakeyaml.nodes.Node; import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.AbstractConstruct; @@ -58,7 +59,7 @@ public class YamlReaderWriter final public static String MIME_TYPE = "text/yaml"; final public static String FILE_EXTENSION = ".yml"; - + final static int MAX_PARALLEL = 1; // Limited by memory mainly. If memory is no object it could be limited by threads. // Each Yaml instance uses a *significant* amount of memory... static final Semaphore parallelLimiter = new Semaphore(MAX_PARALLEL); @@ -89,7 +90,7 @@ public YamlReaderWriter() { } /** We do NOT keep this thread-local, because the Composer is only cleared after - * the next call to load(), so it can persist with a lot of useless data if we + * the next call to load(), so it can persist with a lot of useless data if we * then use a different thread. So lets just construct them as needed. */ private Yaml makeYAML() { DumperOptions opt = new DumperOptions(); @@ -122,14 +123,14 @@ public static class ExtendedRepresenter extends Representer { public ExtendedRepresenter() { this.representers.put(FreenetURI.class, new Represent() { /*@Override**/ public Node representData(Object data) { - return representScalar("!FreenetURI", ((FreenetURI) data).toString()); + return representScalar(new Tag("!FreenetURI"), ((FreenetURI) data).toString()); } }); this.representers.put(Packer.BinInfo.class, new Represent() { /*@Override**/ public Node representData(Object data) { Packer.BinInfo inf = (Packer.BinInfo)data; Map map = Collections.singletonMap(inf.getID(), inf.getWeight()); - return representMapping("!BinInfo", map, true); + return representMapping(new Tag("!BinInfo"), map, true); } }); this.representers.put(TermTermEntry.class, new RepresentTermEntry(tebp_term)); @@ -148,7 +149,14 @@ public RepresentTermEntry(ObjectBlueprint bp) { } /*@Override**/ public Node representData(Object data) { - return representMapping(tag, blueprint.objectAsMap((T)data), true); +/* Map tempMap = blueprint.objectAsMap((T)data); + Map stringMap; + for(String key : tempMap.keySet()) { + Object tempObject = tempMap.get(key); + stringMap.put(key, tempObject.toString()); + }*/ + + return representMapping(new Tag(tag), blueprint.objectAsMap((T)data), true); } } @@ -161,7 +169,7 @@ public RepresentTermEntry(ObjectBlueprint bp) { */ public static class ExtendedConstructor extends Constructor { public ExtendedConstructor() { - this.yamlConstructors.put("!FreenetURI", new AbstractConstruct() { + this.yamlConstructors.put(new Tag("!FreenetURI"), new AbstractConstruct() { /*@Override**/ public Object construct(Node node) { String uri = (String) constructScalar((ScalarNode)node); try { @@ -171,7 +179,7 @@ public ExtendedConstructor() { } } }); - this.yamlConstructors.put("!BinInfo", new AbstractConstruct() { + this.yamlConstructors.put(new Tag("!BinInfo"), new AbstractConstruct() { /*@Override**/ public Object construct(Node node) { Map map = (Map) constructMapping((MappingNode)node); if (map.size() != 1) { @@ -183,9 +191,9 @@ public ExtendedConstructor() { throw new AssertionError(); } }); - this.yamlConstructors.put("!TermTermEntry", new ConstructTermEntry(tebp_term)); - this.yamlConstructors.put("!TermIndexEntry", new ConstructTermEntry(tebp_index)); - this.yamlConstructors.put("!TermPageEntry", new ConstructTermEntry(tebp_page)); + this.yamlConstructors.put(new Tag("!TermTermEntry"), new ConstructTermEntry(tebp_term)); + this.yamlConstructors.put(new Tag("!TermIndexEntry"), new ConstructTermEntry(tebp_index)); + this.yamlConstructors.put(new Tag("!TermPageEntry"), new ConstructTermEntry(tebp_page)); } public class ConstructTermEntry extends AbstractConstruct { From f33bd29eb19ea6fd6f6b3a3666a0038395cbb681 Mon Sep 17 00:00:00 2001 From: Tim Butram Date: Tue, 22 May 2012 15:26:27 -0400 Subject: [PATCH 2/5] Removed unneeded code, mistook an error as orginating from blueprint --- src/plugins/Library/io/YamlReaderWriter.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/src/plugins/Library/io/YamlReaderWriter.java b/src/plugins/Library/io/YamlReaderWriter.java index 88c13f5e..fc60cae9 100644 --- a/src/plugins/Library/io/YamlReaderWriter.java +++ b/src/plugins/Library/io/YamlReaderWriter.java @@ -149,13 +149,6 @@ public RepresentTermEntry(ObjectBlueprint bp) { } /*@Override**/ public Node representData(Object data) { -/* Map tempMap = blueprint.objectAsMap((T)data); - Map stringMap; - for(String key : tempMap.keySet()) { - Object tempObject = tempMap.get(key); - stringMap.put(key, tempObject.toString()); - }*/ - return representMapping(new Tag(tag), blueprint.objectAsMap((T)data), true); } From a57b766e37e993df8ce107207ecb194c77bb4377 Mon Sep 17 00:00:00 2001 From: Tim Butram Date: Tue, 22 May 2012 15:41:09 -0400 Subject: [PATCH 3/5] Added Tags instead of Strings --- test/plugins/Library/io/serial/YamlMapTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/test/plugins/Library/io/serial/YamlMapTest.java b/test/plugins/Library/io/serial/YamlMapTest.java index 414e8a21..08d41eb5 100644 --- a/test/plugins/Library/io/serial/YamlMapTest.java +++ b/test/plugins/Library/io/serial/YamlMapTest.java @@ -15,6 +15,7 @@ import org.yaml.snakeyaml.representer.Represent; import org.yaml.snakeyaml.nodes.Node; import org.yaml.snakeyaml.nodes.ScalarNode; +import org.yaml.snakeyaml.nodes.Tag; import org.yaml.snakeyaml.nodes.MappingNode; import org.yaml.snakeyaml.constructor.Constructor; import org.yaml.snakeyaml.constructor.Construct; @@ -100,7 +101,7 @@ public ExtendedRepresenter() { private class RepresentCustom implements Represent { public Node representData(Object data) { - return representScalar("!Custom", ((Custom) data).toString()); + return representScalar(new Tag("!Custom"), ((Custom) data).toString()); } } } @@ -108,7 +109,7 @@ public Node representData(Object data) { public static class ExtendedConstructor extends Constructor { public ExtendedConstructor() { - this.yamlConstructors.put("!Custom", new ConstructCustom()); + this.yamlConstructors.put(new Tag("!Custom"), new ConstructCustom()); } private class ConstructCustom implements Construct { From 6439a21a98f289091b9c73a44d490c5046ef0541 Mon Sep 17 00:00:00 2001 From: Tim Butram Date: Fri, 25 May 2012 20:03:47 -0400 Subject: [PATCH 4/5] Changed last line that I forgot. --- build.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.xml b/build.xml index 81634d4f..8260ed66 100644 --- a/build.xml +++ b/build.xml @@ -80,7 +80,7 @@ - +