예제 #1
0
 @Override
 public void parse(ByteBuffer b) {
   int tag = Tag.peekTag(b);
   if (tag != delimiter.value())
     throw new ParseException(
         lookup(tag).prettyName() + ": Repeating group fields out of order",
         SessionRejectReason.OutOfOrderGroupField());
   super.parse(b);
 }
예제 #2
0
 @Override
 public String toString() {
   StringBuilder buf = new StringBuilder();
   buf.append(name);
   for (Tag t : tags()) {
     buf.append(":").append(t.key()).append("=").append(t.value());
   }
   return buf.toString();
 }
예제 #3
0
 /**
  * Create a new id by possibly removing tags from the list. This operation will:<br>
  * 1) remove keys as specified by the parameters<br>
  * 2) dedup entries that have the same key, the first value associated with the key will be the
  * one kept,<br>
  * 3) sort the list by the tag keys.
  *
  * @param keys Set of keys to either keep or remove.
  * @param keep If true, then the new id can only have tag keys in the provided set. Otherwise the
  *     new id can only have ids not in that set.
  * @return New identifier after applying the rollup.
  */
 DefaultId rollup(Set<String> keys, boolean keep) {
   if (tags == TagList.EMPTY) {
     return this;
   } else {
     Map<String, String> ts = new TreeMap<>();
     for (Tag t : tags) {
       if (keys.contains(t.key()) == keep && !ts.containsKey(t.key())) {
         ts.put(t.key(), t.value());
       }
     }
     return new DefaultId(name, TagList.create(ts));
   }
 }
예제 #4
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));
  }
예제 #5
0
 private static String getTagNameFromAnnotation(Class<?> aClass) {
   Tag tag = aClass.getAnnotation(Tag.class);
   if (tag != null && !tag.value().isEmpty()) return tag.value();
   return null;
 }
예제 #6
0
 @Override
 public DefaultId withTag(Tag tag) {
   return new DefaultId(name, new TagList(tag.key(), tag.value(), tags));
 }