/** * 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); } } }
/** * This method is used to write the version attribute. A version is * written only if it is not the initial version or if it required. * The version is used to determine how to deserialize the XML. If * the version is different from the expected version then it allows * the object to be deserialized in a manner that does not require * any attributes or elements, and unmatched nodes are ignored. * * @param node this is the node to read the version attribute from * @param source this is the source object that is to be written * @param schema this is the schema that contains the version */ private void writeVersion(OutputNode node, Object source, Schema schema) throws Exception { Version version = schema.getRevision(); Label label = schema.getVersion(); if(version != null) { Double start = revision.getDefault(); Double value = version.revision(); if(revision.compare(value, start)) { if(label.isRequired()) { writeAttribute(node, value, label); } } else { writeAttribute(node, value, label); } } }
/** * This reflectively checks the annotation to determine the type * of annotation it represents. If it represents an XML schema * annotation it is used to create a <code>Contact</code> which * can be used to represent the field within the source object. * * @param field the field that the annotation comes from * @param label the annotation used to model the XML schema * @param list this is the list of annotations on the field */ private void scan(Field field, Annotation label, Annotation[] list) { if(label instanceof Attribute) { process(field, label, list); } if(label instanceof ElementUnion) { process(field, label, list); } if(label instanceof ElementListUnion) { process(field, label, list); } if(label instanceof ElementMapUnion) { process(field, label, list); } if(label instanceof ElementList) { process(field, label, list); } if(label instanceof ElementArray) { process(field, label, list); } if(label instanceof ElementMap) { process(field, label, list); } if(label instanceof Element) { process(field, label, list); } if(label instanceof Version) { process(field, label, list); } if(label instanceof Text) { process(field, label, list); } if(label instanceof Transient) { remove(field, label); } }
/** * This reflectively checks the annotation to determine the type * of annotation it represents. If it represents an XML schema * annotation it is used to create a <code>Contact</code> which * can be used to represent the method within the source object. * * @param method the method that the annotation comes from * @param label the annotation used to model the XML schema * @param list this is the list of annotations on the method */ private void scan(Method method, Annotation label, Annotation[] list) throws Exception { if(label instanceof Attribute) { process(method, label, list); } if(label instanceof ElementUnion) { process(method, label, list); } if(label instanceof ElementListUnion) { process(method, label, list); } if(label instanceof ElementMapUnion) { process(method, label, list); } if(label instanceof ElementList) { process(method, label, list); } if(label instanceof ElementArray) { process(method, label, list); } if(label instanceof ElementMap) { process(method, label, list); } if(label instanceof Element) { process(method, label, list); } if(label instanceof Version) { process(method, label, list); } if(label instanceof Text) { process(method, label, list); } if(label instanceof Transient) { remove(method, label, list); } }
/** * Creates an entry that is used to select the constructor for the * label. Each label must implement a constructor that takes a * contact and the specific XML annotation for that field. If the * annotation is not know this method throws an exception. * * @param label the XML annotation used to create the label * * @return this returns the entry used to create a constructor */ private LabelBuilder getBuilder(Annotation label) throws Exception{ if(label instanceof Element) { return new LabelBuilder(ElementLabel.class, Element.class); } if(label instanceof ElementList) { return new LabelBuilder(ElementListLabel.class, ElementList.class); } if(label instanceof ElementArray) { return new LabelBuilder(ElementArrayLabel.class, ElementArray.class); } if(label instanceof ElementMap) { return new LabelBuilder(ElementMapLabel.class, ElementMap.class); } if(label instanceof ElementUnion) { return new LabelBuilder(ElementUnionLabel.class, ElementUnion.class, Element.class); } if(label instanceof ElementListUnion) { return new LabelBuilder(ElementListUnionLabel.class, ElementListUnion.class, ElementList.class); } if(label instanceof ElementMapUnion) { return new LabelBuilder(ElementMapUnionLabel.class, ElementMapUnion.class, ElementMap.class); } if(label instanceof Attribute) { return new LabelBuilder(AttributeLabel.class, Attribute.class); } if(label instanceof Version) { return new LabelBuilder(VersionLabel.class, Version.class); } if(label instanceof Text) { return new LabelBuilder(TextLabel.class, Text.class); } throw new PersistenceException("Annotation %s not supported", label); }
/** * 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 the type of the object that is being deserialized * @param label this is the label used to read the version attribute */ private void readVersion(InputNode node, Object source, Label label) throws Exception { Object value = readInstance(node, source, label); Class expect = type.getType(); if(value != null) { Version version = context.getVersion(expect); Double actual = version.revision(); if(!value.equals(revision)) { revision.compare(actual, value); } } }
/** * This reflectively checks the annotation to determine the type * of annotation it represents. If it represents an XML schema * annotation it is used to create a <code>Label</code> which can * be used to represent the field within the context object. * * @param field the field that the annotation comes from * @param label the annotation used to model the XML schema * * @throws Exception if there is more than one text annotation */ public void process(Contact field, Annotation label) throws Exception { if(label instanceof Attribute) { process(field, label, attributes); } if(label instanceof ElementUnion) { union(field, label, elements); } if(label instanceof ElementListUnion) { union(field, label, elements); } if(label instanceof ElementMapUnion) { union(field, label, elements); } if(label instanceof ElementList) { process(field, label, elements); } if(label instanceof ElementArray) { process(field, label, elements); } if(label instanceof ElementMap) { process(field, label, elements); } if(label instanceof Element) { process(field, label, elements); } if(label instanceof Version) { version(field, label); } if(label instanceof Text) { text(field, label); } }
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the schema class */ public Version getRevision() { if(version != null) { Contact contact = version.getContact(); return contact.getAnnotation(Version.class); } return null; }
/** * Constructor for the <code>VersionLabel</code> object. This is * used to create a label that can convert from a double to an * XML attribute and vice versa. This requires the annotation and * contact extracted from the XML schema class. * * @param contact this is the field from the XML schema class * @param label represents the annotation for the field * @param format this is the format used to style the paths */ public VersionLabel(Contact contact, Version label, Format format) { this.detail = new Introspector(contact, this, format); this.decorator = new Qualifier(contact); this.required = label.required(); this.type = contact.getType(); this.name = label.name(); this.format = format; this.label = label; }
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the class that is scanned */ public Version getRevision() { return structure.getRevision(); }
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the class that is scanned */ public Version getRevision() { return revision; }
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the class that is scanned */ public Version getRevision() { return null; }
/** * This returns the version for the type specified. The version is * used to determine how the deserialization process is performed. * If the version of the type is different from the version for * the XML document, then deserialization is done in a best effort. * * @param type this is the type to acquire the version for * * @return the version that has been set for this XML schema class */ Version getVersion(Class type) throws Exception;
/** * This returns the version for the type specified. The version is * used to determine how the deserialization process is performed. * If the version of the type is different from the version for * the XML document, then deserialization is done in a best effort. * * @param type this is the type to acquire the version for * * @return the version that has been set for this XML schema class */ public Version getVersion(Class type) throws Exception { return getScanner(type).getRevision(); }
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the class that is scanned */ Version getRevision();
/** * This is the <code>Version</code> for the scanned class. It * allows the deserialization process to be configured such that * if the version is different from the schema class none of * the fields and methods are required and unmatched elements * and attributes will be ignored. * * @return this returns the version of the class that is scanned */ public Version getRevision() { return scanner.getRevision(); }