Java Code Examples for org.simpleframework.xml.stream.OutputNode#commit()
The following examples show how to use
org.simpleframework.xml.stream.OutputNode#commit() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrimitiveValueTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNoAttributeString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("noAttributeString"), "example"); node.commit(); }
Example 2
Source File: PrimitiveKeyTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNotInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("notInlineString"), "example"); node.commit(); }
Example 3
Source File: PrimitiveKeyTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("inlineString"), "example"); node.commit(); }
Example 4
Source File: CompositeMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testAttributeNoKeyString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeMap value = new CompositeMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("attributeNoKeyString"), exampleMap); node.commit(); }
Example 5
Source File: CompositeMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNoAttributeString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeMap value = new CompositeMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("noAttributeString"), exampleMap); node.commit(); }
Example 6
Source File: CompositeMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNotInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeMap value = new CompositeMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("notInlineString"), exampleMap); node.commit(); }
Example 7
Source File: CompositeMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeMap value = new CompositeMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("inlineString"), exampleMap); node.commit(); }
Example 8
Source File: PrimitiveKeyTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNoAttributeString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("noAttributeString"), "example"); node.commit(); }
Example 9
Source File: PrimitiveValueTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testAttributeNoKeyString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("attributeNoKeyString"), "example"); node.commit(); }
Example 10
Source File: PrimitiveValueTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNotInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("notInlineString"), "example"); node.commit(); }
Example 11
Source File: PrimitiveValueTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveValue value = new PrimitiveValue(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("inlineString"), "example"); node.commit(); }
Example 12
Source File: CompositeInlineMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testAttributeNoKeyString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("attributeNoKeyString").getChild("map"), exampleMap); node.commit(); }
Example 13
Source File: CompositeInlineMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNoAttributeString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("noAttributeString").getChild("map"), exampleMap); node.commit(); }
Example 14
Source File: CompositeInlineMapTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testNotInlineString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(false, // attribute false, // data "entry", // entry true, // inline "key", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); CompositeInlineMap value = new CompositeInlineMap(source, entry, new ClassType(Map.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); Map exampleMap = new HashMap(); exampleMap.put("a", "1"); exampleMap.put("b", "2"); value.write(node.getChild("notInlineString").getChild("map"), exampleMap); node.commit(); }
Example 15
Source File: PrimitiveKeyTest.java From simplexml with Apache License 2.0 | 6 votes |
public void testAttributeNoKeyString() throws Exception { Source source = new Source(new TreeStrategy(), new Support(), new Session()); MockElementMap map = new MockElementMap(true, // attribute false, // data "entry", // entry true, // inline "", // key String.class, // keyType "name", // name true, // required "value", // value String.class); // valueType PrimitiveType type = new PrimitiveType(map); Contact string = type.getString(); Entry entry = new Entry(string, map); PrimitiveKey value = new PrimitiveKey(source, entry, new ClassType(String.class)); OutputNode node = NodeBuilder.write(new PrintWriter(System.out)); value.write(node.getChild("attributeNoKeyString"), "example"); node.commit(); }
Example 16
Source File: Traverser.java From simplexml with Apache License 2.0 | 6 votes |
/** * This <code>write</code> method is used to convert the provided * object to an XML element. This creates a child node from the * given <code>OutputNode</code> object. Once this child element * is created it is populated with the fields of the source object * in accordance with the XML schema class. * * @param source this is the object to be serialized to XML * @param expect this is the class that is expected to be written * @param name this is the name of the root annotation used * * @throws Exception thrown if there is a problem serializing */ public void write(OutputNode node, Object source, Class expect, String name) throws Exception { OutputNode child = node.getChild(name); Type type = getType(expect); if(source != null) { Class actual = source.getClass(); Decorator decorator = getDecorator(actual); if(decorator != null) { decorator.decorate(child); } if(!context.setOverride(type, source, child)) { getComposite(actual).write(child, source); } } child.commit(); }
Example 17
Source File: NamespaceDecoratorTest.java From simplexml with Apache License 2.0 | 5 votes |
public void testQualifier() throws Exception { NamespaceDecorator global = new NamespaceDecorator(); NamespaceDecorator qualifier = new NamespaceDecorator(); NamespaceDecorator attribute = new NamespaceDecorator(); global.add(new MockNamespace("global", "http://www.domain.com/global")); qualifier.add(new MockNamespace("a", "http://www.domain.com/a")); qualifier.add(new MockNamespace("b", "http://www.domain.com/b")); qualifier.add(new MockNamespace("c", "http://www.domain.com/c")); attribute.add(new MockNamespace("d", "http://www.domain.com/d")); global.set(new MockNamespace("first", "http://www.domain.com/ignore")); qualifier.set(new MockNamespace("a", "http://www.domain.com/a")); attribute.set(new MockNamespace("b", "http://www.domain.com/b")); StringWriter out = new StringWriter(); OutputNode top = NodeBuilder.write(out); OutputNode root = top.getChild("root"); root.setAttribute("version", "1.0"); qualifier.decorate(root, global); OutputNode child = root.getChild("child"); child.setAttribute("name", "John Doe"); OutputNode name = child.getAttributes().get("name"); attribute.decorate(name); OutputNode grandChild = child.getChild("grandChild"); grandChild.setValue("this is the grand child"); root.commit(); validate(out.toString()); }
Example 18
Source File: CompositeArray.java From simplexml with Apache License 2.0 | 5 votes |
/** * This <code>write</code> method will write the specified object * to the given XML element as as array entries. Each entry within * the given array must be assignable to the array component type. * Each array entry is serialized as a root element, that is, its * <code>Root</code> annotation is used to extract the name. * * @param source this is the source object array to be serialized * @param node this is the XML element container to be populated */ public void write(OutputNode node, Object source) throws Exception { int size = Array.getLength(source); for(int i = 0; i < size; i++) { Object item = Array.get(source, i); Class type = entry.getType(); root.write(node, item, type, parent); } node.commit(); }
Example 19
Source File: ElementConverter.java From sardine-android with Apache License 2.0 | 4 votes |
public static void write(OutputNode parent, Element domElement) throws Exception { OutputNode child = parent.getChild(domElement.getNodeName()); child.getNamespaces().setReference(domElement.getNamespaceURI(), domElement.getPrefix()); child.setValue(domElement.getTextContent()); child.commit(); }
Example 20
Source File: ElementConverter.java From simpletask-android with GNU General Public License v3.0 | 4 votes |
public static void write(OutputNode parent, Element domElement) throws Exception { OutputNode child = parent.getChild(domElement.getNodeName()); child.getNamespaces().setReference(domElement.getNamespaceURI(), domElement.getPrefix()); child.setValue(domElement.getTextContent()); child.commit(); }