List of usage examples for java.lang NoSuchFieldException NoSuchFieldException
public NoSuchFieldException(String s)
From source file:org.LexGrid.LexBIG.caCore.utils.LexEVSCaCoreUtils.java
public static Field getField(Class clazz, String fieldName) throws NoSuchFieldException { ArrayList<Field> allFields = getAllFields(clazz); for (Field field : allFields) { if (field.getName().equals(fieldName)) { return field; }//from w w w. j a v a2 s. c om } throw new NoSuchFieldException("The Field: " + fieldName + " was not found."); }
From source file:org.spring.data.gemfire.config.DiskStoreBeanPostProcessor.java
@SuppressWarnings("unchecked") private <T> T readField(final Object obj, final String fieldName) { try {//from w w w . j a va 2 s . com Class type = obj.getClass(); Field field; do { field = type.getDeclaredField(fieldName); type = type.getSuperclass(); } while (field == null && !Object.class.equals(type)); if (field == null) { throw new NoSuchFieldException( String.format("Field (%1$s) does not exist on Object of Class type (%2$s)!", fieldName, ObjectUtils.nullSafeClassName(obj))); } field.setAccessible(true); return (T) field.get(obj); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.jkcsoft.java.util.Beans.java
public static void set(Object bean, String propName, Object value) throws Exception { PropertyDescriptor pd = getPropertyDescriptor(bean, propName); if (pd == null) { throw new NoSuchFieldException("Unknown property: " + propName); }/* ww w .ja v a2 s . c om*/ Method setter = pd.getWriteMethod(); if (setter == null) { throw new NoSuchMethodException("No write method for: " + propName); } setter.invoke(bean, new Object[] { value }); }
From source file:org.grouplens.grapht.util.FieldProxy.java
/** * Resolve this proxy into a {@link Field} instance. * @return The {@link Field} represented by this proxy. * @throws ClassNotFoundException If the proxy's declaring type cannot be resolved. * @throws NoSuchFieldException If the field does not exist on the declaring type. *///from w w w . ja v a2s .c om public Field resolve() throws ClassNotFoundException, NoSuchFieldException { Field cachedField = field; if (cachedField == null) { Class<?> cls = declaringClass.resolve(); field = cachedField = cls.getDeclaredField(fieldName); } // REVIEW Do we want to test equality or assignability? if (!cachedField.getType().equals(fieldType.resolve())) { throw new NoSuchFieldException("type mismatch on " + cachedField.toString()); } return cachedField; }
From source file:org.springframework.data.gemfire.config.DiskStoreBeanPostProcessor.java
@SuppressWarnings("unchecked") private <T> T readField(final Object obj, final String fieldName) { try {//w ww. ja v a2s . co m Class type = obj.getClass(); Field field; do { field = type.getDeclaredField(fieldName); type = type.getSuperclass(); // traverse up the object class hierarchy } while (field == null && !Object.class.equals(type)); if (field == null) { throw new NoSuchFieldException( String.format("Field (%1$s) does not exist on Object of type (%2$s)!", fieldName, ObjectUtils.nullSafeClassName(obj))); } field.setAccessible(true); return (T) field.get(obj); } catch (Exception e) { throw new RuntimeException(String.format("Failed to read field (%1$s) on Object of type (%2$s)!", fieldName, ObjectUtils.nullSafeClassName(obj)), e); } }
From source file:org.springframework.data.gemfire.config.support.DiskStoreDirectoryBeanPostProcessor.java
@SuppressWarnings("unchecked") private <T> T readField(Object obj, String fieldName) { try {// ww w. j a va 2 s .c om Class type = obj.getClass(); Field field; do { field = type.getDeclaredField(fieldName); type = type.getSuperclass(); } while (field == null && !Object.class.equals(type)); if (field == null) { throw new NoSuchFieldException( String.format("No field with name [%1$s] found on object of type [%2$s]", fieldName, ObjectUtils.nullSafeClassName(obj))); } field.setAccessible(true); return (T) field.get(obj); } catch (Exception e) { throw new RuntimeException(String.format("Failed to read field [%1$s] from object of type [%2$s]", fieldName, ObjectUtils.nullSafeClassName(obj)), e); } }
From source file:com.manydesigns.elements.reflection.FilteredClassAccessor.java
public PropertyAccessor getProperty(String propertyName) throws NoSuchFieldException { for (PropertyAccessor current : properties) { if (current.getName().equals(propertyName)) { return current; }//w w w . j av a 2s . c o m } throw new NoSuchFieldException(propertyName); }
From source file:nl.knaw.dans.common.lang.search.bean.SearchBeanUtil.java
public static String getFieldName(Object searchBean, String propertyName) throws NoSuchFieldException { Map<String, java.lang.reflect.Field> fields = ClassUtil.getAllFields(searchBean.getClass()); java.lang.reflect.Field classField = fields.get(propertyName); if (classField == null) throw new NoSuchFieldException(propertyName); if (classField.isAnnotationPresent(SearchField.class)) return classField.getAnnotation(SearchField.class).name(); else/*from w w w.ja va2 s.co m*/ return null; }
From source file:org.kuali.rice.krad.dao.impl.PersistenceDaoJpa.java
private Field getField(Class clazz, String name) throws NoSuchFieldException { if (clazz.equals(Object.class)) { throw new NoSuchFieldException(name); }//from w w w . j a v a2 s.c o m Field field = null; try { field = clazz.getDeclaredField(name); } catch (Exception e) { } if (field == null) { field = getField(clazz.getSuperclass(), name); } return field; }
From source file:IntrospectionUtil.java
protected static Field findInheritedField(Package pack, Class clazz, String fieldName, Class fieldType, boolean strictType) throws NoSuchFieldException { if (clazz == null) throw new NoSuchFieldException("No class"); if (fieldName == null) throw new NoSuchFieldException("No field name"); try {/*from www . ja v a 2 s. c o m*/ Field field = clazz.getDeclaredField(fieldName); if (isInheritable(pack, field) && isTypeCompatible(fieldType, field.getType(), strictType)) return field; else return findInheritedField(clazz.getPackage(), clazz.getSuperclass(), fieldName, fieldType, strictType); } catch (NoSuchFieldException e) { return findInheritedField(clazz.getPackage(), clazz.getSuperclass(), fieldName, fieldType, strictType); } }