public class MapConverter implements Converter<HashMap<String, Integer>> { @Override public HashMap<String, Integer> read(InputNode inputNode) throws Exception { final HashMap<String, Integer> result = new HashMap<String, Integer>(); for (final String attributeName : inputNode.getAttributes()) { final String value = inputNode.getAttribute(attributeName).getValue(); result.put(attributeName, Integer.parseInt(value)); } return result; } @Override public void write(OutputNode outputNode, HashMap<String, Integer> stringIntegerHashMap) throws Exception { // not used } }
static Map<String, String> getParameters(InputNode inputNode) throws ParseException { Map<String, String> parameters = Maps.newHashMap(); try { for (String name : inputNode.getAttributes()) { String value = inputNode.getAttribute(name).getValue(); parameters.put(name, value); } } catch (Exception e) { throw new ParseException(e.getMessage(), e); } return parameters; } }
static Map<String, String> getParameters(InputNode inputNode) throws ParseException { Map<String, String> parameters = Maps.newHashMap(); try { for (String name : inputNode.getAttributes()) { String value = inputNode.getAttribute(name).getValue(); parameters.put(name, value); } } catch (Exception e) { throw new ParseException(e.getMessage(), e); } return parameters; } }
/** * This is used to resolve and load a class for the given element. * The class should be of the same type or a subclass of the class * specified. It can be resolved using the details within the * provided XML element, if the details used do not represent any * serializable values they should be removed so as not to disrupt * the deserialization process. For example the default strategy * removes all "class" attributes from the given elements. * * @param type this is the type of the root element expected * @param node this is the element used to resolve an override * * @return returns the type that should be used for the object * * @throws Exception thrown if the class cannot be resolved */ public Value getOverride(Type type, InputNode node) throws Exception { NodeMap<InputNode> map = node.getAttributes(); if(map == null) { throw new PersistenceException("No attributes for %s", node); } return strategy.read(type, map, session); }
/** * This is used to resolve and load a class for the given element. * The class should be of the same type or a subclass of the class * specified. It can be resolved using the details within the * provided XML element, if the details used do not represent any * serializable values they should be removed so as not to disrupt * the deserialization process. For example the default strategy * removes all "class" attributes from the given elements. * * @param type this is the type of the root element expected * @param node this is the element used to resolve an override * * @return returns the type that should be used for the object * * @throws Exception thrown if the class cannot be resolved */ public Value getOverride(Type type, InputNode node) throws Exception { NodeMap<InputNode> map = node.getAttributes(); if(map == null) { throw new PersistenceException("No attributes for %s", node); } return strategy.read(type, map, session); }
/** * This is used to resolve and load a class for the given element. * The class should be of the same type or a subclass of the class * specified. It can be resolved using the details within the * provided XML element, if the details used do not represent any * serializable values they should be removed so as not to disrupt * the deserialization process. For example the default strategy * removes all "class" attributes from the given elements. * * @param type this is the type of the root element expected * @param node this is the element used to resolve an override * * @return returns the type that should be used for the object * * @throws Exception thrown if the class cannot be resolved */ public Value getOverride(Type type, InputNode node) throws Exception { NodeMap<InputNode> map = node.getAttributes(); if(map == null) { throw new PersistenceException("No attributes for %s", node); } return strategy.read(type, map, session); }
@Override public <T> T read(InputNode input, Class<T> type, XmlReadContext delegate) { Value value; try { value = strategy.read(new ClassType(type), input.getAttributes(), delegate); } catch (XmlPersisterException exception) { throw exception; } catch (Exception exception) { throw new XmlPersisterException(exception); } if (value != null && value.isReference()) { return (T) value.getValue(); } else { throw new XmlPersisterException(format("Failed reading %s from %s", type, input)); } }
/** * This <code>readAttributes</code> method reads the attributes from * the provided XML element. This will iterate over all attributes * within the element and convert those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated * the <code>Schema</code> is checked to ensure that there are no * required contacts annotated with the <code>Attribute</code> that * remain. If any required attribute remains an exception is thrown. * * @param node this is the XML element to be evaluated * @param source the type of the object that is being deserialized * @param section this is the XML section that contains the structure */ private void readAttributes(InputNode node, Object source, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { readAttribute(value, source, section, map); } } validate(node, map, source); }
/** * This <code>validateAttributes</code> method validates the attributes * from the provided XML element. This will iterate over all attributes * within the element and validate those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated the * <code>Schema</code> is checked to ensure that there are no required * contacts annotated with the <code>Attribute</code> that remain. If * any required attribute remains an exception is thrown. * * @param node this is the XML element to be validated * @param section this is the section that defines the XML structure */ private void validateAttributes(InputNode node, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { validateAttribute(value, section, map); } } validate(node, map); }
/** * This <code>readAttributes</code> method reads the attributes from * the provided XML element. This will iterate over all attributes * within the element and convert those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated * the <code>Schema</code> is checked to ensure that there are no * required contacts annotated with the <code>Attribute</code> that * remain. If any required attribute remains an exception is thrown. * * @param node this is the XML element to be evaluated * @param source the type of the object that is being deserialized * @param section this is the XML section that contains the structure */ private void readAttributes(InputNode node, Object source, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { readAttribute(value, source, section, map); } } validate(node, map, source); }
/** * This <code>readAttributes</code> method reads the attributes from * the provided XML element. This will iterate over all attributes * within the element and convert those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated * the <code>Schema</code> is checked to ensure that there are no * required contacts annotated with the <code>Attribute</code> that * remain. If any required attribute remains an exception is thrown. * * @param node this is the XML element to be evaluated * @param source the type of the object that is being deserialized * @param section this is the XML section that contains the structure */ private void readAttributes(InputNode node, Object source, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { readAttribute(value, source, section, map); } } validate(node, map, source); }
/** * This <code>validateAttributes</code> method validates the attributes * from the provided XML element. This will iterate over all attributes * within the element and validate those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated the * <code>Schema</code> is checked to ensure that there are no required * contacts annotated with the <code>Attribute</code> that remain. If * any required attribute remains an exception is thrown. * * @param node this is the XML element to be validated * @param section this is the section that defines the XML structure */ private void validateAttributes(InputNode node, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { validateAttribute(value, section, map); } } validate(node, map); }
/** * This <code>validateAttributes</code> method validates the attributes * from the provided XML element. This will iterate over all attributes * within the element and validate those attributes as primitives to * contact values within the source object. * <p> * Once all attributes within the XML element have been evaluated the * <code>Schema</code> is checked to ensure that there are no required * contacts annotated with the <code>Attribute</code> that remain. If * any required attribute remains an exception is thrown. * * @param node this is the XML element to be validated * @param section this is the section that defines the XML structure */ private void validateAttributes(InputNode node, Section section) throws Exception { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = section.getAttributes(); for(String name : list) { InputNode value = node.getAttribute(name); if(value != null) { validateAttribute(value, section, map); } } validate(node, map); }
NodeMap<InputNode> map = node.getAttributes(); InputNode value = map.remove(name);
NodeMap<InputNode> map = node.getAttributes(); InputNode value = map.remove(name);
NodeMap<InputNode> map = node.getAttributes(); InputNode value = map.remove(name);