Пример #1
0
  public static OperationResult createOperationResult(OperationResultType result) {
    if (result == null) {
      return null;
    }

    Map<String, Serializable> params = ParamsTypeUtil.fromParamsType(result.getParams());
    //		if (result.getParams() != null) {
    //			params = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getParams().getEntry()) {
    //				params.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    Map<String, Serializable> context = ParamsTypeUtil.fromParamsType(result.getContext());
    //		if (result.getContext() != null) {
    //			context = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getContext().getEntry()) {
    //				context.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    Map<String, Serializable> returns = ParamsTypeUtil.fromParamsType(result.getReturns());
    //		if (result.getReturns() != null) {
    //			returns = new HashMap<String, Serializable>();
    //			for (EntryType entry : result.getReturns().getEntry()) {
    //				returns.put(entry.getKey(), (Serializable) entry.getEntryValue());
    //			}
    //		}

    List<OperationResult> subresults = null;
    if (!result.getPartialResults().isEmpty()) {
      subresults = new ArrayList<OperationResult>();
      for (OperationResultType subResult : result.getPartialResults()) {
        subresults.add(createOperationResult(subResult));
      }
    }

    LocalizedMessageType message = result.getLocalizedMessage();
    String localizedMessage = message == null ? null : message.getKey();
    List<Serializable> localizedArguments =
        message == null
            ? null
            : (List<Serializable>) (List) message.getArgument(); // FIXME: brutal hack

    OperationResult opResult =
        new OperationResult(
            result.getOperation(),
            params,
            context,
            returns,
            OperationResultStatus.parseStatusType(result.getStatus()),
            result.getToken(),
            result.getMessageCode(),
            result.getMessage(),
            localizedMessage,
            localizedArguments,
            null,
            subresults);
    if (result.getCount() != null) {
      opResult.setCount(result.getCount());
    }
    return opResult;
  }
Пример #2
0
  private OperationResultType createOperationResultType(OperationResult opResult) {
    OperationResultType result = new OperationResultType();
    result.setToken(opResult.getToken());
    result.setStatus(OperationResultStatus.createStatusType(opResult.getStatus()));
    if (opResult.getCount() != 1) {
      result.setCount(opResult.getCount());
    }
    result.setOperation(opResult.getOperation());
    result.setMessage(opResult.getMessage());
    result.setMessageCode(opResult.getMessageCode());

    if (opResult.getCause() != null || !opResult.details.isEmpty()) {
      StringBuilder detailsb = new StringBuilder();

      // Record text messages in details (if present)
      if (!opResult.details.isEmpty()) {
        for (String line : opResult.details) {
          detailsb.append(line);
          detailsb.append("\n");
        }
      }

      // Record stack trace in details if a cause is present
      if (opResult.getCause() != null) {
        Throwable ex = opResult.getCause();
        detailsb.append(ex.getClass().getName());
        detailsb.append(": ");
        detailsb.append(ex.getMessage());
        detailsb.append("\n");
        StackTraceElement[] stackTrace = ex.getStackTrace();
        for (int i = 0; i < stackTrace.length; i++) {
          detailsb.append(stackTrace[i].toString());
          detailsb.append("\n");
        }
      }

      result.setDetails(detailsb.toString());
    }

    if (StringUtils.isNotEmpty(opResult.getLocalizationMessage())) {
      LocalizedMessageType message = new LocalizedMessageType();
      message.setKey(opResult.getLocalizationMessage());
      if (opResult.getLocalizationArguments() != null) {
        message.getArgument().addAll(opResult.getLocalizationArguments());
      }
      result.setLocalizedMessage(message);
    }

    //		Set<Entry<String, Serializable>> params = opResult.getParams();
    //		if (!params.isEmpty()) {
    ParamsType paramsType = ParamsTypeUtil.toParamsType(opResult.getParams());
    result.setParams(paramsType);

    //			for (Entry<String, Serializable> entry : params) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> context = opResult.getContext().entrySet();
    //		if (!context.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getContext());
    result.setContext(paramsType);

    //			for (Entry<String, Serializable> entry : context) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    //		Set<Entry<String, Serializable>> returns = opResult.getReturns().entrySet();
    //		if (!returns.isEmpty()) {
    paramsType = ParamsTypeUtil.toParamsType(opResult.getReturns());
    result.setReturns(paramsType);

    //			for (Entry<String, Serializable> entry : returns) {
    //				paramsType.getEntry().add(createEntryElement(entry.getKey(),entry.getValue()));
    //			}
    //		}

    for (OperationResult subResult : opResult.getSubresults()) {
      result.getPartialResults().add(opResult.createOperationResultType(subResult));
    }

    return result;
  }