Esempio n. 1
0
  /* (non-Javadoc)
   * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
   */
  public Object convertInbound(Class<?> paramType, InboundVariable data)
      throws ConversionException {
    if (data.isNull()) {
      return null;
    }

    String uriString = LocalUtil.urlDecode(data.getValue());
    try {
      return new URI(uriString);
    } catch (URISyntaxException ex) {
      log.warn("Failed to create URL from string '" + uriString + "'. Returning null");
      return null;
    }
  }
Esempio n. 2
0
  /* (non-Javadoc)
   * @see org.directwebremoting.Converter#convertInbound(java.lang.Class, org.directwebremoting.InboundVariable, org.directwebremoting.InboundContext)
   */
  public Object convertInbound(Class<?> paramType, InboundVariable data)
      throws ConversionException {
    if (data.isNull()) {
      return null;
    }

    String value = data.getValue();
    if (value == null) {
      throw new NullPointerException(data.toString());
    }

    // If the text is null then the whole bean is null
    if (value.trim().equals(ProtocolConstants.INBOUND_NULL)) {
      return null;
    }

    if (!value.startsWith(ProtocolConstants.INBOUND_MAP_START)
        || !value.endsWith(ProtocolConstants.INBOUND_MAP_END)) {
      log.warn(
          "Expected object while converting data for "
              + paramType.getName()
              + " in "
              + data.getContext().getCurrentProperty()
              + ". Passed: "
              + value);
      throw new ConversionException(paramType, "Data conversion error. See logs for more details.");
    }

    value = value.substring(1, value.length() - 1);

    try {
      // Loop through the properties passed in
      Map<String, String> tokens = extractInboundTokens(paramType, value);

      if (paramsString == null) {
        return createUsingSetterInjection(paramType, data, tokens);
      } else {
        return createUsingConstructorInjection(paramType, data, tokens);
      }
    } catch (InvocationTargetException ex) {
      throw new ConversionException(paramType, ex.getTargetException());
    } catch (ConversionException ex) {
      throw ex;
    } catch (Exception ex) {
      throw new ConversionException(paramType, ex);
    }
  }