@Override public void write(final Type type, final NodeMap<OutputNode> node) throws Exception { if (type.getType().equals(Command[].class)) { OutputNode element = node.getNode(); StringBuilder builder = new StringBuilder("A configuration must have 9 commands, one for each button.\n Possible icons are:"); for (Command.Icon icon : Command.Icon.values()) builder.append("\n - ").append(icon.toString()); element.setComment(builder.toString()); } } }
/** * This is used to add a length attribute to the element due to * the fact that the serialized value is an array. The length * of the array is acquired and inserted in to the attributes. * * @param field this is the field type for the array to set * @param value this is the actual value for the array to set * @param node this is the map of attributes for the element * * @return returns the array component type that is set */ private Class writeArray(Class field, Object value, NodeMap node){ int size = Array.getLength(value); if(length != null) { node.put(length, String.valueOf(size)); } return field.getComponentType(); } }
@Override public OutputNode writeAttribute(OutputNode output, String namespace, String attribute, Object source) { OutputNode node = null; if (!skip(null, source)) { NodeMap<OutputNode> attributes = output.getAttributes(); node = attributes.get(attribute); if (node == null) { node = attributes.put(attribute, EMPTY); } node.setReference(namespace == null ? EMPTY : namespace); write(node, source); } return node; }
/** * 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); }
/** * This is used to write the attributes of the specified node to * the output. This will iterate over each node entered on to * the node. Once written the node is considered inactive. * * @param node this is the node to have is attributes written */ private void writeAttributes(OutputNode node) throws Exception { NodeMap<OutputNode> map = node.getAttributes(); for(String name : map) { OutputNode entry = map.get(name); String value = entry.getValue(); String prefix = entry.getPrefix(verbose); writer.writeAttribute(name, value, prefix); } active.remove(node); }
/** * 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); } }
/** * This is used to write the attributes of the specified node to * the output. This will iterate over each node entered on to * the node. Once written the node is considered inactive. * * @param node this is the node to have is attributes written */ private void writeAttributes(OutputNode node) throws Exception { NodeMap<OutputNode> map = node.getAttributes(); for(String name : map) { OutputNode entry = map.get(name); String value = entry.getValue(); String prefix = entry.getPrefix(verbose); writer.writeAttribute(name, value, prefix); } active.remove(node); }
@SuppressWarnings("rawtypes") @Override public boolean write(Type type, Object value, NodeMap node, Map map){ Class actual = value.getClass(); Class expect = type.getType(); Class real = actual; if(actual != expect) { node.put("class", real.getName()); } return false; } }
/** * This is used to serialize a representation of the object value * provided. If there is a <code>Convert</code> annotation present * on the provided type then this will use the converter specified * to serialize a representation of the object. If however there * is no annotation then this will delegate to the internal * strategy. This returns true if the serialization has completed. * * @param type this is the type that represents the field or method * @param value this is the object instance to be serialized * @param node this is the XML element to be serialized to * * @return this returns true if it was serialized, false otherwise */ private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception { Converter converter = scanner.getConverter(type, value); OutputNode parent = node.getNode(); if(converter != null) { converter.write(parent, value); return true; } return false; }
/** * 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); } }
/** * This is used to write the attributes of the specified node to * the output. This will iterate over each node entered on to * the node. Once written the node is considered inactive. * * @param node this is the node to have is attributes written */ private void writeAttributes(OutputNode node) throws Exception { NodeMap<OutputNode> map = node.getAttributes(); for(String name : map) { OutputNode entry = map.get(name); String value = entry.getValue(); String prefix = entry.getPrefix(verbose); writer.writeAttribute(name, value, prefix); } active.remove(node); }
/** * This is used to add a length attribute to the element due to * the fact that the serialized value is an array. The length * of the array is acquired and inserted in to the attributes. * * @param field this is the field type for the array to set * @param value this is the actual value for the array to set * @param node this is the map of attributes for the element * * @return returns the array component type that is set */ private Class writeArray(Class field, Object value, NodeMap node){ int size = Array.getLength(value); if(length != null) { node.put(length, String.valueOf(size)); } return field.getComponentType(); } }
/** * This is used to serialize a representation of the object value * provided. If there is a <code>Registry</code> binding present * for the provided type then this will use the converter specified * to serialize a representation of the object. If however there * is no binding present then this will delegate to the internal * strategy. This returns true if the serialization has completed. * * @param type this is the type that represents the field or method * @param value this is the object instance to be serialized * @param node this is the XML element to be serialized to * * @return this returns true if it was serialized, false otherwise */ private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception { Converter converter = lookup(type, value); OutputNode source = node.getNode(); if(converter != null) { converter.write(source, value); return true; } return false; }
/** * 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); }
/** * This is used to add a length attribute to the element due to * the fact that the serialized value is an array. The length * of the array is acquired and inserted in to the attributes. * * @param field this is the field type for the array to set * @param value this is the actual value for the array to set * @param node this is the map of attributes for the element * * @return returns the array component type that is set */ private Class writeArray(Class field, Object value, NodeMap node){ int size = Array.getLength(value); if(length != null) { node.put(length, String.valueOf(size)); } return field.getComponentType(); } }
/** * This is used to serialize a representation of the object value * provided. If there is a <code>Convert</code> annotation present * on the provided type then this will use the converter specified * to serialize a representation of the object. If however there * is no annotation then this will delegate to the internal * strategy. This returns true if the serialization has completed. * * @param type this is the type that represents the field or method * @param value this is the object instance to be serialized * @param node this is the XML element to be serialized to * * @return this returns true if it was serialized, false otherwise */ private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception { Converter converter = scanner.getConverter(type, value); OutputNode parent = node.getNode(); if(converter != null) { converter.write(parent, value); return true; } return false; }
/** * 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); }
/** * This is used to add a length attribute to the element due to * the fact that the serialized value is an array. The length * of the array is acquired and inserted in to the attributes. * * @param field this is the field type for the array to set * @param value this is the actual value for the array to set * @param node this is the map of attributes for the element * * @return returns the array component type that is set */ private Class writeArray(Class field, Object value, NodeMap node){ int size = Array.getLength(value); if(!containsKey(value)) { node.put(length, String.valueOf(size)); } return field.getComponentType(); } }
/** * This is used to serialize a representation of the object value * provided. If there is a <code>Registry</code> binding present * for the provided type then this will use the converter specified * to serialize a representation of the object. If however there * is no binding present then this will delegate to the internal * strategy. This returns true if the serialization has completed. * * @param type this is the type that represents the field or method * @param value this is the object instance to be serialized * @param node this is the XML element to be serialized to * * @return this returns true if it was serialized, false otherwise */ private boolean write(Type type, Object value, NodeMap<OutputNode> node) throws Exception { Converter converter = lookup(type, value); OutputNode source = node.getNode(); if(converter != null) { converter.write(source, value); return true; } return false; }
/** * 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); } }