Ejemplo n.º 1
0
  @Override
  @Nullable
  public Object deserialize(Object o, @NotNull Object... nodes) {
    assert nodes.length > 0;
    Object[] children;
    if (nodes.length == 1) {
      children = JDOMUtil.getContent((Element) nodes[0]);
    } else {
      String name = ((Element) nodes[0]).getName();
      List<Content> childrenList = new SmartList<Content>();
      for (Object node : nodes) {
        assert ((Element) node).getName().equals(name);
        childrenList.addAll(((Element) node).getContent());
      }
      children = ArrayUtil.toObjectArray(childrenList);
    }

    if (children.length == 0) {
      children = new Object[] {new Text(myTagAnnotation.textIfEmpty())};
    }

    assert myBinding != null;
    Object v = myBinding.deserialize(myAccessor.read(o), children);
    Object value = XmlSerializerImpl.convert(v, myAccessor.getValueClass());
    myAccessor.write(o, value);
    return o;
  }
Ejemplo n.º 2
0
  private static Binding _createBinding(@NotNull Accessor accessor) {
    Binding binding = XmlSerializerImpl.getTypeBinding(accessor.getGenericType(), accessor);
    if (binding instanceof JDOMElementBinding) {
      return binding;
    }

    Attribute attribute = accessor.getAnnotation(Attribute.class);
    if (attribute != null) {
      return new AttributeBinding(accessor, attribute);
    }

    Tag tag = accessor.getAnnotation(Tag.class);
    if (tag != null && !tag.value().isEmpty()) {
      return new TagBinding(accessor, tag);
    }

    Text text = accessor.getAnnotation(Text.class);
    if (text != null) {
      return new TextBinding(accessor);
    }

    boolean surroundWithTag = true;
    Property property = accessor.getAnnotation(Property.class);
    if (property != null) {
      surroundWithTag = property.surroundWithTag();
    }

    if (!surroundWithTag) {
      if (!Element.class.isAssignableFrom(binding.getBoundNodeType())) {
        throw new XmlSerializationException(
            "Text-serializable properties can't be serialized without surrounding tags: "
                + accessor);
      }
      return new AccessorBindingWrapper(accessor, binding);
    }

    return new OptionTagBinding(accessor, accessor.getAnnotation(OptionTag.class));
  }
Ejemplo n.º 3
0
 private static String getTagNameFromAnnotation(Class<?> aClass) {
   Tag tag = aClass.getAnnotation(Tag.class);
   if (tag != null && !tag.value().isEmpty()) return tag.value();
   return null;
 }
Ejemplo n.º 4
0
  public TagBinding(Accessor accessor, Tag tagAnnotation) {
    super(accessor, tagAnnotation.value(), null);

    myTagAnnotation = tagAnnotation;
  }