use of org.forgerock.openam.tokens.Converter in project OpenAM by OpenRock.
the class JavaBeanAdapter method initialise.
/**
* Process the annotations on the bean class, and throw exceptions for invalid configuration.
*/
private void initialise() {
this.tokenType = beanClass.getAnnotation(Type.class).value();
BeanInfo beanInfo;
try {
beanInfo = Introspector.getBeanInfo(beanClass);
} catch (IntrospectionException e) {
throw new IllegalStateException("Could not introspect type " + beanClass.getName(), e);
}
for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
if (pd.getReadMethod() != null && pd.getWriteMethod() != null) {
Method readMethod = pd.getReadMethod();
Field f = readMethod.getAnnotation(Field.class);
Method writeMethod = pd.getWriteMethod();
if (f == null) {
f = writeMethod.getAnnotation(Field.class);
}
if (f == null) {
try {
java.lang.reflect.Field field = beanClass.getDeclaredField(pd.getName());
f = field.getAnnotation(Field.class);
} catch (NoSuchFieldException e) {
// fine - field isn't for storage in CTS.
}
}
if (f != null) {
CoreTokenField tokenField = f.field();
Class<?> attributeType = tokenField.getAttributeType();
Class<?> beanFieldType = readMethod.getReturnType();
Class<? extends Converter> converterType = f.converter();
if (converterType.equals(Converter.IdentityConverter.class) && !beanFieldType.equals(attributeType)) {
throw new IllegalStateException("Field " + pd.getDisplayName() + " does not have a compatible type" + "and does not declare a converter");
}
validateConverterType(attributeType, beanFieldType, converterType);
Converter converter = InjectorHolder.getInstance(converterType);
boolean generated = f.generated();
FieldDetails field = new FieldDetails(tokenField, readMethod, writeMethod, converter, generated);
if (tokenField == CoreTokenField.TOKEN_ID) {
idField = field;
} else {
if (generated) {
throw new IllegalStateException("Non-id values cannot be generated: " + f.toString());
}
fields.add(field);
}
fieldsMap.put(pd.getName(), field);
}
}
}
if (idField == null) {
throw new IllegalStateException("The bean class does not declare an ID field");
}
}
Aggregations