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


Java Introspector.getBeanInfo方法代码示例

本文整理汇总了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;
}
 
开发者ID:liuxx001,项目名称:bird-java,代码行数:24,代码来源:InstanceHelper.java

示例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);
    }
}
 
开发者ID:hulang1024,项目名称:SummerFramework,代码行数:18,代码来源:XMLBeanFactory.java

示例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);
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:22,代码来源:FeaturesSchemaEditor.java

示例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);
    }
}
 
开发者ID:liaokailin,项目名称:tomcat7,代码行数:19,代码来源:BeanELResolver.java

示例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);
    }
}
 
开发者ID:hulang1024,项目名称:SummerFramework,代码行数:26,代码来源:XMLBeanFactory.java

示例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"});
    }
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:21,代码来源:InheritPropertyInfoTest.java

示例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$
    }
}
 
开发者ID:nextyu,项目名称:summer-mybatis-generator,代码行数:25,代码来源:RootClassInfo.java

示例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);
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:39,代码来源:Generator.java

示例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;
    }
}
 
开发者ID:stand1123,项目名称:sun-members,代码行数:37,代码来源:CommonUtil.java

示例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);
}
 
开发者ID:toasttab,项目名称:jdbishard,代码行数:16,代码来源:CopiedDataSourceFactoryTest.java

示例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);
        }
    }
    
}
 
开发者ID:etomica,项目名称:etomica,代码行数:32,代码来源:ModifierGeneral.java

示例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");
        }
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:15,代码来源:Test6277246.java

示例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;
    }
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:9,代码来源:PropertiesDataLoaderBeanInfo.java

示例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");
    }
}
 
开发者ID:AdoptOpenJDK,项目名称:openjdk-jdk10,代码行数:16,代码来源:LoadingStandardIcons.java

示例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;
}
 
开发者ID:GateNLP,项目名称:gate-core,代码行数:10,代码来源:AbstractResource.java


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