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


Java PropertyDescriptor类代码示例

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


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

示例1: filterPropertyDescriptorsForDependencyCheck

import java.beans.PropertyDescriptor; //导入依赖的package包/类
/**
 * Extract a filtered set of PropertyDescriptors from the given BeanWrapper,
 * excluding ignored dependency types or properties defined on ignored dependency interfaces.
 * @param bw the BeanWrapper the bean was created with
 * @param cache whether to cache filtered PropertyDescriptors for the given bean Class
 * @return the filtered PropertyDescriptors
 * @see #isExcludedFromDependencyCheck
 * @see #filterPropertyDescriptorsForDependencyCheck(org.springframework.beans.BeanWrapper)
 */
protected PropertyDescriptor[] filterPropertyDescriptorsForDependencyCheck(BeanWrapper bw, boolean cache) {
	PropertyDescriptor[] filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass());
	if (filtered == null) {
		if (cache) {
			synchronized (this.filteredPropertyDescriptorsCache) {
				filtered = this.filteredPropertyDescriptorsCache.get(bw.getWrappedClass());
				if (filtered == null) {
					filtered = filterPropertyDescriptorsForDependencyCheck(bw);
					this.filteredPropertyDescriptorsCache.put(bw.getWrappedClass(), filtered);
				}
			}
		}
		else {
			filtered = filterPropertyDescriptorsForDependencyCheck(bw);
		}
	}
	return filtered;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:AbstractAutowireCapableBeanFactory.java

示例2: writeDirectly

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public static void writeDirectly(Object destination, PropertyDescriptor propertyDescriptor, Object value) {
	try {
		Field field = findField(destination, propertyDescriptor);
		boolean accessible = field.isAccessible();
		try {
			if (!accessible) {
				field.setAccessible(true);
			}
			field.set(destination, value);
		} finally {
			if (!accessible) {
				field.setAccessible(false);
			}
		}
	} catch (NoSuchFieldException | IllegalAccessException e) {
		throw new ReflectionRuntimeException("Failed to write " + getQualifiedPropertyName(destination, propertyDescriptor), e);
	}
}
 
开发者ID:cronn-de,项目名称:reflection-util,代码行数:19,代码来源:PropertyUtils.java

示例3: convertMap2Bean

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public static Object convertMap2Bean(Class type, Map map)
		throws IntrospectionException, IllegalAccessException,
		InstantiationException, InvocationTargetException {
	BeanInfo beanInfo = Introspector.getBeanInfo(type);
	Object obj = type.newInstance();
	PropertyDescriptor[] propertyDescriptors = beanInfo
			.getPropertyDescriptors();
	for (PropertyDescriptor pro : propertyDescriptors) {
		String propertyName = pro.getName();
		if (pro.getPropertyType().getName().equals("java.lang.Class")) {
			continue;
		}
		if (map.containsKey(propertyName)) {
			Object value = map.get(propertyName);
			Method setter = pro.getWriteMethod();
			setter.invoke(obj, value);
		}
	}
	return obj;
}
 
开发者ID:iminto,项目名称:zooadmin,代码行数:21,代码来源:BeanMapUtil.java

示例4: getProperty

import java.beans.PropertyDescriptor; //导入依赖的package包/类
/**
 * 获取Bean的属性
 * @param bean bean
 * @param propertyName 属性名
 * @return 属性值
 */
public static Object getProperty(Object bean, String propertyName) {
	PropertyDescriptor pd = getPropertyDescriptor(bean.getClass(), propertyName);
	if (pd == null) {
		throw new RuntimeException("Could not read property '" + propertyName + "' from bean PropertyDescriptor is null");
	}
	Method readMethod = pd.getReadMethod();
	if (readMethod == null) {
		throw new RuntimeException("Could not read property '" + propertyName + "' from bean readMethod is null");
	}
	if (!readMethod.isAccessible()) {
		readMethod.setAccessible(true);
	}
	try {
		return readMethod.invoke(bean);
	} catch (Throwable ex) {
		throw new RuntimeException("Could not read property '" + propertyName + "' from bean", ex);
	}
}
 
开发者ID:TomChen001,项目名称:xmanager,代码行数:25,代码来源:BeanUtils.java

