當前位置: 首頁>>代碼示例>>Java>>正文


Java BeanWrapper.getPropertyDescriptors方法代碼示例

本文整理匯總了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;
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:18,代碼來源:RdbmsDataSourceBeanDefinitionBuilder.java

示例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));
        }
    }
}
 
開發者ID:lodsve,項目名稱:lodsve-framework,代碼行數:25,代碼來源:PropertiesConfigurationFactory.java

示例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;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:27,代碼來源:ConnectorFactoryBuiltinImpl.java

示例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;
}
 
開發者ID:Pardus-Engerek,項目名稱:engerek,代碼行數:9,代碼來源:UcfUtil.java

示例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;
}
 
開發者ID:paulcwarren,項目名稱:spring-content,代碼行數:23,代碼來源:BeanUtils.java

示例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;
  }
 
開發者ID:DISID,項目名稱:springlets,代碼行數:21,代碼來源:ConvertedDatatablesData.java

示例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);
}
 
開發者ID:zouzhirong,項目名稱:configx,代碼行數:14,代碼來源:BeanUtils.java

示例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));
}
 
開發者ID:eclipse,項目名稱:gemini.blueprint,代碼行數:13,代碼來源:BlueprintFieldsTest.java

示例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);
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:22,代碼來源:AbstractAutowireCapableBeanFactory.java

示例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();
}
 
開發者ID:tkob,項目名稱:spring-data-gclouddatastore,代碼行數:30,代碼來源:Marshaller.java

示例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);
}
 
開發者ID:JUGIstanbul,項目名稱:second-opinion-api,代碼行數:16,代碼來源:ObjectUtils.java

示例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);
}
 
開發者ID:brianmcca1,項目名稱:ResidentialWay,代碼行數:23,代碼來源:ApplicationHelper.java

示例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;
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:35,代碼來源:FibreIntrospectionUtils.java

示例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;
    }
}
 
開發者ID:HewlettPackard,項目名稱:loom,代碼行數:44,代碼來源:FibreIntrospectionUtils.java

示例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);
}
 
開發者ID:finefuture,項目名稱:data-migration,代碼行數:13,代碼來源:BeanUtil.java


注:本文中的org.springframework.beans.BeanWrapper.getPropertyDescriptors方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。