/** * Return the key fields of a given class. * @param classKeys map of classname to set of keys * @param clsName the class name to look up * @return the fields that are class keys for the class */ public static List<FieldDescriptor> getKeyFields(Map<String, List<FieldDescriptor>> classKeys, String clsName) { String className = TypeUtil.unqualifiedName(clsName); return classKeys.get(className); }
/** * Returns a FieldInfo object for the given class and field name. * * @param c the Class * @param fieldname the fieldname * @return a FieldInfo object, or null if the fieldname is not found */ public static FieldInfo getFieldInfo(Class<?> c, String fieldname) { return getFieldInfos(c).get(fieldname); }
public Object getFieldValue(final String fieldName) throws IllegalAccessException { if ("id".equals(fieldName)) { return id; } if (!org.intermine.model.bio.Interactor.class.equals(getClass())) { return TypeUtil.getFieldValue(this, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } public Object getFieldProxy(final String fieldName) throws IllegalAccessException {
parsedValue = TypeUtil.stringToObject(type, value); if (parsedValue instanceof String) { parsedValue = ((String) parsedValue).trim();
/** * Returns the value of a public or protected Field of an Object given the field name * * @param o the Object * @param fieldName the name of the relevant Field * @return the value of the Field * @throws IllegalAccessException if the field is inaccessible */ public static Object getFieldValue(Object o, String fieldName) throws IllegalAccessException { try { return getGetter(o.getClass(), fieldName).invoke(o, new Object[] {}); } catch (Exception e) { String type = ""; try { type = " (a " + getFieldInfo(o.getClass(), fieldName).getGetter().getReturnType() .getName() + ")"; } catch (Exception e3) { type = " (available fields are " + getFieldInfos(o.getClass()).keySet() + ")"; } IllegalAccessException e2 = new IllegalAccessException("Couldn't get field \"" + Util.decomposeClass(o.getClass()) + "." + fieldName + "\"" + type); e2.initCause(e); throw e2; } }
public void addCollectionElement(final String fieldName, final org.intermine.model.InterMineObject element) { { if (!org.intermine.model.bio.CrossReference.class.equals(getClass())) { TypeUtil.addCollectionElement(this, fieldName, element); return; } throw new IllegalArgumentException("Unknown collection " + fieldName); } } public Class<?> getElementType(final String fieldName) {
public Class<?> getElementType(final String fieldName) { if (!org.intermine.model.bio.Comment.class.equals(getClass())) { return TypeUtil.getElementType(org.intermine.model.bio.Comment.class, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } }
public Class<?> getFieldType(final String fieldName) { if ("id".equals(fieldName)) { return java.lang.Integer.class; } if (!org.intermine.model.bio.Interactor.class.equals(getClass())) { return TypeUtil.getFieldType(org.intermine.model.bio.Interactor.class, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } public StringConstructor getoBJECT() {
public Object getFieldProxy(final String fieldName) throws IllegalAccessException { if ("id".equals(fieldName)) { return id; } if (!org.intermine.model.bio.Interactor.class.equals(getClass())) { return TypeUtil.getFieldProxy(this, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } public void setFieldValue(final String fieldName, final Object value) {
/** * Returns the Method object that is the setter for the field name * * @param c the Class * @param fieldName the name of the relevant field * @return the setter, or null if the field is not found */ public static Method getSetter(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { return info.getSetter(); } return null; }
type = Class.class; } else { Method field = TypeUtil.getGetter(qc.getType(), fieldName); if (field == null) { throw new IllegalArgumentException("Field '" + fieldName + "' not found in " secondFieldName = null; Class<?> fieldType = field.getReturnType(); type = fieldType.isPrimitive() ? TypeUtil.instantiate(fieldType.toString()) : fieldType;
/** * Instantiate a class by unqualified name * The name should be "Date" or that of a primitive container class such as "Integer" * @param className the name of the class * @return the relevant Class */ public static Class<?> getClass(String className) { Class<?> cls = instantiate(className); if (cls == null) { if ("Date".equals(className)) { cls = Date.class; } else { if ("BigDecimal".equals(className)) { cls = BigDecimal.class; } else { try { cls = Class.forName("java.lang." + className); } catch (Exception e) { throw new RuntimeException("unknown class: " + className); } } } } return cls; }
parsedValue = TypeUtil.stringToObject(type, value); if (parsedValue instanceof String) { parsedValue = ((String) parsedValue).trim();
public void addCollectionElement(final String fieldName, final org.intermine.model.InterMineObject element) { { if (!org.intermine.model.bio.Sequence.class.equals(getClass())) { TypeUtil.addCollectionElement(this, fieldName, element); return; } throw new IllegalArgumentException("Unknown collection " + fieldName); } } public Class<?> getElementType(final String fieldName) {
public Class<?> getElementType(final String fieldName) { if (!org.intermine.model.bio.RNAiResult.class.equals(getClass())) { return TypeUtil.getElementType(org.intermine.model.bio.RNAiResult.class, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } }
public Class<?> getFieldType(final String fieldName) { if ("evidence".equals(fieldName)) { return java.lang.String.class; } if ("id".equals(fieldName)) { return java.lang.Integer.class; } if (!org.intermine.model.bio.DOEvidence.class.equals(getClass())) { return TypeUtil.getFieldType(org.intermine.model.bio.DOEvidence.class, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } public StringConstructor getoBJECT() {
public Object getFieldProxy(final String fieldName) throws IllegalAccessException { if ("code".equals(fieldName)) { return code; } if ("id".equals(fieldName)) { return id; } if (!org.intermine.model.bio.GOEvidenceCode.class.equals(getClass())) { return TypeUtil.getFieldProxy(this, fieldName); } throw new IllegalArgumentException("Unknown field " + fieldName); } public void setFieldValue(final String fieldName, final Object value) {
/** * Returns the Method object that is the adder for the field name * * @param c the Class * @param fieldName the name of the relevant collection * @return the adder, or null if it is not present or if the field is not found */ public static Method getAdder(Class<?> c, String fieldName) { FieldInfo info = getFieldInfo(c, fieldName); if (info != null) { return info.getAdder(); } return null; }
throw new NullPointerException("Subquery parameter is null"); Method field = TypeUtil.getGetter(qc.getType(), fieldName); if (field == null) { throw new IllegalArgumentException("Field '" + fieldName + "' not found in " secondFieldName = fieldName; Class<?> fieldType = field.getReturnType(); type = fieldType.isPrimitive() ? TypeUtil.instantiate(fieldType.toString()) : fieldType;
/** * Instantiate a class by unqualified name * The name should be "Date" or that of a primitive container class such as "Integer" * @param className the name of the class * @return the relevant Class */ public static Class<?> getClass(String className) { Class<?> cls = instantiate(className); if (cls == null) { if ("Date".equals(className)) { cls = Date.class; } else { if ("BigDecimal".equals(className)) { cls = BigDecimal.class; } else { try { cls = Class.forName("java.lang." + className); } catch (Exception e) { throw new RuntimeException("unknown class: " + className); } } } } return cls; }