@Override
public Object invoke(final Object proxy, final Method method, final Object[] args)
throws Throwable
{
final CapabilityProperty capabilityProperty = method.getAnnotation(CapabilityProperty.class);
if (capabilityProperty != null) {
if (args == null || args.length == 0) {
// we have a getter
final String value = delegate.property(capabilityProperty.value());
if (value == null || Void.TYPE.equals(method.getReturnType())) {
return null;
}
if (method.getReturnType().isAssignableFrom(capabilityType)) {
return proxy;
}
try {
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;