@Override public String read(InputNode node) throws Exception { InputNode encryptedAttribute = node.getAttribute("encrypted"); if (encryptedAttribute != null && encryptedAttribute.getValue().equals(Boolean.TRUE.toString())) { return TransferSettings.decrypt(node.getValue()); } return node.getValue(); }
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 } }
@Override public PartialFileHistory.FileHistoryId read(InputNode node) throws Exception { return PartialFileHistory.FileHistoryId.parseFileId(node.getValue()); }
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 <code>validate</code> method wll validate the XML element * list against the provided node and validate its children as entry * types. This ensures each entry type is validated as a root type, * that is, its <code>Root</code> annotation must be present and the * name of the entry element must match that root element name. * * @param node this is the XML element that is to be validated * @param type this is the array type used to create the array * * @return true if the element matches the XML schema class given */ private boolean validate(InputNode node, Class type) throws Exception{ while(true) { InputNode next = node.getNext(); if(next == null) { return true; } if(!next.isEmpty()) { root.validate(next, type); } } }
if (root.isElement()) { sb.append("<").append(root.getName()).append(">"); String value = root.getValue(); if (value != null) { sb.append(value); InputNode node = root.getNext(); while (node != null) { concatNodesTree(sb, node); value = root.getValue(); if (value != null) { sb.append(value); node = root.getNext(); if (root.isElement()) { sb.append("</").append(root.getName()).append(">");
public static Element read(InputNode node) throws Exception { QName qname = new QName(node.getReference(), node.getName(), node.getPrefix()); org.w3c.dom.Element element = SardineUtil.createElement(qname); element.setTextContent(node.getValue()); return element; }
@Override public T read(InputNode node) throws Exception { InputNode clazz = node.getAttribute("class"); // if (clazz == null) // clazz = new inputnod return null; }
/** * This <code>validate</code> method will validate the primitive * by checking the node text. If the value is a reference then * this will not extract any value from the node. Transformation * of the extracted value is not done as it can not account for * template variables. Thus any text extracted is valid. * * @param node this is the node to be validated as a primitive * * @return this returns the primitive that has been validated */ public boolean validate(InputNode node) throws Exception { if(node.isElement()) { validateElement(node); } else { node.getValue(); } return true; }
private void skipChildrenOfNode(InputNode node) throws Exception { while(node.getNext() != null) { // Do nothing } }
/** * This is used to get the name of the element that owns the * nodes for the specified map. This can be used to determine * which element the node map belongs to. * * @return this returns the name of the owning element */ public String getName() { return source.getName(); }
@Override public Collect read(InputNode node) throws Exception { List<CollectorStep> collectorSteps = Lists.newArrayList(); InputNode inputNode; while ((inputNode = node.getNext()) != null) { Map<String, String> parameters = getParameters(inputNode); String name = StringUtils.defaultString(parameters.get("name"), inputNode.getName()); CollectorStep collectorStep = new CollectorStep(inputNode.getName(), name, parameters); collectorSteps.add(collectorStep); } ValidationUtils.validateSleep(collectorSteps); return new Collect(collectorSteps); }
/** * 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); }
protected Class<? extends T> lookupType(InputNode input, Class type) { Alias alias = new Alias(input.getReference(), input.getName(), get(input, getTypeAttribute())); return aliasTypeMap.get(alias); }
/** * This <code>read</code> method will extract the text value from * the node and replace any template variables before converting * it to a primitive value. This uses the <code>Context</code> * object used for this instance of serialization to replace all * template variables with values from the context filter. * * @param node this is the node to be converted to a primitive * * @return this returns the primitive that has been deserialized */ public Object read(InputNode node) throws Exception{ if(node.isElement()) { return readElement(node); } return read(node, expect); }
/** * This is used to read the specified node from in to the list. If * the node is null then this represents a null element value in * the array. The node can be null only if there is a parent and * that parent contains no child XML elements. * * @param node this is the node to read the array value from * @param list this is the list to add the array value in to * @param index this is the offset to set the value in the array */ private void read(InputNode node, Object list, int index) throws Exception { Class type = entry.getType(); Object value = null; if(!node.isEmpty()) { value = root.read(node, type); } Array.set(list, index, value); }
/** * 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); }
@Override public FileContent.FileChecksum read(InputNode node) throws Exception { return FileContent.FileChecksum.parseFileChecksum(node.getValue()); }
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 <code>validate</code> method wll validate the XML element * list against the provided node and validate its children as entry * types. This ensures each entry type is validated as a root type, * that is, its <code>Root</code> annotation must be present and the * name of the entry element must match that root element name. * * @param node this is the XML element that is to be validated * @param type this is the array type used to create the array * * @return true if the element matches the XML schema class given */ private boolean validate(InputNode node, Class type) throws Exception{ while(true) { InputNode next = node.getNext(); if(next == null) { return true; } if(!next.isEmpty()) { root.validate(next, type); } } }