类javax.ws.rs.ext.ParamConverter源码实例Demo

下面列出了怎么用javax.ws.rs.ext.ParamConverter的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: rest.vertx   文件: DummyParamProvider.java
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {

	if (rawType.getName().equals(Dummy.class.getName())) {
		return new ParamConverter<T>() {

			@Override
			public T fromString(String value) {
				Dummy dummy = new Dummy(value);
				return rawType.cast(dummy);
			}

			@Override
			public String toString(T myDummy) {
				if (myDummy == null) {
					return null;
				}
				return myDummy.toString();
			}
		};
	}
	return null;
}
 
源代码2 项目: cxf   文件: BookServer.java
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType,
                                          Annotation[] annotations) {
    if (rawType == Book.class) {

        MessageBodyReader<Book> mbr = providers.getMessageBodyReader(Book.class,
                                                                     Book.class,
                                                                     annotations,
                                                                     MediaType.APPLICATION_XML_TYPE);
        MessageBodyWriter<Book> mbw = providers.getMessageBodyWriter(Book.class,
                                                                     Book.class,
                                                                     annotations,
                                                                     MediaType.APPLICATION_XML_TYPE);
        return (ParamConverter<T>)new XmlParamConverter(mbr, mbw);
    } else if (rawType == byte.class) {
        return (ParamConverter<T>)new ByteConverter();
    } else {
        return null;
    }

}
 
源代码3 项目: cxf   文件: JavaTimeTypesParamConverterProvider.java
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {

    if (rawType.equals(LocalDateTime.class)) {
        return (ParamConverter<T>) new LocalDateTimeConverter();
    } else if (rawType.equals(LocalDate.class)) {
        return (ParamConverter<T>) new LocalDateConverter();
    } else if (rawType.equals(LocalTime.class)) {
        return (ParamConverter<T>) new LocalTimeConverter();
    } else if (rawType.equals(OffsetDateTime.class)) {
        return (ParamConverter<T>) new OffsetDateTimeConverter();
    } else if (rawType.equals(OffsetTime.class)) {
        return (ParamConverter<T>) new OffsetTimeConverter();
    } else if (rawType.equals(ZonedDateTime.class)) {
        return (ParamConverter<T>) new ZonedDateTimeConverter();
    } else {
        return null;
    }
}
 
源代码4 项目: cxf   文件: ProviderFactory.java
public <T> ParamConverter<T> createParameterHandler(Class<T> paramType,
                                                    Type genericType,
                                                    Annotation[] anns,
                                                    Message m) {

    anns = anns != null ? anns : new Annotation[]{};
    for (ProviderInfo<ParamConverterProvider> pi : paramConverters) {
        injectContextValues(pi, m);
        ParamConverter<T> converter = pi.getProvider().getConverter(paramType, genericType, anns);
        if (converter != null) {
            return converter;
        }
        pi.clearThreadLocalProxies();
    }
    return null;
}
 
源代码5 项目: cxf   文件: ParamConverterUtils.java
/**
 * Converts the string-based representation of the value to the instance of particular type
 * using parameter converter provider and available parameter converter.
 * @param type type to convert from string-based representation
 * @param provider parameter converter provider to use
 * @param value the string-based representation to convert
 * @return instance of particular type converter from its string representation
 */
@SuppressWarnings("unchecked")
public static< T > T getValue(final Class< T > type, final ParamConverterProvider provider,
        final String value) {

    if (String.class.isAssignableFrom(type)) {
        return (T)value;
    }

    if (provider != null) {
        final ParamConverter< T > converter = provider.getConverter(type, null, new Annotation[0]);
        if (converter != null) {
            return converter.fromString(value);
        }
    }

    throw new IllegalArgumentException(String.format(
            "Unable to convert string '%s' to instance of class '%s': no appropriate converter provided",
            value, type.getName()));
}
 
源代码6 项目: datawave   文件: DateParamConverterProvider.java
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    if (rawType.equals(Date.class)) {
        DateFormat format = FindAnnotation.findAnnotation(annotations, DateFormat.class);
        return (ParamConverter<T>) new DateFormatter(format);
    }
    return null;
}
 
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
    if (clazz.getName().equals(OffsetDateTime.class.getName())) {
        return new ParamConverter<T>() {
            @SuppressWarnings("unchecked")
            public T fromString(String value) {
                return value != null ? (T) OffsetDateTime.parse(value) : null;
            }

            public String toString(T bean) {
                return bean != null ? bean.toString() : "";
            }
        };
    }
    return null;
}
 
