当前位置: 首页>>代码示例>>Java>>正文


Java PropertyDescriptor.getName方法代码示例

本文整理汇总了Java中java.beans.PropertyDescriptor.getName方法的典型用法代码示例。如果您正苦于以下问题:Java PropertyDescriptor.getName方法的具体用法?Java PropertyDescriptor.getName怎么用?Java PropertyDescriptor.getName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在java.beans.PropertyDescriptor的用法示例。


在下文中一共展示了PropertyDescriptor.getName方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: transBean2Map

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static Map<String, Object> transBean2Map(Object obj) {
	Map<String, Object> map = newHashMap();
	if (obj == null) {
		return map;
	}
	try {
		BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor property : propertyDescriptors) {
			String key = property.getName();
			// 过滤class属性
			if (!key.equals("class")) {
				// 得到property对应的getter方法
				Method getter = property.getReadMethod();
				Object value = getter.invoke(obj);
				map.put(key, value);
			}
		}
	} catch (Exception e) {
		System.out.println("transBean2Map Error " + e);
	}
	return map;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:24,代码来源:InstanceUtil.java

示例2: transBean2Map

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static Map<String, Object> transBean2Map(Object obj) {
    Map<String, Object> map = newHashMap();
    if (obj == null) {
        return map;
    }
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor property : propertyDescriptors) {
            String key = property.getName();
            // 过滤class属性
            if (!key.equals("class")) {
                // 得到property对应的getter方法
                Method getter = property.getReadMethod();
                Object value = getter.invoke(obj);
                map.put(key, value);
            }
        }
    } catch (Exception e) {
        logger.error("transBean2Map Error " + e);
    }
    return map;
}
 
开发者ID:iBase4J,项目名称:iBase4J-Common,代码行数:24,代码来源:InstanceUtil.java

示例3: mapToBean

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static <T> T mapToBean(Map<String, Object> map, Class<T> clazz) {
    if (map == null || map.isEmpty()) {
        return null;
    }

    try {
        T bean = clazz.newInstance();
        Map<String, PropertyDescriptor> descriptors = getCachePropertyDescriptors(clazz);
        for (PropertyDescriptor descriptor : descriptors.values()) {
            String propertyName = descriptor.getName();
            if (map.containsKey(propertyName)) {
                Object object = map.get(propertyName);
                if (object == null) { continue; }
                if (object instanceof String) {
                    object = stringConvertTo(object.toString(), descriptor.getPropertyType());
                }
                descriptor.getWriteMethod().invoke(bean, object);
            }
        }
        return bean;
    } catch (Exception e) {
        throw new BeanConverterException(e);
    }
}
 
开发者ID:warlock-china,项目名称:azeroth,代码行数:25,代码来源:BeanCopyUtils.java

示例4: checkDependencies

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
 * Perform a dependency check that all properties exposed have been set,
 * if desired. Dependency checks can be objects (collaborating beans),
 * simple (primitives and String), or all (both).
 * @param beanName the name of the bean
 * @param mbd the merged bean definition the bean was created with
 * @param pds the relevant property descriptors for the target bean
 * @param pvs the property values to be applied to the bean
 * @see #isExcludedFromDependencyCheck(java.beans.PropertyDescriptor)
 */
