List of usage examples for java.lang.reflect Field toString
public String toString()
From source file:net.mindengine.blogix.db.readers.ObjectReader.java
private Object convertFieldValue(String fieldValue, Field field) { if (fieldValue == null) { return null; }/*from w ww . jav a 2 s. c om*/ Class<?> type = field.getType(); try { return convertStringValueToType(fieldValue, type); } catch (Exception e) { throw new IllegalArgumentException("Cannot convert value '" + StringUtils.abbreviate(fieldValue, 20) + "' to field " + field.toString(), e); } }
From source file:org.apache.hadoop.hive.ql.stats.TestStatsUtils.java
@Test public void testPrimitiveSizeEstimations() throws Exception { HiveConf conf = new HiveConf(); Set<String> exclusions = Sets.newHashSet(); exclusions.add(serdeConstants.VOID_TYPE_NAME); exclusions.add(serdeConstants.LIST_TYPE_NAME); exclusions.add(serdeConstants.MAP_TYPE_NAME); exclusions.add(serdeConstants.STRUCT_TYPE_NAME); exclusions.add(serdeConstants.UNION_TYPE_NAME); Field[] serdeFields = serdeConstants.class.getFields(); for (Field field : serdeFields) { if (!Modifier.isStatic(field.getModifiers())) { continue; }//from ww w .ja v a 2 s .co m if (!field.getName().endsWith("_TYPE_NAME")) { continue; } String typeName = (String) FieldUtils.readStaticField(field); if (exclusions.contains(typeName)) { continue; } long siz = StatsUtils.getSizeOfPrimitiveTypeArraysFromType(typeName, 3, conf); assertNotEquals(field.toString(), 0, siz); } }
From source file:sf.net.experimaestro.manager.js.JSBaseObject.java
@Override public Object get(String name, Scriptable start) { // Search for a function MethodFunction function = getMethodFunction(name); if (!function.isEmpty()) { return new JavaScriptFunction(function); }/* www . j a va 2 s . c o m*/ // Search for a property final Field field = classDescription.getFields().get(name); if (field != null) { try { return field.get(this); } catch (IllegalAccessException e) { throw new XPMRhinoException("Illegal access to field [%s]", field.toString()); } } return NOT_FOUND; }
From source file:sf.net.experimaestro.manager.js.JSBaseObject.java
@Override public void put(String name, Scriptable start, Object value) { final Field field = classDescription.getFields().get(name); if (field != null) { if (classDescription.getFields().containsKey(name)) { try { field.set(this, value); return; } catch (IllegalAccessException e) { throw new XPMRhinoException("Illegal access to field [%s]", field.toString()); }/*w w w . java2s . c o m*/ } } throw new XPMRhinoException("Setting the value of a sealed object (" + getClassName() + ")"); }
From source file:org.dd4t.databind.builder.json.JsonModelConverter.java
private <T extends BaseViewModel> void deserializeGeneric(final T model, final JsonNode currentField, final Field f, final FieldType fieldType) throws IOException, IllegalAccessException, SerializationException { LOG.debug("Field Type: " + f.getType().getCanonicalName()); if (currentField.has(DataBindConstants.COMPONENT_TYPE)) { LOG.debug("Building a linked Component or Multimedia component"); final Component component = databinder.buildComponent(currentField, databinder.getConcreteComponentImpl()); setFieldValue(model, f, component, fieldType); } else {/* www .j a va 2s . c o m*/ final org.dd4t.contentmodel.Field renderedField = JsonUtils.renderComponentField(currentField, this.concreteFieldImpl); LOG.trace("Rendered Field is: {} ", renderedField.toString()); LOG.debug("Field Type is: {}", f.getType().toString()); setFieldValue(model, f, renderedField, fieldType); } }
From source file:org.gradle.model.internal.manage.schema.extract.ManagedImplTypeSchemaExtractionStrategySupport.java
private void ensureNoInstanceScopedFields(ModelSchemaExtractionContext<?> extractionContext, Class<?> typeClass) { Class<?> superClass = typeClass.getSuperclass(); if (superClass != null && !superClass.equals(Object.class)) { ensureNoInstanceScopedFields(extractionContext, superClass); }//from w w w. j a v a2s . co m List<Field> declaredFields = Arrays.asList(typeClass.getDeclaredFields()); Iterable<Field> instanceScopedFields = Iterables.filter(declaredFields, new Predicate<Field>() { public boolean apply(Field field) { return !Modifier.isStatic(field.getModifiers()) && !field.getName().equals("metaClass"); } }); ImmutableSortedSet<String> sortedDescriptions = ImmutableSortedSet .copyOf(Iterables.transform(instanceScopedFields, new Function<Field, String>() { public String apply(Field field) { return field.toString(); } })); if (!sortedDescriptions.isEmpty()) { throw new InvalidManagedModelElementTypeException(extractionContext, "instance scoped fields are not allowed (found fields: " + Joiner.on(", ").join(sortedDescriptions) + ")."); } }
From source file:kelly.core.injector.AbstractSpringInjector.java
@Override public final void inject(Object bean) { if (bean == null) return;/*from www .j a v a 2 s. c o m*/ Field[] fields = getFieldsIncludingSuperclass(bean); for (Field field : fields) { Inject inject = field.getAnnotation(Inject.class); boolean nullable = field.getAnnotation(Nullable.class) != null; if (inject == null) { continue; } else { String beanName = inject.value(); Object com = null; if ("".equals(beanName)) { // com = getBeanFromApplicationContext(field.getType()); } else { com = getBeanFromApplicationContext(beanName); } if (com == null) { if (nullable) { continue; } else { throw new InjectException("Inject failed for field " + field.toString()); } } ReflectionUtils.makeAccessible(field); ReflectionUtils.setField(field, bean, com); } } }
From source file:org.openengsb.core.persistence.internal.SerializableChecker.java
private void checkFields(Object obj, ObjectStreamClass desc) { int numFields; try {//from w w w.jav a2s . co m numFields = (Integer) getNumObjFieldsMethod.invoke(desc, (Object[]) null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } if (numFields > 0) { int numPrimFields; ObjectStreamField[] fields = desc.getFields(); Object[] objVals = new Object[numFields]; numPrimFields = fields.length - objVals.length; try { getObjFieldValuesMethod.invoke(desc, obj, objVals); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } for (int i = 0; i < objVals.length; i++) { if (objVals[i] instanceof String || objVals[i] instanceof Number || objVals[i] instanceof Date || objVals[i] instanceof Boolean || objVals[i] instanceof Class) { continue; } // Check for circular reference. if (checked.containsKey(objVals[i])) { continue; } ObjectStreamField fieldDesc = fields[numPrimFields + i]; Field field; try { field = (Field) getFieldMethod.invoke(fieldDesc, (Object[]) null); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } field.getName(); simpleName = field.getName(); fieldDescription = field.toString(); check(objVals[i]); } } }
From source file:org.apache.camel.dataformat.bindy.BindyFixedLengthFactory.java
public void initAnnotatedFields() { for (Class<?> cl : models) { List<Field> linkFields = new ArrayList<Field>(); if (LOG.isDebugEnabled()) { LOG.debug("Class retrieved: " + cl.getName()); }// w ww . j av a 2 s . co m for (Field field : cl.getDeclaredFields()) { DataField dataField = field.getAnnotation(DataField.class); if (dataField != null) { if (LOG.isDebugEnabled()) { LOG.debug("Position defined in the class: " + cl.getName() + ", position: " + dataField.pos() + ", Field: " + dataField.toString()); } if (dataField.required()) { ++numberMandatoryFields; } else { ++numberOptionalFields; } dataFields.put(dataField.pos(), dataField); annotatedFields.put(dataField.pos(), field); } Link linkField = field.getAnnotation(Link.class); if (linkField != null) { if (LOG.isDebugEnabled()) { LOG.debug("Class linked: " + cl.getName() + ", Field: " + field.toString()); } linkFields.add(field); } } if (!linkFields.isEmpty()) { annotatedLinkFields.put(cl.getName(), linkFields); } totalFields = numberMandatoryFields + numberOptionalFields; if (LOG.isDebugEnabled()) { LOG.debug("Number of optional fields: " + numberOptionalFields); LOG.debug("Number of mandatory fields: " + numberMandatoryFields); LOG.debug("Total: " + totalFields); } } }