當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。