PropertyAdaptor pa = PropertyUtils.getPropertyAdaptor(targetService, propertyName);
String readMethodName = pa.getReadMethodName();
if (readMethodName == null)
throw new ApplicationRuntimeException(
ImplMessages.servicePropertyNotReadable(propertyName, targetService),
null,
p.getLocation(),
null);
if (!(serviceInterface.isAssignableFrom(pa.getPropertyType())))
throw new ApplicationRuntimeException(
ImplMessages.servicePropertyWrongType(
propertyName,
targetService,
pa.getPropertyType(),
serviceInterface),
p.getLocation(),
null);
// Now we're good to go.
String name = ClassFabUtils.generateClassName("ServicePropertyProxy");
ClassFab cf = _classFactory.newClass(name, Object.class, invokingModule);
addInfrastructure(cf, targetService, serviceInterface, propertyName, readMethodName);
addMethods(cf, serviceId, serviceInterface, propertyName, targetService);
Class proxyClass = cf.createClass();
try
{
return ConstructorUtils.invokeConstructor(proxyClass, new Object[] { targetService });
}
catch (ApplicationRuntimeException ex)
{
throw new ApplicationRuntimeException(ex.getMessage(), p.getLocation(), ex);
}
}