本文整理汇总了Java中java.beans.PropertyDescriptor.getPropertyType方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDescriptor.getPropertyType方法的具体用法?Java PropertyDescriptor.getPropertyType怎么用?Java PropertyDescriptor.getPropertyType使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.PropertyDescriptor
的用法示例。
在下文中一共展示了PropertyDescriptor.getPropertyType方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getBeanValue
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* 将ResultSet转换为指定class的Bean.
* @param rs ResultSet实例
* @param rsmd ResultSet元数据
* @param beanClass 空属性的Bean的class
* @param propMap Bean属性对应的Map
* @param <T> 泛型方法
* @return 值
* @throws IllegalAccessException IllegalAccessException
* @throws SQLException SQLException
* @throws InvocationTargetException InvocationTargetException
* @throws InstantiationException InstantiationException
*/
public static <T> T getBeanValue(ResultSet rs, ResultSetMetaData rsmd, Class<T> beanClass,
Map<String, PropertyDescriptor> propMap) throws IllegalAccessException, SQLException,
InvocationTargetException, InstantiationException {
T bean = beanClass.newInstance();
for (int i = 0, cols = rsmd.getColumnCount(); i < cols; i++) {
String columnName = JdbcHelper.getColumn(rsmd, i + 1);
if (propMap.containsKey(columnName)) {
PropertyDescriptor prop = propMap.get(columnName);
// 获取并调用setter方法.
Method propSetter = prop.getWriteMethod();
if (propSetter == null || propSetter.getParameterTypes().length != 1) {
log.warn("类'{}'的属性'{}'没有标准的setter方法", beanClass.getName(), columnName);
continue;
}
// 得到属性类型并将该数据库列值转成Java对应类型的值
Class<?> propType = prop.getPropertyType();
Object value = FieldHandlerChain.newInstance().getColumnValue(rs, i + 1, propType);
propSetter.invoke(bean, value);
}
}
return bean;
}
示例2: main
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static void main(String[] args) {
PropertyDescriptor pd = BeanUtils.getPropertyDescriptor(Sub.class, "foo");
Class<?> type = pd.getPropertyType();
int[] array = new int[10];
while (array != null) {
try {
array = new int[array.length + array.length];
}
catch (OutOfMemoryError error) {
array = null;
}
}
if (type != pd.getPropertyType()) {
throw new Error("property type is changed");
}
}
示例3: applyValue
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static void applyValue ( final Object target, final PropertyDescriptor pd, final Variant value ) throws OperationException, IllegalArgumentException, IllegalAccessException, InvocationTargetException
{
// ensure for the following calls that the PD has a write method
final Method m = pd.getWriteMethod ();
if ( m == null )
{
throw new OperationException ( String.format ( "Property '%s' is write protected", pd.getName () ) );
}
final Class<?> targetType = pd.getPropertyType ();
if ( targetType.isAssignableFrom ( Variant.class ) )
{
// direct set using variant type
m.invoke ( target, value );
return;
}
// now we need to convert
if ( !applyValueAsObject ( target, pd, value.getValue () ) )
{
throw new OperationException ( String.format ( "There is no way to convert '%s' to '%s'", value, targetType ) );
}
}
示例4: equals
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* Compare the given {@link PropertyDescriptor} against the given {@link Object} and
* return {@code true} if they are objects are equivalent, i.e. both are {@code
* PropertyDescriptor}s whose read method, write method, property types, property
* editor and flags are equivalent.
* @see PropertyDescriptor#equals(Object)
*/
public static boolean equals(PropertyDescriptor pd1, Object obj) {
if (pd1 == obj) {
return true;
}
if (obj != null && obj instanceof PropertyDescriptor) {
PropertyDescriptor pd2 = (PropertyDescriptor) obj;
if (!compareMethods(pd1.getReadMethod(), pd2.getReadMethod())) {
return false;
}
if (!compareMethods(pd1.getWriteMethod(), pd2.getWriteMethod())) {
return false;
}
if (pd1.getPropertyType() == pd2.getPropertyType() &&
pd1.getPropertyEditorClass() == pd2.getPropertyEditorClass() &&
pd1.isBound() == pd2.isBound() && pd1.isConstrained() == pd2.isConstrained()) {
return true;
}
}
return false;
}
示例5: mapping
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* @param object
* @param parameter property
* @throws IllegalAccessException
* @throws InvocationTargetException
*/
public static void mapping(Object object, Map<String, ?> parameter) throws IllegalAccessException,
InvocationTargetException {
PropertyDescriptor[] pds = getDescriptors(object.getClass());
for (PropertyDescriptor pd : pds) {
Object obj = parameter.get(pd.getName());
Object value = obj;
Class<?> cls = pd.getPropertyType();
if (obj instanceof String) {
String string = (String) obj;
if (!StringUtil.isEmpty(string)) {
string = ConfigUtil.filter(string);
}
if (isPrimitiveType(cls)) {
value = convert(cls, string);
}
} else if (obj instanceof BeanConfig) {
value = createBean((BeanConfig) obj);
} else if (obj instanceof BeanConfig[]) {
List<Object> list = new ArrayList<>();
for (BeanConfig beanconfig : (BeanConfig[]) obj) {
list.add(createBean(beanconfig));
}
value = list.toArray();
}
if (cls != null && value != null) {
Method method = pd.getWriteMethod();
if (method != null) {
method.invoke(object, value);
}
}
}
}
示例6: getProjections
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
protected Projection[] getProjections(me.snowdrop.data.core.spi.Query<T> query) {
ProjectionInformation pi = query.getProjectionInformation();
if (pi != null && pi.isClosed()) {
List<PropertyDescriptor> properties = pi.getInputProperties();
Projection[] projections = new Projection[properties.size()];
for (int i = 0; i < projections.length; i++) {
PropertyDescriptor pd = properties.get(i);
String property = pd.getName();
projections[i] = new SimpleProjection(getFieldName(property), pd.getPropertyType());
}
return projections;
}
return null;
}
示例7: getDescriptors
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* @param clazz
* @return
*/
private static PropertyDescriptor[] getDescriptors(Class<?> clazz) {
PropertyDescriptor[] pds;
List<PropertyDescriptor> list;
PropertyDescriptor[] pds2 = DESCRIPTORS.get(clazz);
//clazz init for first time?
if (null == pds2) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
pds = beanInfo.getPropertyDescriptors();
list = new ArrayList<>();
//add property it type is not null
for (PropertyDescriptor pd : pds) {
if (null != pd.getPropertyType()) {
list.add(pd);
}
}
pds2 = new PropertyDescriptor[list.size()];
list.toArray(pds2);
} catch (IntrospectionException ie) {
LOGGER.info("ParameterMappingError", ie);
pds2 = new PropertyDescriptor[0];
}
}
DESCRIPTORS.put(clazz, pds2);
return (pds2);
}
示例8: compare
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static boolean compare(PropertyDescriptor pd1, PropertyDescriptor pd2) {
if (!compare(pd1.getReadMethod(), pd2.getReadMethod())) {
System.out.println("read methods not equal");
return false;
}
if (!compare(pd1.getWriteMethod(), pd2.getWriteMethod())) {
System.out.println("write methods not equal");
return false;
}
if (pd1.getPropertyType() != pd2.getPropertyType()) {
System.out.println("property type not equal");
return false;
}
if (pd1.getPropertyEditorClass() != pd2.getPropertyEditorClass()) {
System.out.println("property editor class not equal");
return false;
}
if (pd1.isBound() != pd2.isBound()) {
System.out.println("bound value not equal");
return false;
}
if (pd1.isConstrained() != pd2.isConstrained()) {
System.out.println("constrained value not equal");
return false;
}
return true;
}
示例9: EntityField
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
* 构造方法
*
* @param field 字段
* @param propertyDescriptor 字段name对应的property
*/
public EntityField(Field field, PropertyDescriptor propertyDescriptor) {
if (field != null) {
this.field = field;
this.name = field.getName();
this.javaType = field.getType();
}
if (propertyDescriptor != null) {
this.name = propertyDescriptor.getName();
this.setter = propertyDescriptor.getWriteMethod();
this.getter = propertyDescriptor.getReadMethod();
this.javaType = propertyDescriptor.getPropertyType();
}
}
示例10: getFieldList
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static void getFieldList(Class clazz, List<String> fieldList, String prefix, Deque<Class> classStack) throws IntrospectionException {
//To avoid recursion, bail out if the input Class has already been introspected
if (classStack.contains(clazz)) {
if (log.isDebugEnabled())
log.debug("Fields from " + clazz + " prefixed by " + prefix + " will be ignored, since the class has already been introspected as per the stack " + classStack);
return;
} else
classStack.addFirst(clazz);
//Introspect the input Class
BeanInfo beanInfo = Introspector.getBeanInfo(clazz);
if (beanInfo != null) {
PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
if (pds != null) {
for (PropertyDescriptor pd : pds) {
if (pd.getReadMethod() != null && pd.getWriteMethod() != null) {
String name = pd.getName();
String qualifieldName = prefix == null || prefix.length() == 0 ? name : prefix + '.' + name;
Class type = pd.getPropertyType();
if (type.isArray())
type = type.getComponentType();
if (type == String.class || type == Boolean.class || Number.class.isAssignableFrom(type) || IDateBase.class.isAssignableFrom(type) || Currency.class.isAssignableFrom(type) || type.isPrimitive() || type.isEnum())
fieldList.add(qualifieldName);
else
getFieldList(type, fieldList, qualifieldName, classStack);
}
}
}
}
classStack.removeFirst();
}
示例11: getPropertyType
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static Class<?> getPropertyType(Class<?> type, boolean indexed) {
PropertyDescriptor pd = BeanUtils.findPropertyDescriptor(type, indexed ? "index" : "value");
if (pd instanceof IndexedPropertyDescriptor) {
IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
return ipd.getIndexedPropertyType();
}
return pd.getPropertyType();
}
示例12: PropertyInfo
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private PropertyInfo(PropertyDescriptor propertyDescriptor, int propertyIndex) {
super(
propertyDescriptor.getName(),
propertyIndex,
propertyDescriptor.getPropertyType());
readMethodName = Optional.ofNullable(propertyDescriptor.getReadMethod())
.map(prop -> prop.getName())
.orElse(null);
writeMethodName = Optional.ofNullable(propertyDescriptor.getWriteMethod())
.map(prop -> prop.getName())
.orElse(null);
}
示例13: updateSymbols
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public void updateSymbols() throws Exception {
if (!compilablePropertySourceValuesMap.isEmpty()) {
PropertyDescriptor[] propertyDescriptors = CachedIntrospector.getBeanInfo(getClass()).getPropertyDescriptors();
for (Entry<String, Object> propertySource : compilablePropertySourceValuesMap.entrySet()) {
String propertyName = propertySource.getKey();
Object propertyValue = propertySource.getValue();
PropertyDescriptor propertyDescriptor = findPropertyDescriptor(propertyDescriptors, propertyName);
Class<?> propertyType = propertyDescriptor.getPropertyType();
Object newValue = compileProperty(propertyType, propertyName, propertyValue);
propertyDescriptor.getWriteMethod().invoke(this, newValue);
}
}
}
示例14: hasPD
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static boolean hasPD(PropertyDescriptor pd) {
if (null == pd.getPropertyType()) {
return false;
}
return (null != pd.getReadMethod())
|| (null != pd.getWriteMethod());
}
示例15: BeanProperty
import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public BeanProperty(Class<?> owner, PropertyDescriptor descriptor) {
this.owner = owner;
this.descriptor = descriptor;
this.type = descriptor.getPropertyType();
}