protected void checkDependencies(
		String beanName, AbstractBeanDefinition mbd, PropertyDescriptor[] pds, PropertyValues pvs)
		throws UnsatisfiedDependencyException {

	int dependencyCheck = mbd.getDependencyCheck();
	for (PropertyDescriptor pd : pds) {
		if (pd.getWriteMethod() != null && !pvs.contains(pd.getName())) {
			boolean isSimple = BeanUtils.isSimpleProperty(pd.getPropertyType());
			boolean unsatisfied = (dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_ALL) ||
					(isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_SIMPLE) ||
					(!isSimple && dependencyCheck == RootBeanDefinition.DEPENDENCY_CHECK_OBJECTS);
			if (unsatisfied) {
				throw new UnsatisfiedDependencyException(mbd.getResourceDescription(), beanName, pd.getName(),
						"Set this property value or disable dependency checking for this bean.");
			}
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:29,代码来源:AbstractAutowireCapableBeanFactory.java

示例5: _clonePropertyDescriptor

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static PropertyDescriptor _clonePropertyDescriptor(
  PropertyDescriptor oldDescriptor
  )
{
  try
  {
    PropertyDescriptor newDescriptor = new PropertyDescriptor(
                                           oldDescriptor.getName(),
                                           oldDescriptor.getReadMethod(),
                                           oldDescriptor.getWriteMethod());

    // copy the rest of the attributes
    _copyPropertyDescriptor(oldDescriptor, newDescriptor);

    return newDescriptor;
  }
  catch (Exception e)
  {
    _LOG.severe(e);
    return null;
  }
}
 
开发者ID:apache,项目名称:myfaces-trinidad,代码行数:23,代码来源:JavaIntrospector.java

示例6: create

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static PropertyDescriptor create(PropertyDescriptor pd) {
    try {
        if (pd instanceof IndexedPropertyDescriptor) {
            IndexedPropertyDescriptor ipd = (IndexedPropertyDescriptor) pd;
            return new IndexedPropertyDescriptor(
                    ipd.getName(),
                    ipd.getReadMethod(),
                    ipd.getWriteMethod(),
                    ipd.getIndexedReadMethod(),
                    ipd.getIndexedWriteMethod());
        } else {
            return new PropertyDescriptor(
                    pd.getName(),
                    pd.getReadMethod(),
                    pd.getWriteMethod());
        }
    }
    catch (IntrospectionException exception) {
        exception.printStackTrace();
        return null;
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:23,代码来源:Test4634390.java

示例7: objectToMap

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
 * 对象到map
 * @param obj
 * @return
 */
public static Map<String, Object> objectToMap(Object obj) { 
	Map<String, Object> map = new HashMap<String, Object>();
    if(obj == null) {
        return map;      
    }
    try{
     BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());    
     PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();    
     for (PropertyDescriptor property : propertyDescriptors) {    
         String key = property.getName();    
         if (key.compareToIgnoreCase("class") == 0) {   
             continue;  
         }  
         Method getter = property.getReadMethod();  
         Object value = getter!=null ? getter.invoke(obj) : null;  
         map.put(key, value);  
     }    
    }catch(Exception e) {
    	logger.error(e.getMessage());
    }
    return map;
}
 
开发者ID:fier-liu,项目名称:FCat,代码行数:28,代码来源:ObjectUtil.java

示例8: setProperty

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
private static void setProperty (PropertyDescriptor pd, Object value, Object source)
throws IllegalAccessException, InvocationTargetException, MouldException {
    if(pd!=null && pd.getWriteMethod()!=null) {
        Method m = pd.getWriteMethod();
        if(!m.isAccessible()) m.setAccessible(true);
        Class tClass = m.getParameterTypes()[0];
        if(value==null || tClass.isAssignableFrom(value.getClass())) {
            m.invoke(source, new Object[] {value});
            log.debug("Set property '" + pd.getName() + "=" + value + "' on object '" + source.getClass().getName() + "'");
        } else if(DataTypeMapper.instance().isMappable(value.getClass(),tClass)) {
            // See if there is a datatype mapper for these classes
            value = DataTypeMapper.instance().map(value, tClass);
            m.invoke(source, new Object[] {value});
            log.debug("Translate+Set property '" + pd.getName() + "=" + value + "' on object '" + source.getClass().getName() + "'");
        } else {
            // Data type mismatch
            throw new MouldException(MouldException.DATATYPE_MISMATCH, source.getClass().getName() + "." + m.getName(), tClass.getName(), value.getClass().getName());
        }
    } else {
        MouldException me = new MouldException(MouldException.NO_SETTER, null,
                            pd==null?"???":pd.getName(), source.getClass().getName());
        log.error(me.getLocalizedMessage());
        throw me;
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:26,代码来源:BeanMoulder.java

示例9: readProperty

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public static <T> T readProperty(Object entity, PropertyDescriptor propertyDescriptor, Class<T> expectedType) {
	Class<?> clazz = ClassUtils.getRealClass(entity);
	String propertyName = propertyDescriptor.getName();
	Class<?> propertyType = propertyDescriptor.getPropertyType();
	if (!expectedType.isAssignableFrom(propertyType)) {
		throw new IllegalArgumentException(String.format("%s.%s is of type %s but %s is expected", clazz, propertyName, propertyType, expectedType));
	}
	T value = PropertyUtils.read(entity, propertyDescriptor);
	return value;
}
 
开发者ID:cronn-de,项目名称:reflection-util,代码行数:11,代码来源:PropertyUtils.java

示例10: MethodProperty

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public MethodProperty(PropertyDescriptor property) {
    super(property.getName(), property.getPropertyType(),
            property.getReadMethod() == null ? null : property.getReadMethod()
                    .getGenericReturnType());
    this.property = property;
    this.readable = property.getReadMethod() != null;
    this.writable = property.getWriteMethod() != null;
}
 
开发者ID:RoccoDev,项目名称:5zig-TIMV-Plugin,代码行数:9,代码来源:MethodProperty.java

示例11: testWriteDirectly_WrongType

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
@Test
public void testWriteDirectly_WrongType() throws Exception {
	OtherTestEntity testEntity = new OtherTestEntity();
	PropertyDescriptor property = PropertyUtils.getPropertyDescriptor(OtherTestEntity.class, OtherTestEntity::getImmutableValue);
	try {
		PropertyUtils.writeDirectly(testEntity, property, 12345L);
		fail("IllegalArgumentException expected");
	} catch (IllegalArgumentException e) {
		String fieldName = OtherTestEntity.class.getName() + "." + property.getName();
		assertEquals("Can not set final java.lang.String field " + fieldName + " to java.lang.Long", e.getMessage());
	}
}
 
开发者ID:cronn-de,项目名称:reflection-util,代码行数:13,代码来源:PropertyUtilsTest.java

示例12: getDiff

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
 * @param oldBean
 * @param newBean
 * @return
 */
public static <T> T getDiff(T oldBean, T newBean) {
    if (oldBean == null && newBean != null) {
        return newBean;
    } else if (newBean == null) {
        return null;
    } else {
        Class<?> cls1 = oldBean.getClass();
        try {
            @SuppressWarnings("unchecked")
            T object = (T)cls1.newInstance();
            BeanInfo beanInfo = Introspector.getBeanInfo(cls1);
            PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
            for (PropertyDescriptor property : propertyDescriptors) {
                String key = property.getName();
                // 过滤class属性
                if (!key.equals("class")) {
                    // 得到property对应的getter方法
                    Method getter = property.getReadMethod();
                    // 得到property对应的setter方法
                    Method setter = property.getWriteMethod();
                    Object oldValue = getter.invoke(oldBean);
                    Object newValue = getter.invoke(newBean);
                    if (newValue != null) {
                        if (oldValue == null) {
                            setter.invoke(object, newValue);
                        } else if (oldValue != null && !newValue.equals(oldValue)) {
                            setter.invoke(object, newValue);
                        }
                    }
                }
            }
            return object;
        } catch (Exception e) {
            throw new DataParseException(e);
        }
    }
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:43,代码来源:InstanceHelper.java

示例13: findAnnotation

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
/**
 * Find the annotation
 * <p>
 * The following search order processed
 * <ol>
 * <li>Check the field with the same name as the property, process through
 * all superclasses</li>
 * <li>Check the read method</li>
 * <li>Check the write method</li>
 * </ol>
 * </p>
 *
 * @param pd
 *            the property descriptor to check
 * @param clazz
 *            class instance
 * @return the annotation or <code>null</code> if none was found
 */
protected <T extends Annotation> T findAnnotation ( final PropertyDescriptor pd, final Class<?> clazz, final Class<T> annotationClazz )
{
    final String name = pd.getName ();

    try
    {
        final Field field = findField ( name, clazz );
        final T itemName = field.getAnnotation ( annotationClazz );
        if ( itemName != null )
        {
            return itemName;
        }
    }
    catch ( final NoSuchFieldException e )
    {
    }

    if ( pd.getReadMethod () != null && pd.getReadMethod ().getAnnotation ( annotationClazz ) != null )
    {
        return pd.getReadMethod ().getAnnotation ( annotationClazz );
    }

    if ( pd.getWriteMethod () != null && pd.getWriteMethod ().getAnnotation ( annotationClazz ) != null )
    {
        return pd.getWriteMethod ().getAnnotation ( annotationClazz );
    }

    return null;
}
 
开发者ID:eclipse,项目名称:neoscada,代码行数:48,代码来源:AbstractObjectExporter.java

示例14: setPropertyDescriptor

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
public void setPropertyDescriptor(AbstractCouchDbTransaction couchDbTransaction, PropertyDescriptor[] propertyDescriptors, DatabaseObject parentObject) {	
	cleanGroups();
	
	/* Fill the Group widget */
	for (PropertyDescriptor property : propertyDescriptors) {
		final String name = property.getName();
		final String description = property.getShortDescription();
		if (!parametersCouch.contains(name) ){

			if ( (name.startsWith("q_") || name.startsWith("p_")) ) {
				if (!parentObject.getClass().getCanonicalName().equals(property.getValue( 
							MySimpleBeanInfo.BLACK_LIST_PARENT_CLASS))) {
					Group choosenGroup = name.startsWith("q_") ? groupQueries : groupParameters;
					addToComposite(choosenGroup, name, description, false);
				}
			} 
		}
	}
	
	if (groupQueries.getChildren().length == 0) {
		groupQueries.dispose();
	}
	
	if (groupParameters.getChildren().length == 0) {
		groupParameters.dispose();
	}
	
	/* */
	Collection<CouchExtraVariable> extraVariables = null;
	if (couchDbTransaction instanceof PostBulkDocumentsTransaction){
		extraVariables = ((PostBulkDocumentsTransaction) couchDbTransaction).getCouchParametersExtra();
	}
	if (couchDbTransaction instanceof PostDocumentTransaction) {
		extraVariables = ((PostDocumentTransaction) couchDbTransaction).getCouchParametersExtra();
	}
	if (couchDbTransaction instanceof PostUpdateTransaction) {
		extraVariables = ((PostUpdateTransaction) couchDbTransaction).getCouchParametersExtra();
	}
	if (couchDbTransaction instanceof PutUpdateTransaction) {
		extraVariables = ((PutUpdateTransaction) couchDbTransaction).getCouchParametersExtra();
	}
	
	if (extraVariables != null ){
		for (CouchExtraVariable extraVariable : extraVariables) {
			addToComposite(groupData, extraVariable.getVariableName(), extraVariable.getVariableDescription(), extraVariable.isMultiValued());
		}
	}
	
	if (groupData.getChildren().length == 0){
		groupData.dispose();
	}
	
	setContent(globalComposite);
	globalComposite.pack(true);
	
	// Fix text no displayed in C8oBrowser
	LinkedList<Control> controls = new LinkedList<>();
	controls.add(globalComposite);
	Control c;
	while ((c = controls.pollFirst()) != null) {
		if (c instanceof C8oBrowser) {
			((C8oBrowser) c).reloadText();
		} else if (c instanceof Composite) {
			controls.addAll(Arrays.asList(((Composite) c).getChildren()));
		}
	}
}
 
开发者ID:convertigo,项目名称:convertigo-eclipse,代码行数:68,代码来源:CouchVariablesComposite.java

示例15: setProperty

import java.beans.PropertyDescriptor; //导入方法依赖的package包/类
static void setProperty(PropertyDescriptor pd, Object value, Object source)
        throws IllegalAccessException, InvocationTargetException, TransformException {
    if (pd != null && pd.getWriteMethod() != null) {
        Method m = pd.getWriteMethod();
        if (!m.isAccessible())
            m.setAccessible(true);
        Class tClass = m.getParameterTypes()[0];
        if (value == null || tClass.isAssignableFrom(value.getClass())) {
            m.invoke(source, new Object[]{value});
            if (log.isDebugEnabled())
                log.debug("Set property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
        } else if (DataTypeMapper.instance().isMappable(value.getClass(), tClass)) {
            // See if there is a datatype mapper for these classes
            value = DataTypeMapper.instance().map(value, tClass);
            m.invoke(source, new Object[]{value});
            if (log.isDebugEnabled())
                log.debug("Translate+Set property '" + pd.getName() + '=' + value + "' on object '" + source.getClass().getName() + '\'');
        } else {
            // Data type mismatch
            throw new TransformException(TransformException.DATATYPE_MISMATCH, source.getClass().getName() + '.' + m.getName(), tClass.getName(), value.getClass().getName());
        }
    } else {
        TransformException me = new TransformException(TransformException.NO_SETTER, null,
                pd == null ? "???" : pd.getName(), source.getClass().getName());
        log.error(me.getLocalizedMessage());
        throw me;
    }
}
 
开发者ID:jaffa-projects,项目名称:jaffa-framework,代码行数:29,代码来源:TransformerUtils.java


注:本文中的java.beans.PropertyDescriptor.getName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。