public Item unmarshall(StaxUnmarshallerContext context) throws Exception {
    Item item = new Item();
    int originalDepth = context.getCurrentDepth();
    int targetDepth = originalDepth + 1;

    if (context.isStartOfDocument()) targetDepth += 2;

    while (true) {
      XMLEvent xmlEvent = context.nextEvent();
      if (xmlEvent.isEndDocument()) return item;

      if (xmlEvent.isAttribute() || xmlEvent.isStartElement()) {
        if (context.testExpression("Name", targetDepth)) {
          item.setName(StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("Name/@encoding", targetDepth)) {
          item.setAlternateNameEncoding(StringStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
        if (context.testExpression("Attribute", targetDepth)) {
          item.getAttributes().add(AttributeStaxUnmarshaller.getInstance().unmarshall(context));
          continue;
        }
      } else if (xmlEvent.isEndElement()) {
        if (context.getCurrentDepth() < originalDepth) {
          return item;
        }
      }
    }
  }
Beispiel #2
0
 /**
  * Constructs a new Item object. Callers should use the setter or fluent setter (with...) methods
  * to initialize any additional object members.
  *
  * @param name The name of the item.
  * @param attributes A list of attributes.
  */
 public Item(String name, java.util.List<Attribute> attributes) {
   setName(name);
   setAttributes(attributes);
 }