Ejemplo n.º 1
0
  @SuppressWarnings("unchecked")
  private Map<String, Object> fireStructEvents(
      final Class<?> type, final Object part, final XmlRpcListener listener)
      throws XmlRpcException {
    final Mapping<String> recipe = (Mapping<String>) recipesByClass.get(type);

    if (recipe == null) {
      throw new BindException("Cannot find recipe for array value: " + type.getName());
    }

    listener.startStruct();

    LambdaHolder<XmlRpcException> holder = new LambdaHolder<>();
    Map<String, FieldBinding> bindings = recipe.getFieldBindings();

    final Map<String, Object> result = new LinkedHashMap<String, Object>();
    bindings.forEach(
        (memberName, fieldBinding) -> {
          try {
            Object arrayEntry =
                fireValueEvents(
                    fieldBinding,
                    part,
                    listener,
                    (val, t) -> {
                      try {
                        listener.startStructMember(memberName);
                        return true;
                      } catch (XmlRpcException e) {
                        holder.set(e);
                      }
                      return false;
                    },
                    (val, t) -> {
                      try {
                        result.put(memberName, val);

                        listener.structMember(memberName, val, t);
                        listener.endStructMember();
                        return true;
                      } catch (XmlRpcException e) {
                        holder.set(e);
                      }
                      return false;
                    });
          } catch (XmlRpcException e) {
            holder.set(e);
          }
        });

    if (holder.has()) {
      throw holder.get();
    }

    listener.endStruct();

    return result;
  }
Ejemplo n.º 2
0
  @SuppressWarnings("unchecked")
  private void fireMessageEvents(final XmlRpcListener listener) throws XmlRpcException {
    final Class<?> messageCls = message.getClass();
    final Mapping<Integer> recipe = (Mapping<Integer>) recipesByClass.get(messageCls);

    if (recipe == null) {
      throw new BindException("Cannot find recipe for message: " + messageCls.getName());
    }

    final Map<Integer, FieldBinding> bindings =
        new TreeMap<Integer, FieldBinding>(recipe.getFieldBindings());

    LambdaHolder<XmlRpcException> holder = new LambdaHolder<>();
    bindings.forEach(
        (index, fieldBinding) -> {
          try {
            fireValueEvents(
                fieldBinding,
                message,
                listener,
                (val, t) -> {
                  try {
                    listener.startParameter(index);
                    return true;
                  } catch (XmlRpcException e) {
                    holder.set(e);
                  }
                  return false;
                },
                (val, t) -> {
                  try {
                    listener.parameter(index, val, t);
                    listener.endParameter();
                    return true;
                  } catch (XmlRpcException e) {
                    holder.set(e);
                  }
                  return false;
                });
          } catch (XmlRpcException e) {
            holder.set(e);
          }
        });

    if (holder.has()) {
      throw holder.get();
    }
  }
Ejemplo n.º 3
0
  @SuppressWarnings("unchecked")
  private List<Object> fireArrayEvents(
      final Class<?> type, final Object part, final XmlRpcListener listener)
      throws XmlRpcException {
    Logger logger = LoggerFactory.getLogger(getClass());
    logger.trace("Getting mapping recipe for: {}", type.getSimpleName());
    final Mapping<Integer> recipe = (Mapping<Integer>) recipesByClass.get(type);

    if (recipe == null) {
      throw new BindException("Cannot find recipe for array value: " + type.getName());
    }

    final Map<Integer, FieldBinding> bindings =
        new TreeMap<Integer, FieldBinding>(recipe.getFieldBindings());

    listener.startArray();

    final List<Object> result = new ArrayList<Object>();

    LambdaHolder<XmlRpcException> holder = new LambdaHolder<>();
    bindings.forEach(
        (index, fieldBinding) -> {
          try {
            Object arrayEntry =
                fireValueEvents(
                    fieldBinding,
                    part,
                    listener,
                    (val, t) -> {
                      try {
                        listener.startArrayElement(index);
                        return true;
                      } catch (XmlRpcException e) {
                        holder.set(e);
                      }
                      return false;
                    },
                    (val, t) -> {
                      try {
                        while (result.size() < index) {
                          result.add(null);
                        }

                        result.add(val);

                        listener.arrayElement(index, val, t);
                        listener.endArrayElement();
                        return true;
                      } catch (XmlRpcException e) {
                        holder.set(e);
                      }
                      return false;
                    });
          } catch (XmlRpcException e) {
            holder.set(e);
          }
        });

    if (holder.has()) {
      throw holder.get();
    }

    listener.endArray();

    return result;
  }