Java Code Examples for org.simpleframework.xml.stream.InputNode#getName()

The following examples show how to use org.simpleframework.xml.stream.InputNode#getName() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CompositeInlineList.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>read</code> method will read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This will each entry type is deserialized 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 deserialized
 * 
 * @return this returns the item to attach to the object contact
 */ 
public boolean validate(InputNode node) throws Exception{
   InputNode from = node.getParent();
   Class type = entry.getType();
   String name = node.getName();
   
   while(node != null) {
      boolean valid = root.validate(node, type);
  
      if(valid == false) {
         return false;
      }
      node = from.getNext(name);
   }  
   return true;
}
 
Example 2
Source File: CompositeInlineMap.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>read</code> method will read the XML element map from
 * the provided node and deserialize its children as entry types.
 * Each entry type must contain a key and value so that the entry 
 * can be inserted in to the map as a pair. If either the key or 
 * value is composite it is read as a root object, which means its
 * <code>Root</code> annotation must be present and the name of the
 * object element must match that root element name.
 * 
 * @param node this is the XML element that is to be deserialized
 * @param map this is the map object that is to be populated
 * 
 * @return this returns the item to attach to the object contact
 */
private Object read(InputNode node, Map map) throws Exception {
   InputNode from = node.getParent();
   String name = node.getName();                

   while(node != null) {         
      Object index = key.read(node);
      Object item = value.read(node);
         
      if(map != null) {
         map.put(index, item);
      }
      node = from.getNext(name);
   }
   return map;
}
 
Example 3
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>validateElement</code> method performs a validation
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. If this
 * fails validation then an exception is thrown to report the issue.
 * 
 * @param node this is the node that contains the contact value
 * @param section this is the section to validate this element in
 * @param map this is the map that contains the label objects
 */
private void validateElement(InputNode node, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name);
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = type.getType();
      
      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not exist for %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      validateUnion(node, map, label);
   }         
}
 
Example 4
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>validateElements</code> 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 <code>Schema</code> is checked to ensure that there are no
 * required contacts annotated with the <code>Element</code> that
 * remain. If any required element remains an exception is thrown.
 * 
 * @param node this is the XML element to be evaluated
 * @param section this is the section that defines the XML structure
 */
private void validateElements(InputNode node, Section section) throws Exception {
   LabelMap map = section.getElements();
   InputNode next = node.getNext();
   
   while(next != null) {         
      String name = next.getName();
      Section child = section.getSection(name);         
      
      if(child != null) {
         validateSection(next, child);
      } else {         
         validateElement(next, section, map);
      }
      next = node.getNext();
   } 
   validate(node, map);
}
 
Example 5
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>readElement</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the element from
 * @param map this is the map that contains the label objects
 */
private void readElement(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getPath(name); 
   Label label = map.getLabel(path);      

   if(label == null) {
      label = criteria.resolve(path);
   }
   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);
      
      if(map.isStrict(context) && revision.isEqual()) {              
         throw new ElementException("Element '%s' does not have a match in %s at %s", path, expect, line);
      } else {
         node.skip();                 
      }
   } else {
      readUnion(node, source, map, label);
   }         
}
 
Example 6
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>readAttribute</code> method is used for deserialization
 * of the provided node object using a delegate converter. This is
 * typically another <code>Composite</code> converter, or if the
 * node is an attribute a <code>Primitive</code> converter. When
 * the delegate converter has completed the deserialized value is
 * assigned to the contact.
 * 
 * @param node this is the node that contains the contact value
 * @param source the type of the object that is being deserialized
 * @param section this is the section to read the attribute from
 * @param map this is the map that contains the label objects
 */
private void readAttribute(InputNode node, Object source, Section section, LabelMap map) throws Exception {
   String name = node.getName();
   String path = section.getAttribute(name);
   Label label = map.getLabel(path);
   
   if(label == null) {
      Position line = node.getPosition();
      Class expect = context.getType(type, source);

      if(map.isStrict(context) && revision.isEqual()) {              
         throw new AttributeException("Attribute '%s' does not have a match in %s at %s", path, expect, line);
      }            
   } else {
      readInstance(node, source, label);
   }         
}
 
Example 7
Source File: Composite.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>readElements</code> method reads the elements from 
 * the provided XML element. This will iterate over all elements
 * within the element and convert those elements to primitives or
 * composite objects depending on the contact annotation.
 * <p>
 * Once all elements 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>Element</code> that
 * remain. If any required element 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 the XML section that contains the structure
 */
private void readElements(InputNode node, Object source, Section section) throws Exception {
   LabelMap map = section.getElements();
   InputNode child = node.getNext();
   
   while(child != null) {         
      String name = child.getName();
      Section block = section.getSection(name);         
      
      if(block != null) {
         readSection(child, source, block);
      } else { 
         readElement(child, source, section, map);
      }
      child = node.getNext();
   } 
   validate(node, map, source);
}
 
Example 8
Source File: CompositeInlineList.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>read</code> method wll read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This will each entry type is deserialized 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 deserialized
 * @param list this is the collection that is to be populated
 * 
 * @return this returns the item to attach to the object contact
 */ 
private Object read(InputNode node, Collection list) throws Exception {              
   InputNode from = node.getParent();
   String name = node.getName();
   
   while(node != null) {
      Class type = entry.getType();
      Object item = read(node, type);
      
      if(item != null) {
         list.add(item);
      }      
      node = from.getNext(name);
   }
   return list;
}
 
