Java Code Examples for org.simpleframework.xml.stream.NodeMap#remove()
The following examples show how to use
org.simpleframework.xml.stream.NodeMap#remove() .
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: Composite.java From simplexml with Apache License 2.0 | 6 votes |
/** * This method is used to read the version from the provided input * node. Once the version has been read it is used to determine how * to deserialize the object. If the version is not the initial * version then it is read in a manner that ignores excessive XML * elements and attributes. Also none of the annotated fields or * methods are required if the version is not the initial version. * * @param node the XML element contact values are deserialized from * @param source this object whose contacts are to be deserialized * @param schema this object visits the objects contacts */ private void readVersion(InputNode node, Object source, Schema schema) throws Exception { Label label = schema.getVersion(); Class expect = type.getType(); if(label != null) { String name = label.getName(); NodeMap<InputNode> map = node.getAttributes(); InputNode value = map.remove(name); if(value != null) { readVersion(value, source, label); } else { Version version = context.getVersion(expect); Double start = revision.getDefault(); Double expected = version.revision(); criteria.set(label, start); revision.compare(expected, start); } } }
Example 2
Source File: AliasTest.java From simplexml with Apache License 2.0 | 6 votes |
public boolean write(Type field, Object value, NodeMap<OutputNode> node, Map map) throws Exception { boolean done = strategy.write(field, value, node, map); Node entry = node.remove("class"); if(entry != null) { String className = entry.getValue(); Class type = Class.forName(className); String name = forward.get(type); if(name == null) { throw new PersistenceException("Could not find alias for class %s", className); } node.put("type", name); } return done; }
Example 3
Source File: ReadGraph.java From simplexml with Apache License 2.0 | 5 votes |
/** * This is used to recover the object references from the document * using the special attributes specified. This allows the element * specified by the <code>NodeMap</code> to be used to discover * exactly which node in the object graph the element represents. * * @param type the type of the field or method in the instance * @param node this is the XML element to be deserialized * * @return this is used to return the type to acquire the value */ public Value read(Type type, NodeMap node) throws Exception { Node entry = node.remove(label); Class expect = type.getType(); if(expect.isArray()) { expect = expect.getComponentType(); } if(entry != null) { String name = entry.getValue(); expect = loader.load(name); } return readInstance(type, expect, node); }
Example 4
Source File: ReadGraph.java From simplexml with Apache License 2.0 | 5 votes |
/** * This is used to recover the object references from the document * using the special attributes specified. This allows the element * specified by the <code>NodeMap</code> to be used to discover * exactly which node in the object graph the element represents. * * @param type the type of the field or method in the instance * @param real this is the overridden type from the XML element * @param node this is the XML element to be deserialized * * @return this is used to return the type to acquire the value */ private Value readInstance(Type type, Class real, NodeMap node) throws Exception { Node entry = node.remove(mark); if(entry == null) { return readReference(type, real, node); } String key = entry.getValue(); if(containsKey(key)) { throw new CycleException("Element '%s' already exists", key); } return readValue(type, real, node, key); }
Example 5
Source File: ReadGraph.java From simplexml with Apache License 2.0 | 5 votes |
/** * This is used to recover the object references from the document * using the special attributes specified. This allows the element * specified by the <code>NodeMap</code> to be used to discover * exactly which node in the object graph the element represents. * * @param type the type of the field or method in the instance * @param real this is the overridden type from the XML element * @param node this is the XML element to be deserialized * * @return this is used to return the type to acquire the value */ private Value readReference(Type type, Class real, NodeMap node) throws Exception { Node entry = node.remove(refer); if(entry == null) { return readValue(type, real, node); } String key = entry.getValue(); Object value = get(key); if(!containsKey(key)) { throw new CycleException("Invalid reference '%s' found", key); } return new Reference(value, real); }
Example 6
Source File: ClassToNamespaceVisitor.java From simplexml with Apache License 2.0 | 5 votes |
public void write(Type field, NodeMap<OutputNode> node) throws Exception { OutputNode value = node.remove("class"); if(value != null) { String type = value.getValue(); String name = new PackageParser().parse(type); if(name == null) { throw new PersistenceException("Could not match class %s", type); } if(comment) { node.getNode().setComment(type); } node.getNode().getNamespaces().setReference(name, "class"); node.getNode().setReference(name); } }
Example 7
Source File: AliasTest.java From simplexml with Apache License 2.0 | 5 votes |
public Value read(Type field, NodeMap<InputNode> node, Map map) throws Exception { Node entry = node.remove("type"); if(entry != null) { String value = entry.getValue(); Class type = backward.get(value); if(type == null) { throw new PersistenceException("Could not find class for alias %s", value); } node.put("class", type.getName()); } return strategy.read(field, node, map); }
Example 8
Source File: StrategyTest.java From simplexml with Apache License 2.0 | 5 votes |
public Value read(Type field, NodeMap node, Map map) throws Exception { Node value = node.remove(ELEMENT_NAME); if(value == null) { return null; } String name = value.getValue(); Class type = Class.forName(name); return new SimpleType(type); }
Example 9
Source File: DecoratorTest.java From simplexml with Apache License 2.0 | 5 votes |
public void read(Class field, NodeMap<InputNode> node) throws Exception{ InputNode value = node.remove(replace); if(value != null) { String name = value.getValue(); String type = read.get(name); if(type == null) { throw new PersistenceException("Could not match name %s", name); } node.put(label, type); } }
Example 10
Source File: DecoratorTest.java From simplexml with Apache License 2.0 | 5 votes |
public void write(Class field, NodeMap<OutputNode> node) throws Exception { OutputNode value = node.remove(label); if(value != null) { String type = value.getValue(); String name = write.get(type); if(name == null) { throw new PersistenceException("Could not match class %s", type); } node.put(replace, name); } }
Example 11
Source File: TreeStrategy.java From simplexml with Apache License 2.0 | 3 votes |
/** * This is used to resolve and load a class for the given element. * Resolution of the class to used is done by inspecting the * XML element provided. If there is a "class" attribute on the * element then its value is used to resolve the class to use. * This also expects a "length" attribute for the array length. * * @param type this is the type of the XML element expected * @param node this is the element used to resolve an override * * @return returns the class that should be used for the object * * @throws Exception thrown if the class cannot be resolved */ private Value readArray(Class type, NodeMap node) throws Exception { Node entry = node.remove(length); int size = 0; if(entry != null) { String value = entry.getValue(); size = Integer.parseInt(value); } return new ArrayValue(type, size); }
Example 12
Source File: TreeStrategy.java From simplexml with Apache License 2.0 | 3 votes |
/** * This is used to resolve and load a class for the given element. * Resolution of the class to used is done by inspecting the * XML element provided. If there is a "class" attribute on the * element then its value is used to resolve the class to use. * If no such attribute exists the specified field is returned, * or if the field type is an array then the component type. * * @param type this is the type of the XML element expected * @param node this is the element used to resolve an override * * @return returns the class that should be used for the object * * @throws Exception thrown if the class cannot be resolved */ private Class readValue(Type type, NodeMap node) throws Exception { Node entry = node.remove(label); Class expect = type.getType(); if(expect.isArray()) { expect = expect.getComponentType(); } if(entry != null) { String name = entry.getValue(); expect = loader.load(name); } return expect; }
Example 13
Source File: ReadGraph.java From simplexml with Apache License 2.0 | 3 votes |
/** * This is used to acquire the <code>Value</code> which can be used * to represent the deserialized value. The type create cab be * added to the graph of created instances if the XML element has * an identification attribute, this allows cycles to be completed. * * @param type the type of the field or method in the instance * @param real this is the overridden type from the XML element * @param node this is the XML element to be deserialized * * @return this is used to return the type to acquire the value */ private Value readArray(Type type, Class real, NodeMap node) throws Exception { Node entry = node.remove(length); int size = 0; if(entry != null) { String value = entry.getValue(); size = Integer.parseInt(value); } return new ArrayValue(real, size); }