源代码8 项目: openapi-generator   文件: LocalDateProvider.java
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
    if (clazz.getName().equals(LocalDate.class.getName())) {
        return new ParamConverter<T>() {
            @SuppressWarnings("unchecked")
            public T fromString(String value) {
                return value!=null ? (T) LocalDate.parse(value) : null;
            }

            public String toString(T bean) {
                return bean!=null ? bean.toString() : "";
            }
        };
    }
    return null;
}
 
源代码9 项目: jax-rs-moshi   文件: MoshiParamConverterFactory.java
@Override public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType,
    Annotation[] annotations) {
  for (Annotation annotation : annotations) {
    if (annotation instanceof Json) {
      JsonAdapter<T> adapter = moshi.adapter(genericType);
      return new MoshiParamConverter<>(adapter);
    }
  }
  return null;
}
 
@Test public void differentJsonAnnotationReturnsNull() {
  ParamConverter<String> converter =
      provider.getConverter(String.class, String.class, new Annotation[] {
          Annotations.other()
      });
  assertNull(converter);
}
 
@Test public void jsonAnnotationReturnsConverterClass() {
  ParamConverter<String> converter =
      provider.getConverter(String.class, String.class, new Annotation[] {
          Annotations.real()
      });
  String value = converter.fromString("\"hey\"");
  assertEquals("hey", value);
  String json = converter.toString("hey");
  assertEquals("\"hey\"", json);
}
 
@Test public void jsonAnnotationReturnsConverterParameterized() {
  Type genericType = Types.newParameterizedType(List.class, String.class);
  ParamConverter<List<String>> converter =
      (ParamConverter) provider.getConverter(List.class, genericType, new Annotation[] {
          Annotations.real()
      });
  List<String> value = converter.fromString("[\"hey\"]");
  assertEquals(singletonList("hey"), value);
  String json = converter.toString(singletonList("hey"));
  assertEquals("[\"hey\"]", json);
}
 
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> aClass, Type type, Annotation[] annotations) {
    if(String.class.isAssignableFrom(aClass)) {
        return (ParamConverter<T>) new TestParamConverter();
    }
    return null;
}
 
源代码14 项目: eplmp   文件: CustomConverterProvider.java
@Override
// Safe cast, ignore warning
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> clazz, Type type, Annotation[] annotations) {
    if (clazz.isAssignableFrom(Date.class)) {
        return (ParamConverter<T>) dateAdapter;
    }
    return null;
}
 
源代码15 项目: Web-API   文件: ParamConverterProvider.java
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    if (CachedWorld.class.isAssignableFrom(rawType)) {
        return (ParamConverter<T>) new WorldParamConverter();
    } else if (CachedPlayer.class.isAssignableFrom(rawType)) {
        return (ParamConverter<T>) new PlayerParamConverter();
    } else if (Vector3d.class.isAssignableFrom(rawType)) {
        return (ParamConverter<T>) new Vector3dParamConverter();
    } else if (Vector3i.class.isAssignableFrom(rawType)) {
        return (ParamConverter<T>) new Vector3iParamConverter();
    }
    return null;
}
 
源代码16 项目: openmeetings   文件: OmParamConverterProvider.java
@SuppressWarnings("unchecked")
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
	if (Calendar.class.isAssignableFrom(rawType)) {
		return (ParamConverter<T>)new CalendarParamConverter();
	} else if (Date.class.isAssignableFrom(rawType)) {
		return (ParamConverter<T>)new DateParamConverter();
	} else if (AppointmentDTO.class.isAssignableFrom(rawType)) {
		return (ParamConverter<T>)new AppointmentParamConverter();
	} else if (UserDTO.class.isAssignableFrom(rawType)) {
		return (ParamConverter<T>)new UserParamConverter();
	}
	return null;
}
 
源代码17 项目: syncope   文件: DateParamConverterProvider.java
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(
        final Class<T> rawType, final Type genericType, final Annotation[] annotations) {

    if (Date.class.equals(rawType)) {
        return (ParamConverter<T>) new DateParamConverter();
    }

    return null;
}
 
源代码18 项目: syncope   文件: DateParamConverterProvider.java
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(
        final Class<T> rawType, final Type genericType, final Annotation[] annotations) {

    if (Date.class.equals(rawType)) {
        return (ParamConverter<T>) new DateParamConverter();
    }

    return null;
}
 
