/** * 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()); }
/** * 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()); }
/** * Get a list of key field values for the given object. This will return null if there are no * key fields for the object's class or if there are no non-null values for the key fields. * The key fields are kept in a consistent order with inherited fields appearing before those * defined in a subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static List<Object> getKeyFieldValues(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); List<Object> fieldValueList = new ArrayList<Object>(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { fieldValueList.add(valueFromObject); } } return fieldValueList; } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; } }
/** * Get a key field value for the given object. This will return null if there are no key fields * for the object's class or if there are no non-null values for the key fields. The key fields * are kept in a consistent order with inherited fields appearing before those defined in a * subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static Object getKeyFieldValue(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { return valueFromObject; } } } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; }
/** * Get a list of key field values for the given object. This will return null if there are no * key fields for the object's class or if there are no non-null values for the key fields. * The key fields are kept in a consistent order with inherited fields appearing before those * defined in a subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static List<Object> getKeyFieldValues(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); List<Object> fieldValueList = new ArrayList<Object>(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { fieldValueList.add(valueFromObject); } } return fieldValueList; } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; } }
/** * Get a key field value for the given object. This will return null if there are no key fields * for the object's class or if there are no non-null values for the key fields. The key fields * are kept in a consistent order with inherited fields appearing before those defined in a * subclass. * @param obj an object from the model * @param classKeys the key field definition for this model * @return the first available key field value or null */ public static Object getKeyFieldValue(FastPathObject obj, Map<String, List<FieldDescriptor>> classKeys) { String clsName = DynamicUtil.getSimpleClass(obj).getSimpleName(); try { for (String keyField : getKeyFieldNames(classKeys, clsName)) { Object valueFromObject = obj.getFieldValue(keyField); if (valueFromObject != null) { return valueFromObject; } } } catch (IllegalAccessException e) { // this shouldn't happen because objects conform to the model LOG.error("Error fetching a key field value from object: " + obj); } return null; }
InterMineObject imo = (InterMineObject) fpo; for (Class<?> keyCls : refsInKeys.keySet()) { if (DynamicUtil.isAssignableFrom(keyCls, DynamicUtil.getSimpleClass(imo))) { for (String fieldName : refsInKeys.get(keyCls)) {
InterMineObject imo = (InterMineObject) fpo; for (Class<?> keyCls : refsInKeys.keySet()) { if (DynamicUtil.isAssignableFrom(keyCls, DynamicUtil.getSimpleClass(imo))) { for (String fieldName : refsInKeys.get(keyCls)) {
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) { } }
String objectClass = DynamicUtil.getSimpleClass( (Class<? extends FastPathObject>) element.getClass()) .getSimpleName();
String objectClass = DynamicUtil.getSimpleClass( (Class<? extends FastPathObject>) element.getClass()) .getSimpleName();
/** * Reference types are resolved internally either from Object or ProxyReference * @throws Exception */ public void testReferenceTypes() throws Exception { // Collection List<Object> collection = new ArrayList<Object>(); collection.add(ceo); // InlineResultsTable InlineResultsTable resultsTable = new InlineResultsTable(collection, model, webConfig, null, new Integer(1), new Boolean(false), null); assertEquals(new Integer(1), (Integer) resultsTable.getListOfTypes().size()); assertEquals(new Boolean(false), resultsTable.getHasMoreThanOneType()); assertEquals(DynamicUtil.getSimpleClass(ceo), resultsTable.getListOfTypes().get(0)); }
/** * Collection passed to an InlineList requires us to pass in a list of Types, resolved * higher up using PathQueryResultHelper.queryForTypesInCollection() working over OS * @throws Exception */ public void testCollectionTypes() throws Exception { // Collection List<Object> collection = new ArrayList<Object>(); collection.add(company); collection.add(ceo); // Types for a Collection from WebConfig List<Class<?>> typeClasses = new ArrayList<Class<?>>(); Map<String, Type> typesMap = webConfig.getTypes(); // for all types for (Type type : typesMap.values()) { // String to Class typeClasses.add(Class.forName(type.getClassName())); } // InlineResultsTable InlineResultsTable resultsTable = new InlineResultsTable(collection, model, webConfig, null, new Integer(2), new Boolean(false), typeClasses); assertEquals(new Integer(2), (Integer) resultsTable.getListOfTypes().size()); assertEquals(new Integer(3), new Integer(resultsTable.getColumnsSize())); assertEquals(new Boolean(true), resultsTable.getHasMoreThanOneType()); assertEquals( new ArrayList<Class<?>>(Arrays.asList( DynamicUtil.getSimpleClass(ceo), DynamicUtil.getSimpleClass(company))), resultsTable.getListOfTypes()); }