/// <summary> /// This <c>readAttributes</c> 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 <c>Schema</c> is checked to ensure that there are no /// required contacts annotated with the <c>Attribute</c> that /// remain. If any required attribute remains an exception is thrown. /// </summary> /// <param name="node"> /// this is the XML element to be evaluated /// </param> /// <param name="source"> /// the type of the object that is being deserialized /// </param> /// <param name="schema"> /// this is used to visit the attribute contacts /// </param> public void ReadAttributes(InputNode node, Object source, Schema schema) { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = schema.getAttributes(); for(String name : list) { ReadAttribute(node.GetAttribute(name), source, map); } Validate(node, map, source); }
/// <summary> /// This <c>validateAttributes</c> 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 /// <c>Schema</c> is checked to ensure that there are no required /// contacts annotated with the <c>Attribute</c> that remain. If /// any required attribute remains an exception is thrown. /// </summary> /// <param name="node"> /// this is the XML element to be validated /// </param> /// <param name="schema"> /// this is used to visit the attribute contacts /// </param> public void ValidateAttributes(InputNode node, Schema schema) { NodeMap<InputNode> list = node.getAttributes(); LabelMap map = schema.getAttributes(); for(String name : list) { ValidateAttribute(node.GetAttribute(name), map); } Validate(node, map); }
/// <summary> /// This write method is used to write all the attribute contacts from /// the provided source object to the XML element. This visits all /// the contacts marked with the <c>Attribute</c> annotation in /// the source object. All annotated contacts are written as attributes /// to the XML element. This will throw an exception if a required /// contact within the source object is null. /// </summary> /// <param name="source"> /// this is the source object to be serialized /// </param> /// <param name="node"> /// this is the XML element to write attributes to /// </param> /// <param name="schema"> /// this is used to track the referenced attributes /// </param> public void WriteAttributes(OutputNode node, Object source, Schema schema) { LabelMap attributes = schema.getAttributes(); for(Label label : attributes) { Contact contact = label.getContact(); Object value = contact.Get(source); if(value == null) { value = label.getEmpty(context); } if(value == null && label.isRequired()) { throw new AttributeException("Value for %s is null", label); } WriteAttribute(node, value, label); } }