/** * For the given object returns the result of decomposeClass if that is a single class, or * throws an exception if there are more than one class. * * @param obj an object from the model * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass(FastPathObject obj) { return getSimpleClass(obj.getClass()); }
public void setFieldValue(final String fieldName, final Object value) { if ("id".equals(fieldName)) { id = (java.lang.Integer) value; } else { if (!org.intermine.model.bio.Interactor.class.equals(getClass())) { DynamicUtil.setFieldValue(this, fieldName, value); return; } throw new IllegalArgumentException("Unknown field " + fieldName); } } public Class<?> getFieldType(final String fieldName) {
/** * 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()); }
InterMineObject imo = (InterMineObject) fpo; for (Class<?> keyCls : refsInKeys.keySet()) { if (DynamicUtil.isAssignableFrom(keyCls, DynamicUtil.getSimpleClass(imo))) { for (String fieldName : refsInKeys.get(keyCls)) {
public void testCreateObjectNothing() throws Exception { try { Object obj = DynamicUtil.createObject(Collections.EMPTY_SET); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testGetSimpleClass() throws Exception { FastPathObject obj = DynamicUtil.instantiateObject("org.intermine.model.testmodel.Company", null); assertEquals(Company.class, DynamicUtil.getSimpleClass(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.getSimpleClass(obj); fail("Expected an IllegalArgumentException"); } catch (IllegalArgumentException 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) { } }
public void testInstantiateObjectNullClassName() throws Exception { Object obj = DynamicUtil.instantiateObject(null, "org.intermine.model.testmodel.Broke"); assertTrue(obj instanceof Broke); }
/** * Create a 'simple object' which doesn't inherit from InterMineObject and doesn't have an id. * @param c the class of object to create * @param <C> the type of the class * @return an empty simple object of the given class */ public <C extends FastPathObject> C createSimpleObject(Class<C> c) { C o = DynamicUtil.simpleCreateObject(c); return o; }
/** * Return the Class for the array of Class objects. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException is there is more than one Class, or if the fields are not * compatible. */ public static Class<? extends FastPathObject> composeClass(Class<?>... classes) { return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Returns true if obj is an instance of clazz, taking into account dynamic classes. * * @param obj the Object * @param clazz the Class * @return a boolean */ public static boolean isInstance(Object obj, Class<?> clazz) { return isAssignableFrom(clazz, obj.getClass()); }
public void testCreateObjectTwoClasses() throws Exception { Set intSet = new HashSet(); intSet.add(Manager.class); intSet.add(Department.class); try { Object obj = DynamicUtil.createObject(intSet); fail("Expected: IllegalArgumentException"); } catch (IllegalArgumentException e) { } }
public void testInstantiateObjectEmptyClassName() throws Exception { Object obj = DynamicUtil.instantiateObject("", "org.intermine.model.testmodel.Broke"); assertTrue(obj instanceof Broke); }
InterMineObject imo = (InterMineObject) fpo; for (Class<?> keyCls : refsInKeys.keySet()) { if (DynamicUtil.isAssignableFrom(keyCls, DynamicUtil.getSimpleClass(imo))) { for (String fieldName : refsInKeys.get(keyCls)) {
/** * Create a 'simple object' which doesn't inherit from InterMineObject and doesn't have an id. * @param c the class of object to create * @param <C> the type of the class * @return an empty simple object of the given class */ public <C extends FastPathObject> C createSimpleObject(Class<C> c) { C o = DynamicUtil.simpleCreateObject(c); return o; }
/** * Return the Class for the array of Class objects. * * @param classes the classes and interfaces to extend/implement * @return the Class * @throws IllegalArgumentException is there is more than one Class, or if the fields are not * compatible. */ public static Class<? extends FastPathObject> composeClass(Class<?>... classes) { return composeClass(new HashSet<Class<?>>(Arrays.asList(classes))); }
/** * Returns true if obj is an instance of clazz, taking into account dynamic classes. * * @param obj the Object * @param clazz the Class * @return a boolean */ public static boolean isInstance(Object obj, Class<?> clazz) { return isAssignableFrom(clazz, obj.getClass()); }
private Company createCompanyWithId(String companyName) { Company company = (Company) DynamicUtil.createObject(Collections.singleton(Company.class)); company.setId(new Integer(idCounter++)); company.setName(companyName); return company; }
public void setFieldValue(final String fieldName, final Object value) { if ("genes".equals(fieldName)) { genes = (java.util.Set) value; } else if ("id".equals(fieldName)) { id = (java.lang.Integer) value; } else { if (!org.intermine.model.bio.SequenceVariant.class.equals(getClass())) { DynamicUtil.setFieldValue(this, fieldName, value); return; } throw new IllegalArgumentException("Unknown field " + fieldName); } } public Class<?> getFieldType(final String fieldName) {
/** * For the given object returns the result of decomposeClass if that is a single class, or * throws an exception if there are more than one class. * * @param obj an object from the model * @return the corresponding non-dynamic class */ @SuppressWarnings("unchecked") public static Class<? extends FastPathObject> getSimpleClass(FastPathObject obj) { return getSimpleClass(obj.getClass()); }