return Primitives.wrap(method.getReturnType())
.getConstructor(String.class)
.newInstance(value);
}
catch (final Exception e) {
throw new ReflectiveCapabilityImplementationException(
"Could not convert '" + value + "' to a " + method.getReturnType()
);
}
}
else if (args.length == 1) {
delegate.withProperty(capabilityProperty.value(), args[0] == null ? null : args[0].toString());
if (Void.TYPE.equals(method.getReturnType())) {
return null;
}
if (method.getReturnType().isAssignableFrom(capabilityType)) {
return proxy;
}
throw new ReflectiveCapabilityImplementationException("Could not reflectively implement " + method);
}
else {
throw new ReflectiveCapabilityImplementationException(
CapabilityProperty.class.getName() + " annotations are only allowed on setters and getters"
);
}
}
try {
final Method actual = delegate.getClass().getMethod(method.getName(), method.getParameterTypes());
final Object result = actual.invoke(delegate, args);
if (method.getReturnType() != null && method.getReturnType().isAssignableFrom(capabilityType)) {
return proxy;
}
return result;
}
catch (NoSuchMethodException e) {
throw new ReflectiveCapabilityImplementationException("Could not reflectively implement " + method);
}
catch (InvocationTargetException e) {
throw e.getTargetException();
}
catch (IllegalAccessException e) {