示例5: UIStyleBeanInfo

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public UIStyleBeanInfo() {
	try {
		beanClass = UIStyle.class;
		additionalBeanClass = com.twinsoft.convertigo.beans.mobile.components.UIComponent.class;

		iconNameC16 = "/com/twinsoft/convertigo/beans/mobile/components/images/uistyle_color_16x16.png";
		iconNameC32 = "/com/twinsoft/convertigo/beans/mobile/components/images/uistyle_color_32x32.png";

		resourceBundle = getResourceBundle("res/UIStyle");

		displayName = resourceBundle.getString("display_name");
		shortDescription = resourceBundle.getString("short_description");
		
		properties = new PropertyDescriptor[1];
		
		properties[0] = new PropertyDescriptor("styleContent", beanClass, "getStyleContent", "setStyleContent");
		properties[0].setDisplayName(getExternalizedString("property.styleContent.display_name"));
		properties[0].setShortDescription(getExternalizedString("property.styleContent.short_description"));
		properties[0].setHidden(true);
	}
	catch(Exception e) {
		com.twinsoft.convertigo.engine.Engine.logBeans.error("Exception with bean info; beanClass=" + beanClass.toString(), e);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:25,代码来源:UIStyleBeanInfo.java

示例6: buildClass

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public void buildClass(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
	String clazz=req.getParameter("clazz");
	List<Field> result=new ArrayList<Field>();
	try{
		Class<?> targetClass=Class.forName(clazz);
		PropertyDescriptor[] propertyDescriptors=PropertyUtils.getPropertyDescriptors(targetClass);
		for(PropertyDescriptor pd:propertyDescriptors){
			String name=pd.getName();
			if("class".equals(name)){
				continue;
			}
			result.add(new Field(name));
		}
		writeObjectToJson(resp, result);
	}catch(Exception ex){
		throw new ReportDesignException(ex);
	}
}
 
开发者ID:youseries,项目名称:ureport,代码行数:19,代码来源:DatasourceServletAction.java

示例7: SerialStepBeanInfo

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public SerialStepBeanInfo() {
	try {
		beanClass = SerialStep.class;
		additionalBeanClass = com.twinsoft.convertigo.beans.steps.BranchStep.class;

		iconNameC16 = "/com/twinsoft/convertigo/beans/steps/images/serial_16x16.png";
		iconNameC32 = "/com/twinsoft/convertigo/beans/steps/images/serial_32x32.png";
		
		resourceBundle = getResourceBundle("res/SerialStep");
		
		displayName = resourceBundle.getString("display_name");
		shortDescription = resourceBundle.getString("short_description");
		
		PropertyDescriptor property = getPropertyDescriptor("maxNumberOfThreads");
           property.setHidden(true) ;
		
	}
	catch(Exception e) {
		com.twinsoft.convertigo.engine.Engine.logBeans.error("Exception with bean info; beanClass=" + beanClass.toString(), e);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:22,代码来源:SerialStepBeanInfo.java

示例8: testUsageOfExplicitPropertyDescriptor

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public void testUsageOfExplicitPropertyDescriptor() throws Exception {
    PropertyDescriptor pd = new PropertyDescriptor(
            "myProp", this.getClass(),
            "getterUsageOfExplicitPropertyDescriptor",
            "setterUsageOfExplicitPropertyDescriptor"
            );
    
    DefaultPropertyModel model = new DefaultPropertyModel(this, pd);
    
    assertEquals("Getter returns this", model.getValue(), this);
    
    String msgToThrow = "msgToThrow";
    try {
        model.setValue(msgToThrow);
        fail("Setter should throw an exception");
    } catch (InvocationTargetException ex) {
        // when an exception occurs it should throw InvocationTargetException
        assertEquals("The right message", msgToThrow, ex.getTargetException().getMessage());
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:21,代码来源:DefaultPropertyModelTest.java

示例9: XMLHttpHeadersBeanInfo

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public XMLHttpHeadersBeanInfo() {
	try {
		beanClass = XMLHttpHeaders.class;
		additionalBeanClass = com.twinsoft.convertigo.beans.extractionrules.HtmlExtractionRule.class;

	    iconNameC16 = "/com/twinsoft/convertigo/beans/common/images/xmlhttpheaders_color_16x16.png";
	    iconNameC32 = "/com/twinsoft/convertigo/beans/common/images/xmlhttpheaders_color_32x32.png";

		resourceBundle = getResourceBundle("res/XMLHttpHeaders");

		displayName = getExternalizedString("display_name");
		shortDescription = getExternalizedString("short_description");
		
		PropertyDescriptor property = getPropertyDescriptor("xpath");
		property.setHidden(true);
	}
	catch(Exception e) {
		com.twinsoft.convertigo.engine.Engine.logBeans.error("Exception with bean info; beanClass=" + beanClass.toString(), e);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:21,代码来源:XMLHttpHeadersBeanInfo.java

示例10: 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

示例11: getEnumAndValue

import java.beans.PropertyDescriptor; //导入依赖的package包/类
/**
 * 获取枚举中指定属性的值
 *
 * @param enumCls 枚举类型
 * @param prop    Bean属性名
 * @return (枚举值, 指定属性的值)
 */
public static Map<Enum<?>, Object> getEnumAndValue(Class<?> enumCls, String prop) {

    Object[] enumValues = enumCls.getEnumConstants();
    if (isEmpty(enumValues)) {
        return newLinkedHashMap();
    }
    Map<Enum<?>, Object> result = newLinkedHashMapWithExpectedSize(enumValues.length * 2);
    try {
        for (Object enumValue : enumValues) {
            PropertyDescriptor pd = getPropertyDescriptor(enumValue, prop);
            if (pd == null || pd.getReadMethod() == null) {
                continue;
            }
            result.put((Enum<?>) enumValue, pd.getReadMethod().invoke(enumValue));
        }
    } catch (Exception e) {
        // ignore
    }
    return result;
}
 
开发者ID:thlcly,项目名称:Dude,代码行数:28,代码来源:Enums.java

示例12: getOperationDescription

import java.beans.PropertyDescriptor; //导入依赖的package包/类
/**
 * Retrieves the description for the supplied {@code Method} from the
 * metadata. Uses the method name is no description is present in the metadata.
 */
@Override
protected String getOperationDescription(Method method, String beanKey) {
	PropertyDescriptor pd = BeanUtils.findPropertyForMethod(method);
	if (pd != null) {
		ManagedAttribute ma = this.attributeSource.getManagedAttribute(method);
		if (ma != null && StringUtils.hasText(ma.getDescription())) {
			return ma.getDescription();
		}
		ManagedMetric metric = this.attributeSource.getManagedMetric(method);
		if (metric != null && StringUtils.hasText(metric.getDescription())) {
			return metric.getDescription();
		}
		return method.getName();
	}
	else {
		ManagedOperation mo = this.attributeSource.getManagedOperation(method);
		if (mo != null && StringUtils.hasText(mo.getDescription())) {
			return mo.getDescription();
		}
		return method.getName();
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:MetadataMBeanInfoAssembler.java

示例13: collectParameters

import java.beans.PropertyDescriptor; //导入依赖的package包/类
private static void collectParameters(Collection<Parameters> parameters, Parameter parameter, Annotation a,
		boolean isPathVariable) {
	if (a != null) {
		String typeStr = parameter.getType().getSimpleName();
		Type type = parameter.getParameterizedType();
		if (type instanceof ParameterizedType) {
			typeStr = ((Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0]).getSimpleName();
		}
		parameters.add(new Parameters((boolean) AnnotationUtils.getValue(a, "required"),
				(String) (AnnotationUtils.getValue(a).equals("") ? parameter.getName()
						: AnnotationUtils.getValue(a)),
				typeStr));
	} else if (Pageable.class.isAssignableFrom(parameter.getType()) && !isPathVariable) {
		try {
			for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(parameter.getType())
					.getPropertyDescriptors()) {
				parameters.add(new Parameters(false, propertyDescriptor.getName(),
						propertyDescriptor.getPropertyType().getSimpleName()));
			}
		} catch (IntrospectionException e) {
			LOGGER.error("Problemas al obtener el Pageable: {}", parameter, e);
		}
	}
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:25,代码来源:ReflectionUtils.java

示例14: InjectorBeanInfo

import java.beans.PropertyDescriptor; //导入依赖的package包/类
public InjectorBeanInfo() {
	try {
		beanClass = Injector.class;
		additionalBeanClass = com.twinsoft.convertigo.beans.extractionrules.siteclipper.BaseRule.class;

		resourceBundle = getResourceBundle("res/Injector");

		properties = new PropertyDescriptor[2];

		properties[0] = new PropertyDescriptor("location", beanClass, "getLocation", "setLocation");
        properties[0].setDisplayName(getExternalizedString("property.location.display_name"));
        properties[0].setShortDescription(getExternalizedString("property.location.short_description"));
    	properties[0].setPropertyEditorClass(HtmlLocation.class);
    	
		properties[1] = new PropertyDescriptor("customRegexp", beanClass, "getCustomRegexp", "setCustomRegexp");
        properties[1].setDisplayName(getExternalizedString("property.customRegexp.display_name"));
        properties[1].setShortDescription(getExternalizedString("property.customRegexp.short_description"));
    	properties[1].setExpert(true);
	}
	catch(Exception e) {
		com.twinsoft.convertigo.engine.Engine.logBeans.error("Exception with bean info; beanClass=" + beanClass.toString(), e);
	}
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:24,代码来源:InjectorBeanInfo.java

示例15: createDetail

import java.beans.PropertyDescriptor; //导入依赖的package包/类
private List<DetailField> createDetail(Class<?> c, boolean isRequest) {
	List<DetailField> detailFields = new ArrayList<>();
	ReflectionUtils.getGenericClass(c).ifPresent(clazz -> {
		try {
			for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(clazz, Object.class)
					.getPropertyDescriptors()) {
				if (!propertyDescriptor.getReadMethod().getDeclaringClass().equals(Object.class)) {
					Optional<Field> field = getField(clazz, propertyDescriptor);
					if (checkIfAddField(field, propertyDescriptor, isRequest)) {
						Optional<DetailField> detail = super.createDetail(propertyDescriptor, field, isRequest);
						detail.ifPresent(detailFields::add);
					}
				}
			}
		} catch (Exception e) {
			LOGGER.error("Error al inspeccionar la clase {}", clazz, e);
		}
	});
	return detailFields;
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:21,代码来源:ModelStrategy.java


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