in plugins/openldap.config.editor/src/main/java/org/apache/directory/studio/openldap/config/model/io/ConfigurationReader.java [717:870]
private static void readAttributeValue( Object bean, Field field, Attribute attribute, Value value )
throws ConfigurationException
{
Class<?> type = field.getType();
String addMethodName = "add" + Character.toUpperCase( field.getName().charAt( 0 ) )
+ field.getName().substring( 1 );
String valueStr = value.getString();
try
{
// String class
if ( type == String.class )
{
Object stringValue = readSingleValue( type, attribute, valueStr );
if ( stringValue != null )
{
field.set( bean, stringValue );
}
}
// Int primitive type
else if ( type == int.class )
{
Object integerValue = readSingleValue( type, attribute, valueStr );
if ( integerValue != null )
{
field.setInt( bean, ( ( Integer ) integerValue ).intValue() );
}
}
// Integer class
else if ( type == Integer.class )
{
Object integerValue = readSingleValue( type, attribute, valueStr );
if ( integerValue != null )
{
field.set( bean, ( Integer ) integerValue );
}
}
// Long primitive type
else if ( type == long.class )
{
Object longValue = readSingleValue( type, attribute, valueStr );
if ( longValue != null )
{
field.setLong( bean, ( ( Long ) longValue ).longValue() );
}
}
// Long class
else if ( type == Long.class )
{
Object longValue = readSingleValue( type, attribute, valueStr );
if ( longValue != null )
{
field.setLong( bean, ( Long ) longValue );
}
}
// Boolean primitive type
else if ( type == boolean.class )
{
Object booleanValue = readSingleValue( type, attribute, valueStr );
if ( booleanValue != null )
{
field.setBoolean( bean, ( ( Boolean ) booleanValue ).booleanValue() );
}
}
// Boolean class
else if ( type == Boolean.class )
{
Object booleanValue = readSingleValue( type, attribute, valueStr );
if ( booleanValue != null )
{
field.set( bean, ( Boolean ) booleanValue );
}
}
// Dn class
else if ( type == Dn.class )
{
Object dnValue = readSingleValue( type, attribute, valueStr );
if ( dnValue != null )
{
field.set( bean, dnValue );
}
}
// Set class
else if ( type == Set.class )
{
Type genericFieldType = field.getGenericType();
if ( genericFieldType instanceof ParameterizedType )
{
ParameterizedType parameterizedType = ( ParameterizedType ) genericFieldType;
Type[] fieldArgTypes = parameterizedType.getActualTypeArguments();
if ( ( fieldArgTypes != null ) && ( fieldArgTypes.length > 0 ) )
{
Class<?> fieldArgClass = ( Class<?> ) fieldArgTypes[0];
Object methodParameter = Array.newInstance( fieldArgClass, 1 );
Array.set( methodParameter, 0, readSingleValue( fieldArgClass, attribute, valueStr ) );
Method method = bean.getClass().getMethod( addMethodName, methodParameter.getClass() );
method.invoke( bean, methodParameter );
}
}
}
// List class
else if ( type == List.class )
{
Type genericFieldType = field.getGenericType();
if ( genericFieldType instanceof ParameterizedType )
{
ParameterizedType parameterizedType = ( ParameterizedType ) genericFieldType;
Type[] fieldArgTypes = parameterizedType.getActualTypeArguments();
if ( ( fieldArgTypes != null ) && ( fieldArgTypes.length > 0 ) )
{
Class<?> fieldArgClass = ( Class<?> ) fieldArgTypes[0];
Object methodParameter = Array.newInstance( fieldArgClass, 1 );
Array.set( methodParameter, 0, readSingleValue( fieldArgClass, attribute, valueStr ) );
Method method = bean.getClass().getMethod( addMethodName, methodParameter.getClass() );
method.invoke( bean, methodParameter );
}
}
}
}
catch ( IllegalArgumentException | IllegalAccessException iae )
{
throw new ConfigurationException( "Cannot store '" + valueStr + "' into attribute "
+ attribute.getId() );
}
catch ( SecurityException se )
{
throw new ConfigurationException( "Cannot access to the class "
+ bean.getClass().getName() );
}
catch ( NoSuchMethodException nsme )
{
throw new ConfigurationException( "Cannot find a method " + addMethodName
+ " in the class "
+ bean.getClass().getName() );
}
catch ( InvocationTargetException ite )
{
throw new ConfigurationException( "Cannot invoke the class "
+ bean.getClass().getName() + ", "
+ ite.getMessage() );
}
catch ( NegativeArraySizeException nase )
{
// No way that can happen...
}
}