/* */
/* */ public class RtUtil
/* */ {
/* */ public static void add(Object o, Object value, String prop, String colType, boolean ignoreNotFoundField, ValueAdapter valueAdapter)
/* */ {
/* 55 */ FieldInfo fieldInfo = FieldInfo.getFieldInfo(o.getClass(), prop, !ignoreNotFoundField);
/* 56 */ if (fieldInfo == null)
/* */ {
/* 58 */ return;
/* */ }
/* */
/* 61 */ Class fieldType = fieldInfo.getType();
/* */ boolean arrType;
/* 63 */ if (fieldType.isArray())
/* */ {
/* 65 */ arrType = true;
/* */ }
/* */ else
/* */ {
/* */ boolean arrType;
/* 67 */ if (Collection.class.isAssignableFrom(fieldType))
/* */ {
/* 69 */ arrType = false;
/* */ }
/* */ else
/* */ {
/* 73 */ throw new JBossXBRuntimeException("Expected type for " + prop + " in " + o.getClass() + " is an array or java.util.Collection but was " + fieldType);
/* */ }
/* */ }
/* */ boolean arrType;
/* 79 */ if (valueAdapter != null)
/* */ {
/* 81 */ value = valueAdapter.cast(value, fieldType);
/* */ }
/* */
/* 84 */ if ((!arrType) || (colType != null))
/* */ {
/* 86 */ Collection col = (Collection)fieldInfo.getValue(o);
/* 87 */ if (col == null)
/* */ {
/* 89 */ if (colType == null)
/* */ {
/* 91 */ col = new ArrayList();
/* */ }
/* */ else
/* */ {
/* */ Class colCls;
/* */ try {
/* 98 */ colCls = Thread.currentThread().getContextClassLoader().loadClass(colType);
/* */ }
/* */ catch (ClassNotFoundException e)
/* */ {
/* 102 */ throw new JBossXBRuntimeException("Failed to load collection type: " + colType);
/* */ }
/* */
/* */ try
/* */ {
/* 107 */ col = (Collection)colCls.newInstance();
/* */ }
/* */ catch (Exception e)
/* */ {
/* 111 */ throw new JBossXBRuntimeException("Failed to create an instance of " + colCls);
/* */ }
/* */ }
/* */
/* 115 */ fieldInfo.setValue(o, col);
/* */ }
/* */
/* 118 */ col.add(value);
/* */ }
/* */ else
/* */ {
/* 122 */ Object arr = fieldInfo.getValue(o);
/* 123 */ int length = 0;
/* 124 */ if (arr == null)
/* */ {
/* 126 */ arr = Array.newInstance(fieldType.getComponentType(), 1);
/* */ }
/* */ else
/* */ {
/* 130 */ Object tmp = arr;
/* 131 */ length = Array.getLength(arr);
/* 132 */ arr = Array.newInstance(fieldType.getComponentType(), length + 1);
/* 133 */ System.arraycopy(tmp, 0, arr, 0, length);
/* */ }
/* */
/* 136 */ Array.set(arr, length, value);
/* 137 */ fieldInfo.setValue(o, arr);
/* */ }
/* */ }