/** * (Note that this method doesn't support @RepHandler; the implementation in * BaseDelegatingResource does.) * * @param delegate * @param rep * @return * @throws ConversionException */ @Override public SimpleObject asRepresentation(T delegate, Representation rep) throws ConversionException { if (delegate == null) throw new NullPointerException(); DelegatingResourceDescription description = getRepresentationDescription(rep); SimpleObject simple = convertDelegateToRepresentation(delegate, description); return simple; }
for (Hyperlink link : rep.getLinks()) { if (link.getUri().startsWith(".")) { link = new Hyperlink(link.getRel(), getUri(delegate) + link.getUri().substring(1)); } else if (link.getUri().startsWith("/")) { link = new Hyperlink(link.getRel(), RestConstants.URI_PREFIX + link.getUri().substring(1)); link.setUri(applyTemplate(link.getUri(), ret));
@Override public void setProperty(Object instance, String propertyName, Object value) throws ConversionException { try { // try to find a @PropertySetter-annotated method Method annotatedSetter = ReflectionUtil.findPropertySetterMethod(this, propertyName); if (annotatedSetter != null) { Type expectedType = annotatedSetter.getGenericParameterTypes()[1]; value = ConversionUtil.convert(value, expectedType); annotatedSetter.invoke(this, instance, value); return; } // we need the generic type of this property, not just the class Method setter = PropertyUtils.getPropertyDescriptor(instance, propertyName).getWriteMethod(); // Convert the value to the specified type value = ConversionUtil.convert(value, setter.getGenericParameterTypes()[0], instance); setPropertyWhichMayBeAHibernateCollection(instance, propertyName, value); } catch (Exception ex) { throw new ConversionException(propertyName + " on " + instance.getClass(), ex); } }
public <T> Object evaluate(BaseDelegatingConverter<T> converter, T delegate) throws ConversionException { if (delegateProperty != null) { Object propVal = converter.getProperty(delegate, delegateProperty); if (propVal instanceof Collection) { List<Object> ret = new ArrayList<Object>(); for (Object element : (Collection<?>) propVal) ret.add(ConversionUtil.convertToRepresentation(element, rep, getConvertAs())); return ret; } else { return ConversionUtil.convertToRepresentation(propVal, rep, getConvertAs()); } } else if (method != null) { try { return method.invoke(converter, delegate); } catch (Exception ex) { throw new ConversionException("method " + method, ex); } } else { throw new RuntimeException("Property with no delegateProperty or method specified"); } }