Example 9
Source File: CompositeInlineMap.java    From simplexml with Apache License 2.0 6 votes vote down vote up
/**
 * This <code>read</code> method will read the XML element map from
 * the provided node and deserialize its children as entry types.
 * Each entry type must contain a key and value so that the entry 
 * can be inserted in to the map as a pair. If either the key or 
 * value is composite it is read as a root object, which means its
 * <code>Root</code> annotation must be present and the name of the
 * object element must match that root element name.
 * 
 * @param node this is the XML element that is to be deserialized
 * 
 * @return this returns the item to attach to the object contact
 */
public boolean validate(InputNode node) throws Exception{
   InputNode from = node.getParent();
   String name = node.getName();                
   
   while(node != null) {
      if(!key.validate(node)) {
         return false;
      }
      if(!value.validate(node)) {
         return false;
      }
      node = from.getNext(name);
   }
   return true;
}
 
Example 10
Source File: PrimitiveInlineList.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * This <code>read</code> method wll read the XML element list from
 * the provided node and deserialize its children as entry types.
 * This will deserialize each entry type as a primitive value. In
 * order to do this the parent string provided forms the element.
 * 
 * @param node this is the XML element that is to be deserialized
 * 
 * @return this returns the item to attach to the object contact
 */ 
public boolean validate(InputNode node) throws Exception{     
   InputNode from = node.getParent();
   String name = node.getName();
   
   while(node != null) {
      boolean valid = root.validate(node);
      
      if(valid == false) {
         return false;            
      }      
      node = from.getNext(name);
   }
   return true;
}
 
Example 11
Source File: Variable.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public boolean validate(InputNode node) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         
   
   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;
      
      return repeat.validate(node);
   }
   throw new PersistenceException("Element '%s' declared twice at %s", name, line);
}
 
Example 12
Source File: Variable.java    From simplexml with Apache License 2.0 5 votes vote down vote up
/**
 * This <code>read</code> method will perform a read using the
 * provided object with the repeater. Reading with this method
 * ensures that any additional XML elements within the source
 * will be added to the value.
 * 
 *  @param node this is the node that contains the extra data
 *  
 *  @return this will return the original deserialized object
 */
public Object read(InputNode node, Object value) throws Exception {
   Position line = node.getPosition();
   String name = node.getName();         
   
   if(reader instanceof Repeater) {
      Repeater repeat = (Repeater) reader;
      
      return repeat.read(node, value);
   }
   throw new PersistenceException("Element '%s' is already used with %s at %s", name, label, line);
}
 
Example 13
Source File: ElementConverter.java    From sardine-android with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 14
Source File: ElementConverter.java    From simpletask-android with GNU General Public License v3.0 4 votes vote down vote up
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;
}
 
Example 15
Source File: CompositeMapUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>validate</code> method is used to validate the XML
 * element provided using an associated class schema. The schema
 * is selected using the name of the XML element to acquire
 * the associated converter. Once the converter has been acquired
 * it is delegated to and validated against it.
 * 
 * @param node this is the input XML element to be validated
 * 
 * @return this returns true if the node validates 
 */
public boolean validate(InputNode node) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);
   
   return converter.validate(node);
}
 
Example 16
Source File: CompositeMapUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>read</code> method uses the name of the XML element to
 * select a converter to be used to read the instance. Selection of
 * the converter is done by looking up the associated label from
 * the union group using the element name. Once the converter has
 * been selected it is used to read the instance.
 * 
 * @param node this is the XML element used to read the instance
 * @param value this is the value that is to be repeated
 * 
 * @return this is the instance that has been read by this
 */
public Object read(InputNode node, Object value) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);
   
   return converter.read(node, value);
}
 
Example 17
Source File: CompositeUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>read</code> method uses the name of the XML element to
 * select a converter to be used to read the instance. Selection of
 * the converter is done by looking up the associated label from
 * the union group using the element name. Once the converter has
 * been selected it is used to read the instance.
 * 
 * @param node this is the XML element used to read the instance
 * 
 * @return this is the instance that has been read by this
 */
public Object read(InputNode node) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);
   
   return converter.read(node);
}
 
Example 18
Source File: CompositeListUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>validate</code> method is used to validate the XML
 * element provided using an associated class schema. The schema
 * is selected using the name of the XML element to acquire
 * the associated converter. Once the converter has been acquired
 * it is delegated to and validated against it.
 * 
 * @param node this is the input XML element to be validated
 * 
 * @return this returns true if the node validates 
 */
public boolean validate(InputNode node) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);
   
   return converter.validate(node);
}
 
Example 19
Source File: CompositeListUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>readElement</code> method uses the name of the element 
 * to select a converter to be used to read the instance. Selection 
 * of the converter is done by looking up the associated label from
 * the union group using the element name. Once the converter has
 * been selected it is used to read the instance.
 * 
 * @param node this is the XML element used to read the instance
 * 
 * @return this is the instance that has been read by this
 */
private Object readElement(InputNode node) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);

   return converter.read(node);
}
 
Example 20
Source File: CompositeUnion.java    From simplexml with Apache License 2.0 3 votes vote down vote up
/**
 * The <code>validate</code> method is used to validate the XML
 * element provided using an associated class schema. The schema
 * is selected using the name of the XML element to acquire
 * the associated converter. Once the converter has been acquired
 * it is delegated to and validated against it.
 * 
 * @param node this is the input XML element to be validated
 * 
 * @return this returns true if the node validates 
 */
public boolean validate(InputNode node) throws Exception {
   String name = node.getName();
   String element = path.getElement(name);
   Label label = elements.get(element);
   Converter converter = label.getConverter(context);
   
   return converter.validate(node);
}