本文整理匯總了Java中org.springframework.beans.BeanWrapper.getPropertyDescriptors方法的典型用法代碼示例。如果您正苦於以下問題:Java BeanWrapper.getPropertyDescriptors方法的具體用法?Java BeanWrapper.getPropertyDescriptors怎麽用?Java BeanWrapper.getPropertyDescriptors使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.beans.BeanWrapper
的用法示例。
在下文中一共展示了BeanWrapper.getPropertyDescriptors方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: toMap
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
private Map<String, String> toMap(Object object) {
BeanWrapper wrapper = new BeanWrapperImpl(object);
PropertyDescriptor[] descriptors = wrapper.getPropertyDescriptors();
Map<String, String> properties = new HashMap<>(descriptors.length);
for (PropertyDescriptor d : descriptors) {
if (d.getWriteMethod() == null) {
continue;
}
String name = d.getName();
Object value = wrapper.getPropertyValue(name);
properties.put(name, value.toString());
}
return properties;
}
示例2: generateObject
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
private void generateObject(String prefix, Object target) {
BeanWrapper beanWrapper = new BeanWrapperImpl(target);
PropertyDescriptor[] descriptors = beanWrapper.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
if (descriptor.getWriteMethod() == null) {
continue;
}
String name = descriptor.getName();
Class<?> type = descriptor.getPropertyType();
Method readMethod = descriptor.getReadMethod();
TypeDescriptor typeDescriptor = beanWrapper.getPropertyTypeDescriptor(name);
Required required = typeDescriptor.getAnnotation(Required.class);
Object value = getValue(type, prefix, name, readMethod);
if (value != null) {
beanWrapper.setPropertyValue(name, value);
} else if (required != null) {
throw new RuntimeException(String.format("property [%s]'s value can't be null!please check your config!", name));
}
}
}
示例3: generateConnectorConfigurationSchema
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
private PrismSchema generateConnectorConfigurationSchema(ConnectorStruct struct) {
Class<? extends ConnectorInstance> connectorClass = struct.connectorClass;
PropertyDescriptor connectorConfigurationProp = UcfUtil.findAnnotatedProperty(connectorClass, ManagedConnectorConfiguration.class);
PrismSchema connectorSchema = new PrismSchemaImpl(struct.connectorObject.getNamespace(), prismContext);
// Create configuration type - the type used by the "configuration" element
PrismContainerDefinitionImpl<?> configurationContainerDef = ((PrismSchemaImpl) connectorSchema).createPropertyContainerDefinition(
ResourceType.F_CONNECTOR_CONFIGURATION.getLocalPart(),
SchemaConstants.CONNECTOR_SCHEMA_CONFIGURATION_TYPE_LOCAL_NAME);
Class<?> configurationClass = connectorConfigurationProp.getPropertyType();
BeanWrapper configurationClassBean = new BeanWrapperImpl(configurationClass);
for (PropertyDescriptor prop: configurationClassBean.getPropertyDescriptors()) {
if (!UcfUtil.hasAnnotation(prop, ConfigurationProperty.class)) {
continue;
}
ItemDefinition<?> itemDef = createPropertyDefinition(configurationContainerDef, prop);
LOGGER.trace("Configuration item definition for {}: {}", prop.getName(), itemDef);
}
return connectorSchema;
}
示例4: findAnnotatedProperty
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public static PropertyDescriptor findAnnotatedProperty(BeanWrapper connectorBean, Class<? extends Annotation> annotationClass) {
for (PropertyDescriptor prop: connectorBean.getPropertyDescriptors()) {
if (hasAnnotation(prop, annotationClass)) {
return prop;
}
}
return null;
}
示例5: findFieldWithAnnotation
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public static Field findFieldWithAnnotation(Class<?> domainObjClass, Class<? extends Annotation> annotationClass)
throws SecurityException, BeansException {
BeanWrapper wrapper = new BeanWrapperImpl(domainObjClass);
PropertyDescriptor[] descriptors = wrapper.getPropertyDescriptors();
for (PropertyDescriptor descriptor : descriptors) {
Field candidate = getField(domainObjClass, descriptor.getName());
if (candidate != null) {
if (candidate.getAnnotation(annotationClass) != null) {
return candidate;
}
}
}
for (Field field : getAllFields(domainObjClass)) {
if (field.getAnnotation(annotationClass) != null) {
return field;
}
}
return null;
}
示例6: convert
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
private static Map<String, Object> convert(Object value, ConversionService conversionService) {
BeanWrapper bean = new BeanWrapperImpl(value);
PropertyDescriptor[] properties = bean.getPropertyDescriptors();
Map<String, Object> convertedValue = new HashMap<>(properties.length);
for (int i = 0; i < properties.length; i++) {
String name = properties[i].getName();
Object propertyValue = bean.getPropertyValue(name);
if (propertyValue != null
&& conversionService.canConvert(propertyValue.getClass(), String.class)) {
TypeDescriptor source = bean.getPropertyTypeDescriptor(name);
String convertedPropertyValue =
(String) conversionService.convert(propertyValue, source, TYPE_STRING);
convertedValue.put(name, convertedPropertyValue);
}
}
return convertedValue;
}
示例7: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null)
emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例8: testUseBlueprintExceptions
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public void testUseBlueprintExceptions() throws Exception {
OsgiServiceProxyFactoryBean fb = new OsgiServiceProxyFactoryBean();
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(fb);
String propertyName = "useBlueprintExceptions";
for (PropertyDescriptor desc : wrapper.getPropertyDescriptors()) {
System.out.println(desc.getName());
}
Class type = wrapper.getPropertyType(propertyName);
System.out.println("type is " + type);
assertTrue(wrapper.isWritableProperty(propertyName));
assertFalse(wrapper.isReadableProperty(propertyName));
}
示例9: unsatisfiedNonSimpleProperties
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
/**
* Return an array of non-simple bean properties that are unsatisfied.
* These are probably unsatisfied references to other beans in the
* factory. Does not include simple properties like primitives or Strings.
* @param mbd the merged bean definition the bean was created with
* @param bw the BeanWrapper the bean was created with
* @return an array of bean property names
* @see org.springframework.beans.BeanUtils#isSimpleProperty
*/
protected String[] unsatisfiedNonSimpleProperties(AbstractBeanDefinition mbd, BeanWrapper bw) {
Set<String> result = new TreeSet<String>();
PropertyValues pvs = mbd.getPropertyValues();
PropertyDescriptor[] pds = bw.getPropertyDescriptors();
for (PropertyDescriptor pd : pds) {
if (pd.getWriteMethod() != null && !isExcludedFromDependencyCheck(pd) && !pvs.contains(pd.getName()) &&
!BeanUtils.isSimpleProperty(pd.getPropertyType())) {
result.add(pd.getName());
}
}
return StringUtils.toStringArray(result);
}
示例10: toEntity
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public FullEntity<? extends IncompleteKey> toEntity(Object object, Key key) {
FullEntity.Builder<? extends IncompleteKey> builder;
if (key == null) {
builder = Entity.newBuilder();
}
else {
builder = FullEntity.newBuilder(key);
}
if (object instanceof Map) {
for (Map.Entry<String, Object> entry : ((Map<String, Object>) object)
.entrySet()) {
setEntityValue(builder, entry.getKey(), entry.getValue());
}
}
else {
BeanWrapper beanWrapper = PropertyAccessorFactory
.forBeanPropertyAccess(object);
for (PropertyDescriptor propertyDescriptor : beanWrapper
.getPropertyDescriptors()) {
String name = propertyDescriptor.getName();
if ("class".equals(name))
continue;
setEntityValue(builder, name, beanWrapper.getPropertyValue(name));
}
}
return builder.build();
}
示例11: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public static String[] getNullPropertyNames(Object source, Set<String> notCopiedAttributes) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet(notCopiedAttributes);
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例12: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
/**
* Returns an array of fields that have attributes with <i>null</i> value in
* the desired object.
*
* @param source
* {@link Object} updated object.
* @return {@link String} array of fields that have attributes with
* <i>null</i> value in the desired object.
*/
private static String[] getNullPropertyNames(Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<String>();
for (java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) {
emptyNames.add(pd.getName());
}
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}
示例13: introspectPropertiesOfObject
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
/**
* Return String representations of the values of all of the properties of the object.
*
* @param errors Map of error codes and error messages if a problem is encountered.
* @param object object to introspect
* @return String representations of the values of all of the object
*/
public static Map<String, Object> introspectPropertiesOfObject(final Map<OperationErrorCode, String> errors,
final Object object) {
Map<String, Object> values = new HashMap<>();
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(object);
for (PropertyDescriptor des : wrapper.getPropertyDescriptors()) {
if (RESERVED_WORDS.contains(des.getName())) {
continue;
}
try {
Method readMethod = des.getReadMethod();
if (readMethod != null) {
Object readObject = readMethod.invoke(object);
if (readObject != null) {
readObject.toString();
values.put(des.getName(), readObject);
} else {
errors.put(OperationErrorCode.ReadNullObject, readMethod.toString());
continue;
}
}
} catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) {
errors.put(OperationErrorCode.NotReadableField, e.toString());
}
}
return values;
}
示例14: introspectProperty
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
/**
* Return the value of the specified property.
*
* @param <T> Type of the returned property.
* @param propertyName Name of the property.
* @param errors Map of error codes and error messages if a problem is encountered.
* @param fibre fibre to introspect
* @param context query context
* @return Value of the specified property.
*/
@JsonIgnore
public static <T> T introspectProperty(final String propertyName, final Fibre fibre,
final Map<OperationErrorCode, String> errors, final OperationContext context) {
if (RESERVED_WORDS.contains(propertyName)) {
errors.put(OperationErrorCode.NotReadableField, propertyName + " is not a valid property");
return null;
}
PropertyResult<T> entityPropertyResult = getEntityProperty(propertyName, fibre, errors, context);
if (entityPropertyResult.isFound()) {
return entityPropertyResult.getReadValue();
} else {
// Try introspection
IntrospectionContext iContext = fibre.getIntrospectionContextForProperty(propertyName);
T readValue = null;
BeanWrapper wrapper = PropertyAccessorFactory.forBeanPropertyAccess(iContext.getObject());
for (PropertyDescriptor des : wrapper.getPropertyDescriptors()) {
if (des.getName().equalsIgnoreCase(iContext.getProperty())) {
try {
Method readMethod = des.getReadMethod();
if (readMethod != null) {
readValue = (T) readMethod.invoke(iContext.getObject());
} else {
errors.put(OperationErrorCode.NotReadableField, propertyName + " is not readable");
}
} catch (IllegalAccessException | InvocationTargetException e) {
errors.put(OperationErrorCode.NotReadableField, e.toString());
}
break;
}
}
return readValue;
}
}
示例15: getNullPropertyNames
import org.springframework.beans.BeanWrapper; //導入方法依賴的package包/類
public static String[] getNullPropertyNames (Object source) {
final BeanWrapper src = new BeanWrapperImpl(source);
java.beans.PropertyDescriptor[] pds = src.getPropertyDescriptors();
Set<String> emptyNames = new HashSet<>();
for(java.beans.PropertyDescriptor pd : pds) {
Object srcValue = src.getPropertyValue(pd.getName());
if (srcValue == null) emptyNames.add(pd.getName());
}
String[] result = new String[emptyNames.size()];
return emptyNames.toArray(result);
}