Пример #1
0
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and the node is valid.
   *
   * @param node this is the node to read the key value from
   * @param key this is the name of the key wrapper XML element
   * @return this returns the value deserialized from the node
   */
  private boolean validate(InputNode node, String key) throws Exception {
    String name = style.getElement(key);
    InputNode next = node.getNext(name);
    Class expect = type.getType();

    if (next == null) {
      return true;
    }
    if (next.isEmpty()) {
      return true;
    }
    return root.validate(next, expect);
  }
Пример #2
0
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and returned.
   *
   * @param node this is the node to read the key value from
   * @param key this is the name of the key wrapper XML element
   * @return this returns the value deserialized from the node
   */
  private Object read(InputNode node, String key) throws Exception {
    String name = style.getElement(key);
    Class expect = type.getType();

    if (name != null) {
      node = node.getNext(name);
    }
    if (node == null) {
      return null;
    }
    if (node.isEmpty()) {
      return null;
    }
    return root.read(node, expect);
  }
Пример #3
0
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and returned.
   *
   * @param node this is the node to read the key value from
   * @param value this is the value to deserialize in to
   * @return this returns the value deserialized from the node
   * @throws Exception if value is not null an exception is thrown
   */
  public Object read(InputNode node, Object value) throws Exception {
    Position line = node.getPosition();
    Class expect = type.getType();

    if (value != null) {
      throw new PersistenceException("Can not read key of %s for %s at %s", expect, entry, line);
    }
    return read(node);
  }
Пример #4
0
    public Value read(Type type, NodeMap<InputNode> node, Map map) throws Exception {
      Component component = type.getAnnotation(Component.class);

      if (component != null) {
        String name = component.name();
        InputNode value = node.get(KEY);

        if (!value.getValue().equals(name)) {
          throw new IllegalStateException(
              "Component name incorrect, expected '"
                  + name
                  + "' but was '"
                  + value.getValue()
                  + "'");
        }
      }
      return strategy.read(type, node, map);
    }
Пример #5
0
  public Party read(InputNode node) throws Exception {
    Person contact = serializer.read(Person.class, node);
    InputNode typeAttribute = node.getAttribute("type");
    if (typeAttribute != null) {
      contact.setType(typeAttribute.getValue());
    }

    if (contact.getType().equals("Company")) {
      Company company = new Company();
      company.setName(contact.getName());
      company.setAvatarUrl(contact.getAvatarUrl());
      company.setBackground(contact.getBackground());
      company.setContactData(contact.getContactData());
      company.setType(contact.getType());
      return company;
    } else {
      return contact;
    }
  }
Пример #6
0
  /**
   * This method is used to read the key value from the node. The value read from the node is
   * resolved using the template filter. If the key value can not be found according to the
   * annotation attributes then null is assumed and returned.
   *
   * @param node this is the node to read the key value from
   * @return this returns the value deserialized from the node
   */
  public Object read(InputNode node) throws Exception {
    Position line = node.getPosition();
    Class expect = type.getType();
    String name = entry.getKey();

    if (name == null) {
      name = context.getName(expect);
    }
    if (entry.isAttribute()) {
      throw new AttributeException(
          "Can not have %s as an attribute for %s at %s", expect, entry, line);
    }
    return read(node, name);
  }
  private Element getElement(Document d, InputNode node) throws DOMException, Exception {
    Element e = d.createElementNS(node.getReference(), node.getName());

    for (String attrName : node.getAttributes()) {
      if (!attrName.equals("xmlns"))
        e.setAttribute(attrName, node.getAttribute(attrName).getValue());
    }

    InputNode nextNode = node.getNext();
    while (nextNode != null) {
      e.appendChild(getElement(d, nextNode));
      nextNode = node.getNext();
    }

    return e;
  }
 public Person read(InputNode node) throws Exception {
   return serializer.read(PersonDelegate.class, node.getNext());
 }