Ejemplo n.º 1
0
  @Override
  public Param createParam(
      org.glassfish.jersey.server.model.Resource r, ResourceMethod m, final Parameter p) {

    if (p.getSource() == Parameter.Source.UNKNOWN) return null;

    Param wadlParam = new Param();
    wadlParam.setName(p.getSourceName());

    switch (p.getSource()) {
      case FORM:
        wadlParam.setStyle(ParamStyle.QUERY);
        break;
      case QUERY:
        wadlParam.setStyle(ParamStyle.QUERY);
        break;
      case MATRIX:
        wadlParam.setStyle(ParamStyle.MATRIX);
        break;
      case PATH:
        wadlParam.setStyle(ParamStyle.TEMPLATE);
        break;
      case HEADER:
        wadlParam.setStyle(ParamStyle.HEADER);
        break;
      case COOKIE:
        // Generates name="Cookie" path="<name>"
        wadlParam.setStyle(ParamStyle.HEADER);
        wadlParam.setName("Cookie");
        wadlParam.setPath(p.getSourceName());
        break;
      default:
        break;
    }

    if (p.hasDefaultValue()) wadlParam.setDefault(p.getDefaultValue());
    Class<?> pClass = p.getRawType();
    if (pClass.isArray()) {
      wadlParam.setRepeating(true);
      pClass = pClass.getComponentType();
    }
    if (pClass.equals(int.class) || pClass.equals(Integer.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "int", "xs"));
    else if (pClass.equals(boolean.class) || pClass.equals(Boolean.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "boolean", "xs"));
    else if (pClass.equals(long.class) || pClass.equals(Long.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "long", "xs"));
    else if (pClass.equals(short.class) || pClass.equals(Short.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "short", "xs"));
    else if (pClass.equals(byte.class) || pClass.equals(Byte.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "byte", "xs"));
    else if (pClass.equals(float.class) || pClass.equals(Float.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "float", "xs"));
    else if (pClass.equals(double.class) || pClass.equals(Double.class))
      wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "double", "xs"));
    else wadlParam.setType(new QName("http://www.w3.org/2001/XMLSchema", "string", "xs"));
    return wadlParam;
  }
  @Override
  public AbstractContainerRequestValueFactory<?> createValueFactory(Parameter parameter) {
    String parameterName = parameter.getSourceName();

    if (parameterName == null || parameterName.isEmpty()) {
      // Invalid query parameter name
      return null;
    }

    MultivaluedParameterExtractor e = get(parameter);
    if (e == null) {
      return null;
    }
    return new FormParamValueFactory(e, !parameter.isEncoded());
  }