本文整理匯總了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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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());
}
}
示例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);
}
}
示例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;
}
示例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;
}
示例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();
}
}
示例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);
}
}
}
示例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);
}
}
示例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;
}