本文整理汇总了Java中java.beans.Introspector.getBeanInfo方法的典型用法代码示例。如果您正苦于以下问题:Java Introspector.getBeanInfo方法的具体用法?Java Introspector.getBeanInfo怎么用?Java Introspector.getBeanInfo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.beans.Introspector
的用法示例。
在下文中一共展示了Introspector.getBeanInfo方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transBean2Map
import java.beans.Introspector; //导入方法依赖的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;
}
示例2: autowiredByName
import java.beans.Introspector; //导入方法依赖的package包/类
private void autowiredByName(Bean bean) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClazz());
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
for (PropertyDescriptor desc : descriptors) {
for (Bean definedBean : beanDefinitionList) {
if (desc.getName().equals(definedBean.getName())) {
desc.getWriteMethod().invoke(bean.getObject(), createBean(definedBean) );
break;
}
}
}
} catch (Exception e) {
throw new BeansException(e);
}
}
示例3: setParameterValue
import java.beans.Introspector; //导入方法依赖的package包/类
/**
* Sets the value for a specified parameter.
*
* @param paramaterName the name for the parameteer
* @param parameterValue the value the parameter will receive
*/
@Override
public void setParameterValue(String paramaterName, Object parameterValue)
throws ResourceInstantiationException{
// get the beaninfo for the resource bean, excluding data about Object
BeanInfo resBeanInf = null;
try {
resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class);
} catch(Exception e) {
throw new ResourceInstantiationException(
"Couldn't get bean info for resource " + this.getClass().getName()
+ Strings.getNl() + "Introspector exception was: " + e
);
}
AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue);
}
示例4: BeanProperties
import java.beans.Introspector; //导入方法依赖的package包/类
public BeanProperties(Class<?> type) throws ELException {
this.type = type;
this.properties = new HashMap<String, BeanProperty>();
try {
BeanInfo info = Introspector.getBeanInfo(this.type);
PropertyDescriptor[] pds = info.getPropertyDescriptors();
for (PropertyDescriptor pd: pds) {
this.properties.put(pd.getName(), new BeanProperty(type, pd));
}
if (System.getSecurityManager() != null) {
// When running with SecurityManager, some classes may be
// not accessible, but have accessible interfaces.
populateFromInterfaces(type);
}
} catch (IntrospectionException ie) {
throw new ELException(ie);
}
}
示例5: autowiredByType
import java.beans.Introspector; //导入方法依赖的package包/类
private void autowiredByType(Bean bean) {
try {
BeanInfo beanInfo = Introspector.getBeanInfo(bean.getClazz());
PropertyDescriptor[] descriptors = beanInfo.getPropertyDescriptors();
PropertyDescriptor usePd = null;
List<Bean> foundBeans = new ArrayList<Bean>();
for (PropertyDescriptor desc : descriptors) {
for (Bean definedBean : beanDefinitionList) {
if (desc.getPropertyType().equals(definedBean.getClazz())) {
foundBeans.add(definedBean);
usePd = desc;
}
}
}
if (!foundBeans.isEmpty()) {
if (foundBeans.size() > 1)
throw new BeansException("too many");
usePd.getWriteMethod().invoke(bean.getObject(), createBean(foundBeans.get(0)) );
}
} catch (Exception e) {
throw new BeansException(e);
}
}
示例6: main
import java.beans.Introspector; //导入方法依赖的package包/类
public static void main(String[] args) throws Exception {
BeanInfo i = Introspector.getBeanInfo(C.class, Object.class);
PropertyDescriptor[] pds = i.getPropertyDescriptors();
Checker.checkEq("number of properties", pds.length, 1);
PropertyDescriptor p = pds[0];
Checker.checkEq("property description", p.getShortDescription(), "BASE");
Checker.checkEq("isBound", p.isBound(), true);
Checker.checkEq("isExpert", p.isExpert(), true);
Checker.checkEq("isHidden", p.isHidden(), true);
Checker.checkEq("isPreferred", p.isPreferred(), true);
Checker.checkEq("required", p.getValue("required"), true);
Checker.checkEq("visualUpdate", p.getValue("visualUpdate"), true);
Checker.checkEnumEq("enumerationValues", p.getValue("enumerationValues"),
new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
}
示例7: RootClassInfo
import java.beans.Introspector; //导入方法依赖的package包/类
private RootClassInfo(String className, List<String> warnings) {
super();
this.className = className;
this.warnings = warnings;
if (className == null) {
return;
}
FullyQualifiedJavaType fqjt = new FullyQualifiedJavaType(className);
String nameWithoutGenerics = fqjt.getFullyQualifiedNameWithoutTypeParameters();
if (!nameWithoutGenerics.equals(className)) {
genericMode = true;
}
try {
Class<?> clazz = ObjectFactory.externalClassForName(nameWithoutGenerics);
BeanInfo bi = Introspector.getBeanInfo(clazz);
propertyDescriptors = bi.getPropertyDescriptors();
} catch (Exception e) {
propertyDescriptors = null;
warnings.add(getString("Warning.20", className)); //$NON-NLS-1$
}
}
示例8: TagHandlerInfo
import java.beans.Introspector; //导入方法依赖的package包/类
/**
* Constructor.
*
* @param n
* The custom tag whose tag handler class is to be
* introspected
* @param tagHandlerClass
* Tag handler class
* @param err
* Error dispatcher
*/
TagHandlerInfo(Node n, Class tagHandlerClass, ErrorDispatcher err)
throws JasperException {
this.tagHandlerClass = tagHandlerClass;
this.methodMaps = new Hashtable();
this.propertyEditorMaps = new Hashtable();
try {
BeanInfo tagClassInfo = Introspector
.getBeanInfo(tagHandlerClass);
PropertyDescriptor[] pd = tagClassInfo.getPropertyDescriptors();
for (int i = 0; i < pd.length; i++) {
/*
* FIXME: should probably be checking for things like
* pageContext, bodyContent, and parent here -akv
*/
if (pd[i].getWriteMethod() != null) {
methodMaps.put(pd[i].getName(), pd[i].getWriteMethod());
}
if (pd[i].getPropertyEditorClass() != null)
propertyEditorMaps.put(pd[i].getName(), pd[i]
.getPropertyEditorClass());
}
} catch (IntrospectionException ie) {
err.jspError(n, "jsp.error.introspect.taghandler",
tagHandlerClass.getName(), ie);
}
}
示例9: bean2Map
import java.beans.Introspector; //导入方法依赖的package包/类
/**
* 将bean转换为map
*
* @param bean
* @return
*/
public static Map<String, Object> bean2Map(Object bean) {
try {
if (null == bean) {
return null;
}
Class<? extends Object> entityClass = bean.getClass();
Map<String, Object> returnMap = new HashMap<String, Object>();
BeanInfo beanInfo = Introspector.getBeanInfo(entityClass);
PropertyDescriptor[] propertyDescriptors = beanInfo
.getPropertyDescriptors();
if (null != propertyDescriptors) {
for (int i = 0; i < propertyDescriptors.length; i++) {
PropertyDescriptor descriptor = propertyDescriptors[i];
String propertyName = descriptor.getName();
if (!propertyName.equals("class")) {
Method readMethod = descriptor.getReadMethod();
Object result = readMethod.invoke(bean, new Object[0]);
if (result != null) {
returnMap.put(propertyName, result);
} else {
returnMap.put(propertyName, null);
}
}
}
}
return returnMap;
} catch (Exception e) {
return null;
}
}
示例10: detectConversionConstructorBreakingChanges
import java.beans.Introspector; //导入方法依赖的package包/类
@Test
public void detectConversionConstructorBreakingChanges() throws Exception {
// n.b. If DataSourceFactory introduces an object with nested properties,
// those will have to be validated too. At time of writing this was
// not the case.
BeanInfo baseclassInfo = Introspector.getBeanInfo(DataSourceFactory.class, Object.class);
Set<String> actualProperties = new HashSet<>();
for (PropertyDescriptor property : baseclassInfo.getPropertyDescriptors()) {
actualProperties.add(property.getName());
}
assertThat(actualProperties).isEqualTo(expectedDataSourceFactoryProperties);
}
示例11: initialize
import java.beans.Introspector; //导入方法依赖的package包/类
private void initialize() {
if(nObjects == 0) return;
readMethod = new Method[nObjects]; //not sure if these need to be arrays, but doing this way to be safe
writeMethod = new Method[nObjects]; //(might be able to use same readMethod and writeMethod objects for all objects
for(int j=0; j<nObjects; j++) {
Class c = object[j].getClass();
//bits of this code are taken from Thinking in Java (1st edition), pages 708-713
BeanInfo bi = null;
try {
bi = Introspector.getBeanInfo(c, java.lang.Object.class);
}
catch(IntrospectionException ex) {
System.out.println("Couldn't introspect " + c.getName());
System.exit(1);
}
PropertyDescriptor[] properties = bi.getPropertyDescriptors();
for(int i=0; i<properties.length; i++) {
String propertyName = properties[i].getName();
if(propertyName.equals(property)) {
readMethod[j] = properties[i].getReadMethod();
writeMethod[j] = properties[i].getWriteMethod();
break;
}
}
if(j == 0) {//discover dimension of modified property by looking at getDimension method of first object
dimension = Dimension.introspect(object[0],property,bi);
}
}
}
示例12: main
import java.beans.Introspector; //导入方法依赖的package包/类
public static void main(String[] args) throws IntrospectionException {
Class type = sun.security.x509.X509CertInfo.class;
System.setSecurityManager(new SecurityManager());
BeanInfo info = Introspector.getBeanInfo(type);
for (MethodDescriptor md : info.getMethodDescriptors()) {
Method method = md.getMethod();
System.out.println(method);
String name = method.getDeclaringClass().getName();
if (name.startsWith("sun.")) {
throw new Error("found inaccessible method");
}
}
}
示例13: getAdditionalBeanInfo
import java.beans.Introspector; //导入方法依赖的package包/类
public BeanInfo[] getAdditionalBeanInfo () {
try {
return new BeanInfo[] { Introspector.getBeanInfo (MultiFileLoader.class) };
} catch (IntrospectionException ie) {
ErrorManager.getDefault().notify(ie);
return null;
}
}
示例14: main
import java.beans.Introspector; //导入方法依赖的package包/类
public static void main(final String[] args) {
final Object bi;
try {
bi = Introspector.getBeanInfo(JButton.class);
} catch (IntrospectionException e) {
throw new RuntimeException(e);
}
final Image m16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_16x16);
final Image m32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_MONO_32x32);
final Image c16 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_16x16);
final Image c32 = ((BeanInfo) bi).getIcon(BeanInfo.ICON_COLOR_32x32);
if (m16 == null || m32 == null || c16 == null || c32 == null) {
throw new RuntimeException("Image should not be null");
}
}
示例15: getBeanInfo
import java.beans.Introspector; //导入方法依赖的package包/类
public static BeanInfo getBeanInfo(Class<? extends Resource> c) throws IntrospectionException {
BeanInfo r = beanInfoCache.get(c);
if(r == null) {
r = Introspector.getBeanInfo(c, Object.class);
beanInfoCache.put(c, r);
}
return r;
}