public static void setProperty(Object bean, Object name, Object value) { try { if (bean instanceof Class) { Field f = ((Class<?>) bean).getDeclaredField(name.toString()); f.set(null, value); }else if(bean instanceof Map ){ ((Map<Object,Object>)bean).put(name, value); } else { Class<?> filedClass = PropertyUtils.getPropertyType(bean, name.toString()); PropertyUtils.setProperty(bean, name.toString(),ExpressUtil.castObject(value, filedClass, false)); } } catch (Exception e) { throw new RuntimeException("不能访问" + bean + "的property:" + name,e); } }
/** * This method simply uses PojoPropertyUtilsBean logic to get the Class of a Class property. * This method does not have any of the logic needed to obtain the Class of an element of a Collection specified in * the DataDictionary. * * @param object An instance of the Class of which we're trying to get the property Class. * @param propertyName The name of the property. * @return * @throws IllegalAccessException * @throws NoSuchMethodException * @throws InvocationTargetException */ static public Class easyGetPropertyType(Object object, String propertyName) throws IllegalAccessException, NoSuchMethodException, InvocationTargetException { // FIXME (laran) This dependence should be inverted. Instead of having a core class // depend on PojoPropertyUtilsBean, which is in the web layer, the web layer // should depend downward to the core. return PropertyUtils.getPropertyType(object, propertyName); }
public static String getSimpleTypeName(Object targetObject, String propertyName) { String simpleTypeName = StringUtils.EMPTY; try { simpleTypeName = PropertyUtils.getPropertyType(targetObject, propertyName).getSimpleName(); } catch (Exception e) { LOG.debug(e); } return simpleTypeName; }
public static Class<?> getPropertyType(Object bean, String name) { try { return PropertyUtils.getPropertyType(bean, name); } catch (IllegalAccessException e) { e.printStackTrace(); } catch (InvocationTargetException e) { e.printStackTrace(); } catch (NoSuchMethodException e) { e.printStackTrace(); } return null; }
public Class getPropertyType(Map beans) throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, ClassNotFoundException { Object bean; if (beans.containsKey(beanKey)) { bean = beans.get(beanKey); // ZJ if (type == null) { return PropertyUtils.getPropertyType(bean, propertyName); } else { return Class.forName(type); } } return Object.class; }
/** * プロパティの型を取得します。 * * @param bean クラス情報を取得するためのオブジェクト * @param propertyName プロパティ名 * @return beanのクラスにあるプロパティの型 */ public static Class getPropertyClass(Object bean, String propertyName) { try { return PropertyUtils.getPropertyType(bean, propertyName); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e.getTargetException()); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } }
public static Class getPropertyType(Object object, String fieldName) { try { return PropertyUtils.getPropertyType(object, fieldName); } catch(Exception ex) { throw new JcrMappingException("Cannot access property " + fieldName, ex); } }
public static Class getPropertyType(Object object, String fieldName) { try { return PropertyUtils.getPropertyType(object, fieldName); } catch(Exception ex) { throw new JcrMappingException("Cannot access property " + fieldName, ex); } }
public static Class getPropertyType(Object bean, String name) { try { return org.apache.commons.beanutils.PropertyUtils.getPropertyType(bean, name); }catch(Exception e) { handleException(e); return null; } }
/** * Given an property on the main BO class, return the defined type of the ExternalizableBusinessObject. This will be used * by other code to determine the correct module service to call for the lookup. * * @param boClass * @param propertyName * @return */ protected Class<? extends ExternalizableBusinessObject> getExternalizableBusinessObjectClass(Class boClass, String propertyName) { try { return (Class<? extends ExternalizableBusinessObject>)PropertyUtils.getPropertyType( boClass.newInstance(), StringUtils.substringBeforeLast( propertyName, "." ) ); } catch (Exception e) { LOG.debug("Unable to determine type of property for " + boClass.getName() + "/" + propertyName, e ); } return null; }
public static void setProperty(Object bean, Object name, Object value) { try { if (bean instanceof Class) { Field f = ((Class<?>) bean).getDeclaredField(name.toString()); f.set(null, value); }else if(bean instanceof Map ){ ((Map<Object,Object>)bean).put(name, value); } else { Class<?> filedClass = PropertyUtils.getPropertyType(bean, name.toString()); PropertyUtils.setProperty(bean, name.toString(),ExpressUtil.castObject(value, filedClass, false)); } } catch (Exception e) { throw new RuntimeException("不能访问" + bean + "的property:" + name,e); } }
public void applyConfiguration(String prefix, Object obj) { String propertyPrefix = prefix + "."; for (String propertyName : properties.stringPropertyNames()) { if (propertyName.startsWith(propertyPrefix)) { String name = propertyName.substring(propertyPrefix.length()); try { Class<?> propertyType = PropertyUtils.getPropertyType(obj, name); if (String.class == propertyType) { PropertyUtils.setProperty(obj, name, properties.getProperty(propertyName)); } else if (Map.class == propertyType) { PropertyUtils.setProperty(obj, name, JSONUtils.json2map(properties.getProperty(propertyName))); } else { log.warn("Unhandled property {} of type {} on class {}", new String[] {name, propertyType.getName(), obj.getClass().getName()}); } } catch (Exception e) { log.warn("Unhandled property {} on class {}", name, obj.getClass().getName()); } } } }
/** * Check whether the given property represents a property within an EBO starting * with the sampleBo object given. This is used to determine if a criteria needs * to be applied to the EBO first, before sending to the normal lookup DAO. */ protected boolean isExternalBusinessObjectProperty(Object sampleBo, String propertyName) { try { if ( propertyName.indexOf( "." ) > 0 && !StringUtils.contains( propertyName, "add." ) ) { Class propertyClass = PropertyUtils.getPropertyType( sampleBo, StringUtils.substringBeforeLast( propertyName, "." ) ); if ( propertyClass != null ) { return ExternalizableBusinessObjectUtils.isExternalizableBusinessObjectInterface( propertyClass ); } else { if ( LOG.isDebugEnabled() ) { LOG.debug( "unable to get class for " + StringUtils.substringBeforeLast( propertyName, "." ) + " on " + sampleBo.getClass().getName() ); } } } } catch (Exception e) { LOG.debug("Unable to determine type of property for " + sampleBo.getClass().getName() + "/" + propertyName, e ); } return false; }
try propertyType = PropertyUtils.getPropertyType(bean, property);
Class<?> propertyType = PropertyUtils.getPropertyType(value, propertyName); Object propertyValue = PropertyUtils.getNestedProperty(value, propertyName); PropertyEditor editor = registry.findCustomEditor(propertyType, registryPropertyNamePrefix + propertyName);
public static void deserialize(PragmatachController pragmatachController, String json) throws PragmatachException { try { final JSONObject jSONObject = new JSONObject(json); final String[] names = JSONObject.getNames(jSONObject); if (null != names) { for (final String name : names) { /* * get the data we need */ final Class<?> type = PropertyUtils.getPropertyType(pragmatachController, name); if (null != type) { final String value = jSONObject.getString(name); final Object fieldValue = deserializeField(value, type); /* * set the field data */ PropertyUtils.setProperty(pragmatachController, name, fieldValue); } } } } catch (final Exception e) { throw new PragmatachException("Exception in deserialize", e); } }
/** * Populates a single parameter field based on a field conversion, given an event to populate data from * @param event the event which acts as the source of data * @param validation the validation to populate * @param conversion the conversion information */ protected void populateParameterFromEvent(AttributedDocumentEvent event, ValidationFieldConvertible conversion) { try { Class propertyClass = PropertyUtils.getPropertyType(event, conversion.getSourceEventProperty()); Object propertyValue = ObjectUtils.getPropertyValue(event, conversion.getSourceEventProperty()); if (propertyValue != null) { ObjectUtils.setObjectProperty(this, conversion.getTargetValidationProperty(), propertyClass, propertyValue); } } catch (FormatException fe) { throw new RuntimeException(fe); } catch (IllegalAccessException iae) { throw new RuntimeException(iae); } catch (InvocationTargetException ite) { throw new RuntimeException(ite); } catch (NoSuchMethodException nsme) { throw new RuntimeException(nsme); } } }
Class<?> targetType = PropertyUtils.getPropertyType(context, name); Object value = ConvertUtils.convert(text.getValue(), targetType); PropertyUtils.setProperty(context, name, value);
public DataMappingFieldDefinition getDataMappingFieldDefinition(FunctionalFieldDescription functionalFieldDescription) { BusinessObjectEntry businessObjectEntry = dataDictionaryService.getDataDictionary().getBusinessObjectEntry(functionalFieldDescription.getComponentClass()); String propertyType = ""; try { propertyType = PropertyUtils.getPropertyType(businessObjectEntry.getBusinessObjectClass().newInstance(), functionalFieldDescription.getPropertyName()).getSimpleName(); } catch (Exception e) { if (LOG.isDebugEnabled()) { LOG.debug("KfsBusinessObjectMetaDataServiceImpl unable to get type of property: " + functionalFieldDescription.getPropertyName(), e); } } return new DataMappingFieldDefinition(functionalFieldDescription, businessObjectEntry, businessObjectEntry.getAttributeDefinition(functionalFieldDescription.getPropertyName()), businessObjectMetaDataDao.getFieldMetaData(businessObjectEntry.getBusinessObjectClass(), functionalFieldDescription.getPropertyName()), propertyType, getReferenceComponentLabel(businessObjectEntry.getBusinessObjectClass(), functionalFieldDescription.getPropertyName())); }
: PropertyUtils.getSimpleProperty(bean, next); if (nestedBean == null) { Class clazz = PropertyUtils.getPropertyType(bean, next); PropertyUtils.setProperty(bean, next, nestedBean = clazz.newInstance());