/** * Returns the simple class name for the given object or throws an exception if * there are more than one. * @param obj an object from the model * @return the simple class name */ public static synchronized String getSimpleClassName(FastPathObject obj) { return getSimpleClassName(obj.getClass()); }
/** * Returns the simple class name for the given object or throws an exception if * there are more than one. * @param obj an object from the model * @return the simple class name */ public static synchronized String getSimpleClassName(FastPathObject obj) { return getSimpleClassName(obj.getClass()); }
/** * Get the type * @return the type */ public String getType() { if (imObj == null) { return null; } String cls = DynamicUtil.getSimpleClassName(imObj.getClass()); return TypeUtil.unqualifiedName(cls); }
/** * Get the type * @return the type */ public String getType() { if (imObj == null) { return null; } String cls = DynamicUtil.getSimpleClassName(imObj.getClass()); return TypeUtil.unqualifiedName(cls); }
/** * For the given object and reference field name check and throw an exception if the value in * the field is a ProxyReference instead of a full object. * @param imo the object to check * @param fieldName a reference field name to check */ private void checkForNullProxyReference(InterMineObject imo, String fieldName) { try { InterMineObject refObj = (InterMineObject) imo.getFieldProxy(fieldName); if (refObj instanceof ProxyReference) { throw new IllegalArgumentException("Found ProxyReference in a key field reference" + " for " + DynamicUtil.getSimpleClassName(imo) + "." + fieldName + "." + " With the DirectDataLoader any reference that is part of a primary" + " key must be set as an InterMineObject not a ProxyReference."); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
/** * For the given object and reference field name check and throw an exception if the value in * the field is a ProxyReference instead of a full object. * @param imo the object to check * @param fieldName a reference field name to check */ private void checkForNullProxyReference(InterMineObject imo, String fieldName) { try { InterMineObject refObj = (InterMineObject) imo.getFieldProxy(fieldName); if (refObj instanceof ProxyReference) { throw new IllegalArgumentException("Found ProxyReference in a key field reference" + " for " + DynamicUtil.getSimpleClassName(imo) + "." + fieldName + "." + " With the DirectDataLoader any reference that is part of a primary" + " key must be set as an InterMineObject not a ProxyReference."); } } catch (IllegalAccessException e) { throw new RuntimeException(e); } }
public void testGetSimpleClassName() throws Exception { FastPathObject obj = DynamicUtil.instantiateObject("org.intermine.model.testmodel.Company", null); assertEquals(Company.class.getName(), DynamicUtil.getSimpleClassName(obj.getClass())); Set<Class<?>> interfaces = new HashSet<Class<?>>(); interfaces.add(Company.class); interfaces.add(Employee.class); obj = DynamicUtil.createObject(interfaces); // dynamic class composed of multiple classes should throw an exception try { DynamicUtil.getSimpleClassName(obj); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException e) { } }