Пример #1
0
 /// <summary>
 /// This <c>validateElements</c> method validates the elements
 /// from the provided XML element. This will iterate over all elements
 /// within the element and validate those elements as primitives or
 /// composite objects depending on the contact annotation.
 /// <p>
 /// Once all elements 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>Element</c> that
 /// remain. If any required element remains an exception is thrown.
 /// </summary>
 /// <param name="node">
 /// this is the XML element to be evaluated
 /// </param>
 /// <param name="schema">
 /// this is used to visit the element contacts
 /// </param>
 public void ValidateElements(InputNode node, Schema schema) {
    LabelMap map = schema.getElements();
    while(true) {
       InputNode child = node.getNext();
       if(child == null) {
          break;
       }
       ValidateElement(child, map);
    }
    Validate(node, map);
 }
Пример #2
0
 /// <summary>
 /// This write method is used to write all the element contacts from
 /// the provided source object to the XML element. This visits all
 /// the contacts marked with the <c>Element</c> annotation in
 /// the source object. All annotated contacts are written as children
 /// 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 elements to
 /// </param>
 /// <param name="schema">
 /// this is used to track the referenced elements
 /// </param>
 public void WriteElements(OutputNode node, Object source, Schema schema) {
    LabelMap elements = schema.getElements();
    for(Label label : elements) {
       Contact contact = label.getContact();
       Object value = contact.Get(source);
       if(value == null && label.isRequired()) {
          throw new ElementException("Value for %s is null", label);
       }
       Object replace = WriteReplace(value);
       if(replace != null) {
          WriteElement(node, replace, label);
       }
    }
 }