コード例 #1
0
  public static void setAttribute(
      final AttributesContainer state, final String name, final Object value) {
    if (name == null) {
      throw new IllegalArgumentException();
    }

    Attribute attribute = null;

    for (Attribute attr : state.getAttributes()) {
      if (name.equalsIgnoreCase(attr.getName().content())) {
        attribute = attr;
        break;
      }
    }

    String string = null;

    if (value != null) {
      string = state.service(MasterConversionService.class).convert(value, String.class);
    }

    if (string == null) {
      if (attribute != null) {
        state.getAttributes().remove(attribute);
      }
    } else {
      if (attribute == null) {
        attribute = state.getAttributes().insert();
        attribute.setName(name);
      }

      attribute.setValue(string);
    }
  }
コード例 #2
0
  public static Object getAttribute(
      final AttributesContainer state, final String name, final Object def) {
    if (name == null) {
      throw new IllegalArgumentException();
    }

    Object value = null;

    for (Attribute attribute : state.getAttributes()) {
      if (name.equalsIgnoreCase(attribute.getName().content())) {
        value = attribute.getValue().content();
        break;
      }
    }

    if (value != null && def != null && def != String.class) {
      value = state.service(MasterConversionService.class).convert(value, def.getClass());
    }

    if (value == null) {
      value = def;
    }

    return value;
  }