if (gbeanInstance == null || attributeInfo == null) {
throw new IllegalArgumentException("null param(s) supplied");
}
if (!attributeInfo.isReadable() && !attributeInfo.isWritable() && !attributeInfo.isPersistent() && !isConstructorArg) {
throw new InvalidConfigurationException("An attribute must be readable, writable, persistent or a constructor arg: " +
" name=" + attributeInfo.getName() + " targetClass=" + gbeanInstance.getType().getName());
}
this.gbeanInstance = gbeanInstance;
this.attributeInfo = attributeInfo;
this.name = attributeInfo.getName();
this.isConstructorArg = isConstructorArg;
try {
this.type = ClassLoading.loadClass(attributeInfo.getType(), gbeanInstance.getClassLoader());
} catch (ClassNotFoundException e) {
throw new InvalidConfigurationException("Could not load attribute class: " + attributeInfo.getType());
}
this.persistent = attributeInfo.isPersistent();
this.manageable = attributeInfo.isManageable();
readable = attributeInfo.isReadable();
writable = attributeInfo.isWritable();
// If attribute is persistent or not tagged as unreadable, search for a
// getter method
if (attributeInfo instanceof DynamicGAttributeInfo) {
this.dynamic = true;
if (readable) {
getInvoker = new DynamicGetterMethodInvoker(name);
} else {
getInvoker = null;
}
if (writable) {
setInvoker = new DynamicSetterMethodInvoker(name);
} else {
setInvoker = null;
}
} else {
this.dynamic = false;
if (attributeInfo.getGetterName() != null) {
try {
String getterName = attributeInfo.getGetterName();
Method getterMethod = gbeanInstance.getType().getMethod(getterName, null);
if (!getterMethod.getReturnType().equals(type)) {
throw new InvalidConfigurationException("Getter method of wrong type: " + getterMethod.getReturnType() + " expected " +getDescription());
}
if (AbstractGBeanReference.NO_PROXY) {
getInvoker = new ReflectionMethodInvoker(getterMethod);
} else {
getInvoker = new FastMethodInvoker(getterMethod);
}
} catch (NoSuchMethodException e) {
throw new InvalidConfigurationException("Getter method not found " +getDescription());
}
} else {
getInvoker = null;
}
// If attribute is persistent or not tagged as unwritable, search
// for a setter method
if (attributeInfo.getSetterName() != null) {
try {
String setterName = attributeInfo.getSetterName();
Method setterMethod = gbeanInstance.getType().getMethod(setterName, new Class[] {type});
if (AbstractGBeanReference.NO_PROXY) {
setInvoker = new ReflectionMethodInvoker(setterMethod);
} else {
setInvoker = new FastMethodInvoker(setterMethod);
}
} catch (NoSuchMethodException e) {
throw new InvalidConfigurationException("Setter method not found " + getDescription());
}
} else {
setInvoker = null;
}
}