源代码19 项目: hawkular-metrics   文件: ConvertersProvider.java
public ConvertersProvider() {
    ImmutableMap.Builder<Class<?>, ParamConverter<?>> paramConvertersBuilder = ImmutableMap.builder();
    paramConverters = paramConvertersBuilder
            .put(Duration.class, new DurationConverter())
            .put(Tags.class, new TagsConverter())
            .put(TagNames.class, new TagNamesConverter())
            .put(MetricType.class, new MetricTypeConverter())
            .put(Order.class, new OrderConverter())
            .put(Percentiles.class, new PercentilesConverter())
            .build();
}
 
@Override
@SuppressWarnings("unchecked")
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type genericType, Annotation[] annotations) {
    if (genericType.equals(MyMessage.class)) {
        return (ParamConverter<T>) new MyMessageParamConverter();
    }
    return null;
}
 
源代码21 项目: portals-pluto   文件: DateParamConverterProvider.java
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type baseType, Annotation[] annotations) {

	if (rawType == null) {
		return null;
	}

	if (rawType.equals(Date.class)) {
		return (ParamConverter<T>) new DateParamConverter(portletPreferences);
	}

	return null;
}
 
源代码22 项目: portals-pluto   文件: DateParamConverterProvider.java
@Override
public <T> ParamConverter<T> getConverter(Class<T> rawType, Type baseType, Annotation[] annotations) {

	if (rawType == null) {
		return null;
	}

	if (rawType.equals(Date.class)) {
		return (ParamConverter<T>) new DateParamConverter(portletPreferences);
	}

	return null;
}
 
public <T> ParamConverter getParamConverter(Class<?> rawType, Type baseType, Annotation[] annotations) {

		for (ParamConverterProvider paramConverterProvider : paramConverterProviders) {
			ParamConverter<T> paramConverter = paramConverterProvider.getConverter((Class<T>) rawType, baseType,
					annotations);

			if (paramConverter != null) {
				return paramConverter;
			}
		}

		return null;
	}
 
源代码24 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Boolean getBooleanParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Boolean> paramConverter = _getParamConverter(Boolean.class, field.getBaseType(),
			fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Boolean");
	}

	return null;
}
 
源代码25 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Date getDateParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Date> paramConverter = _getParamConverter(Date.class, field.getBaseType(), fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Date");
	}

	return null;
}
 
源代码26 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Double getDoubleParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Double> paramConverter = _getParamConverter(Double.class, field.getBaseType(), fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Double");
	}

	return null;
}
 
源代码27 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Float getFloatParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Float> paramConverter = _getParamConverter(Float.class, field.getBaseType(), fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Float");
	}

	return null;
}
 
源代码28 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Integer getIntegerParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Integer> paramConverter = _getParamConverter(Integer.class, field.getBaseType(),
			fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Integer");
	}

	return null;
}
 
源代码29 项目: portals-pluto   文件: PortletParamProducer.java
@Dependent
@PortletParam
@Produces
public Long getLongParam(ClientDataRequest clientDataRequest, PortletResponse portletResponse,
	InjectionPoint injectionPoint) {

	String value = getStringParam(clientDataRequest, portletResponse, injectionPoint);

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

	Annotated field = injectionPoint.getAnnotated();

	Annotation[] fieldAnnotations = _getFieldAnnotations(field);

	ParamConverter<Long> paramConverter = _getParamConverter(Long.class, field.getBaseType(), fieldAnnotations);

	if (paramConverter != null) {

		try {
			return paramConverter.fromString(value);
		}
		catch (IllegalArgumentException iae) {
			_addBindingError(fieldAnnotations, iae.getMessage(), value);

			return null;
		}
	}

	if (LOG.isWarnEnabled()) {
		LOG.warn("Unable to find a ParamConverterProvider for type Long");
	}

	return Long.valueOf(value);
}
 
源代码30 项目: portals-pluto   文件: PortletParamProducer.java
private <T> ParamConverter _getParamConverter(Class<?> rawType, Type baseType, Annotation[] annotations) {

		for (ParamConverterProvider paramConverterProvider : paramConverterProviders) {

			ParamConverter<T> paramConverter = paramConverterProvider.getConverter((Class<T>) rawType, baseType,
					annotations);

			if (paramConverter != null) {
				return paramConverter;
			}
		}

		return null;
	}
 
 类所在包
 类方法
 同包方法