} catch (IllegalAccessException e) { LOG.error("Broken with: " + DynamicUtil.decomposeClass(obj.getClass()) + item.getIdentifier(), e); throw new RuntimeException(e);
    public InterMineObject translateFromDbObject(InterMineObject o)        throws MetaDataException {        if (!(o instanceof Item)) {            return o;        }        Item item = (Item) o;        int itemSize = 100;        Iterator iter = item.getAttributes().iterator();        while (iter.hasNext()) {            itemSize += ((Attribute) iter.next()).getValue().length() + 50;        }        iter = item.getCollections().iterator();        while (iter.hasNext()) {            itemSize += ((ReferenceList) iter.next()).getRefIds().length() + 50;        }        itemSize += item.getReferences().size() * 50;        if (itemSize > 1000000) {            LOG.info("Translating large object " + item.getIdentifier() + " ("                    + identifierToId(item.getIdentifier()) + ") - classname = "                    + item.getClassName() + ", size = " + itemSize);        }        InterMineObject obj = (InterMineObject)            DynamicUtil.instantiateObject(                OntologyUtil.generateClassNames(item.getClassName(), model),                OntologyUtil.generateClassNames(item.getImplementations(), model));        obj.setId(identifierToId(item.getIdentifier()));        try {            for (Iterator i = item.getAttributes().iterator(); i.hasNext();) {                Attribute attr = (Attribute) i.next();                FieldInfo info = TypeUtil.getFieldInfo(obj.getClass(), attr.getName());                if (info == null) {                    String message = "Attribute not found in model: "                                                + DynamicUtil.decomposeClass(obj.getClass())                                                + "." + attr.getName() + " - Attribute id = "                                                + attr.getId() + ", attributes = "                                                + item.getAttributes();                    LOG.error(message);                    throw new MetaDataException(message);                }                Class attrClass = info.getType();                if (!attr.getName().equalsIgnoreCase("id")) {                    Object value = TypeUtil.stringToObject(attrClass, attr.getValue());                    TypeUtil.setFieldValue(obj, attr.getName(), value);                }            }            for (Iterator i = item.getReferences().iterator(); i.hasNext();) {                Reference ref = (Reference) i.next();                Integer identifier = identifierToId(ref.getRefId());                String refName = ref.getName();                if (Character.isLowerCase(refName.charAt(1))) {                    refName = StringUtil.decapitalise(refName);                }                if (TypeUtil.getFieldInfo(obj.getClass(), refName) != null) {                    TypeUtil.setFieldValue(obj, refName, new ProxyReference(os, identifier,                                InterMineObject.class));                } else {                    String message = "Reference not found in model: "                        + DynamicUtil.decomposeClass(obj.getClass())                        + "." + ref.getName();                    LOG.error(message);                    throw new MetaDataException(message);                }            }            for (Iterator i = item.getCollections().iterator(); i.hasNext();) {                ReferenceList refs = (ReferenceList) i.next();                QueryClass qc = new QueryClass(InterMineObject.class);                QueryField qf = new QueryField(qc, "id");                BagConstraint bc =                    new BagConstraint(qf, ConstraintOp.IN,                        toIntegers(new HashSet(StringUtil.tokenize(refs.getRefIds()))));                Query q = new Query();                q.addToSelect(qc);                q.addFrom(qc);                q.setConstraint(bc);                os.getSequence();                refs.getName();                // TODO rules about case changes should be centralised                String refsName = refs.getName();                if (Character.isLowerCase(refsName.charAt(1))) {                    refsName = StringUtil.decapitalise(refsName);                }                if (TypeUtil.getFieldInfo(obj.getClass(), refsName) != null) {                    TypeUtil.setFieldValue(obj, refsName, new SingletonResults(q, os,                                                                             os.getSequence()));                } else {                    String message = "Collection not found in model: "                        + DynamicUtil.decomposeClass(obj.getClass())                        + "." + refsName + " fileInfos: " + TypeUtil.getFieldInfos(obj.getClass());                    LOG.error(message);                    throw new MetaDataException(message);                }            }        } catch (IllegalAccessException e) {            LOG.error("Broken with: " + DynamicUtil.decomposeClass(obj.getClass())                      + item.getIdentifier(), e);            throw new RuntimeException(e);        } catch (MetaDataException e) {            LOG.error("Broken with: " + DynamicUtil.decomposeClass(obj.getClass())                      + item.getIdentifier(), e);            throw e;        } catch (Exception e) {            LOG.error("Broken with: " + DynamicUtil.decomposeClass(obj.getClass())                      + item.getIdentifier(), e);            throw new RuntimeException(e);        }        return obj;    }