當前位置: 首頁>>代碼示例>>Java>>正文


Java IntrospectionException類代碼示例

本文整理匯總了Java中java.beans.IntrospectionException的典型用法代碼示例。如果您正苦於以下問題:Java IntrospectionException類的具體用法?Java IntrospectionException怎麽用?Java IntrospectionException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


IntrospectionException類屬於java.beans包,在下文中一共展示了IntrospectionException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getAttributes

import java.beans.IntrospectionException; //導入依賴的package包/類
/**
 * Maps object attributes.
 * @param type the class to reflect.
 * @param object the instance to address.
 * @param <T> the class to reflect.
 * @return the attributes mapping.
 * @throws IntrospectionException when errors in reflection.
 * @throws InvocationTargetException when errors in reflection.
 * @throws IllegalAccessException when errors in reflection.
 */
public static <T> Map<String,Object> getAttributes(Class<T> type, T object)
    throws IntrospectionException, InvocationTargetException, IllegalAccessException {
  Map<String,Object> propsmap = new HashMap<>();
  final BeanInfo beanInfo = Introspector.getBeanInfo(type);
  final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
  for (PropertyDescriptor pd : propertyDescriptors) {
    if (pd.getName().equals("class")) continue;
    final Method getter = pd.getReadMethod();
    if (getter != null) {
      final String attrname = pd.getName();
      final Object attrvalue = getter.invoke(object);
      propsmap.put(attrname, attrvalue);
    }
  }
  return propsmap;
}
 
開發者ID:braineering,項目名稱:ares,代碼行數:27,代碼來源:ReflectionManager.java

示例2: getBeanInfo

import java.beans.IntrospectionException; //導入依賴的package包/類
private static BeanInfo getBeanInfo(Boolean mark, Class type) {
    System.out.println("test=" + mark + " for " + type);
    BeanInfo info;
    try {
        info = Introspector.getBeanInfo(type);
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
    if (info == null) {
        throw new Error("could not find BeanInfo for " + type);
    }
    if (mark != info.getBeanDescriptor().getValue("test")) {
        throw new Error("could not find marked BeanInfo for " + type);
    }
    return info;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:17,代碼來源:Test4520754.java

示例3: exludedByPropertyTest

import java.beans.IntrospectionException; //導入依賴的package包/類
@Test
public void exludedByPropertyTest() throws IllegalAccessException, InstantiationException, IntrospectionException, InvocationTargetException {
    Object instanceOne = clazz.newInstance();
    Object instanceTwo = clazz.newInstance();

    setProperty(instanceOne, "excludedByProperty", "one");
    setProperty(instanceOne, "excludedByArray", "two");
    setProperty(instanceOne, "notExcluded", "three");
    setProperty(instanceOne, "notExcludedByProperty", "four");

    setProperty(instanceTwo, "excludedByProperty", "differentValue");
    setProperty(instanceTwo, "excludedByArray", "two");
    setProperty(instanceTwo, "notExcluded", "three");
    setProperty(instanceTwo, "notExcludedByProperty", "four");

    assertThat(instanceOne.equals(instanceTwo), is(true));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:ExcludedFromEqualsAndHashCodeIT.java

示例4: notExludedByPropertyTest

import java.beans.IntrospectionException; //導入依賴的package包/類
@Test
public void notExludedByPropertyTest() throws IllegalAccessException, InstantiationException, IntrospectionException, InvocationTargetException {
    Object instanceOne = clazz.newInstance();
    Object instanceTwo = clazz.newInstance();

    setProperty(instanceOne, "excludedByProperty", "one");
    setProperty(instanceOne, "excludedByArray", "two");
    setProperty(instanceOne, "notExcluded", "three");
    setProperty(instanceOne, "notExcludedByProperty", "four");

    setProperty(instanceTwo, "excludedByProperty", "one");
    setProperty(instanceTwo, "excludedByArray", "two");
    setProperty(instanceTwo, "notExcluded", "three");
    setProperty(instanceTwo, "notExcludedByProperty", "differentValue");

    assertThat(instanceOne.equals(instanceTwo), is(false));
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:18,代碼來源:ExcludedFromEqualsAndHashCodeIT.java

示例5: resolveParamProperties

import java.beans.IntrospectionException; //導入依賴的package包/類
private void resolveParamProperties() throws IntrospectionException{
    List<ArgDefEntry<RequestParamDefinition>> reqParamDefs = new LinkedList<>();

    BeanInfo beanInfo = Introspector.getBeanInfo(argType);
    PropertyDescriptor[] propDescs = beanInfo.getPropertyDescriptors();

    for (PropertyDescriptor propDesc : propDescs) {
        //            TypeDescriptor propTypeDesc;
        //            propTypeDesc = beanWrapper.getPropertyTypeDescriptor(propDesc.getName());


        //            RequestParam reqParamAnno = propTypeDesc.getAnnotation(RequestParam.class);
        RequestParam reqParamAnno = propDesc.getPropertyType().getAnnotation(RequestParam.class);
        if (reqParamAnno == null) {
            // 忽略未標注 RequestParam 的屬性;
            continue;
        }
        RequestParamDefinition reqParamDef = RequestParamDefinition.resolveDefinition(reqParamAnno);
        ArgDefEntry<RequestParamDefinition> defEntry = new ArgDefEntry<>(reqParamDefs.size(), propDesc.getPropertyType(),
                reqParamDef);
        reqParamDefs.add(defEntry);
        propNames.add(propDesc.getName());
    }
    paramResolver = RequestParamResolvers.createParamResolver(reqParamDefs);
}
 
開發者ID:bubicn,項目名稱:bubichain-sdk-java,代碼行數:26,代碼來源:PojoPropertiesConverter.java

示例6: getPropertyDescriptors

import java.beans.IntrospectionException; //導入依賴的package包/類
private static PropertyDescriptor[] getPropertyDescriptors(Object object) {
    Class type = object.getClass();
    synchronized (System.out) {
        System.out.println(type);
        ClassLoader loader = type.getClassLoader();
        while (loader != null) {
            System.out.println(" - loader: " + loader);
            loader = loader.getParent();
        }
    }
    try {
        return Introspector.getBeanInfo(type).getPropertyDescriptors();
    } catch (IntrospectionException exception) {
        throw new Error("unexpected exception", exception);
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:17,代碼來源:Test4508780.java

示例7: main

import java.beans.IntrospectionException; //導入依賴的package包/類
public static void main(String[] args) throws IntrospectionException {
    Class[] types = {
            Component.class,
            Container.class,
            JComponent.class,
            AbstractButton.class,
            JButton.class,
            JToggleButton.class,
    };
    // Control set. "enabled" and "name" has the same pattern and can be found
    String[] names = {
            "enabled",
            "name",
            "focusable",
    };
    for (String name : names) {
        for (Class type : types) {
            BeanUtils.getPropertyDescriptor(type, name);
        }
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:22,代碼來源:Test4619792.java

示例8: test

import java.beans.IntrospectionException; //導入依賴的package包/類
private static void test(Class<?> type, Class<?> expected) {
    Class<?> actual;
    try {
        actual = Introspector.getBeanInfo(type).getBeanDescriptor().getCustomizerClass();
    }
    catch (IntrospectionException exception) {
        throw new Error("unexpected error", exception);
    }
    if (actual != expected) {
        StringBuilder sb = new StringBuilder();
        sb.append("bean ").append(type).append(": ");
        if (expected != null) {
            sb.append("expected ").append(expected);
            if (actual != null) {
                sb.append(", but ");
            }
        }
        if (actual != null) {
            sb.append("found ").append(actual);
        }
        throw new Error(sb.toString());
    }
}
 
開發者ID:lambdalab-mirror,項目名稱:jdk8u-jdk,代碼行數:24,代碼來源:Test6447751.java

示例9: initCollection

import java.beans.IntrospectionException; //導入依賴的package包/類
/** Initialize the collection with results of parsing of "Editors/AnnotationTypes" directory */
protected java.util.Collection initCollection() {
    
    AnnotationTypesFolder folder = AnnotationTypesFolder.getAnnotationTypesFolder();

    Iterator types = AnnotationTypes.getTypes().getAnnotationTypeNames();

    java.util.List list = new java.util.LinkedList();

    for( ; types.hasNext(); ) {
        String name = (String)types.next();
        AnnotationType type = AnnotationTypes.getTypes().getType(name);
        if (type == null || !type.isVisible())
            continue;
        try {
            list.add(new AnnotationTypesSubnode(type));
        } catch (IntrospectionException e) {
            Exceptions.printStackTrace(e);
            continue;
        }
    }

    return list;
}
 
開發者ID:apache,項目名稱:incubator-netbeans,代碼行數:25,代碼來源:AnnotationTypesNode.java

示例10: buildMap

import java.beans.IntrospectionException; //導入依賴的package包/類
private Map<String, PropertyDescriptor> buildMap(final Class<?> type) {
    Map<String, PropertyDescriptor> nameMap = propertyNameCache.get(type);
    if (nameMap == null) {
        BeanInfo beanInfo;
        try {
            beanInfo = Introspector.getBeanInfo(type, Object.class);
        } catch (final IntrospectionException e) {
            throw new ObjectAccessException("Cannot get BeanInfo of type " + type.getName(), e);
        }
        nameMap = new LinkedHashMap<String, PropertyDescriptor>();
        final PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (final PropertyDescriptor descriptor : propertyDescriptors) {
            nameMap.put(descriptor.getName(), descriptor);
        }
        nameMap = sorter.sort(type, nameMap);
        propertyNameCache.put(type, nameMap);
    }
    return nameMap;
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:20,代碼來源:PropertyDictionary.java

示例11: propertiesAreSerializedInCorrectOrder

import java.beans.IntrospectionException; //導入依賴的package包/類
@Test
@SuppressWarnings("rawtypes")
public void propertiesAreSerializedInCorrectOrder() throws ClassNotFoundException, IntrospectionException, InstantiationException, IllegalAccessException, InvocationTargetException {

    ClassLoader resultsClassLoader = schemaRule.generateAndCompile("/schema/properties/orderedProperties.json", "com.example");

    Class generatedType = resultsClassLoader.loadClass("com.example.OrderedProperties");
    Object instance = generatedType.newInstance();

    new PropertyDescriptor("type", generatedType).getWriteMethod().invoke(instance, "1");
    new PropertyDescriptor("id", generatedType).getWriteMethod().invoke(instance, "2");
    new PropertyDescriptor("name", generatedType).getWriteMethod().invoke(instance, "3");
    new PropertyDescriptor("hastickets", generatedType).getWriteMethod().invoke(instance, true);
    new PropertyDescriptor("starttime", generatedType).getWriteMethod().invoke(instance, "4");

    String serialized = mapper.valueToTree(instance).toString();

    assertThat("Properties are not in expected order", serialized.indexOf("type"), is(lessThan(serialized.indexOf("id"))));
    assertThat("Properties are not in expected order", serialized.indexOf("id"), is(lessThan(serialized.indexOf("name"))));
    assertThat("Properties are not in expected order", serialized.indexOf("name"), is(lessThan(serialized.indexOf("hastickets"))));
    assertThat("Properties are not in expected order", serialized.indexOf("hastickets"), is(lessThan(serialized.indexOf("starttime"))));

}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:24,代碼來源:PropertiesIT.java

示例12: getPropertyDescriptors

import java.beans.IntrospectionException; //導入依賴的package包/類
@Override
public PropertyDescriptor[] getPropertyDescriptors() {
    PropertyDescriptor[] p = new PropertyDescriptor[1];

    try {
        p[0] = new PropertyDescriptor ("x", Base.class, "getX", null);
        p[0].setShortDescription("BASEPROPERTY");
        p[0].setBound (baseFlag);
        p[0].setExpert(baseFlag);
        p[0].setHidden(baseFlag);
        p[0].setPreferred(baseFlag);
        p[0].setValue("required", baseFlag);
        p[0].setValue("visualUpdate", baseFlag);
        p[0].setValue("enumerationValues",
            new Object[]{"TOP", 1, "javax.swing.SwingConstants.TOP"});
    } catch(IntrospectionException e) { e.printStackTrace(); }

    return p;
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:20,代碼來源:OverrideUserDefPropertyInfoTest.java

示例13: createMethodsMap

import java.beans.IntrospectionException; //導入依賴的package包/類
private void createMethodsMap() {
    methodsMap = new LinkedHashMap<String, Method>();
    Method method;
    try {
        for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(entityClass)
                                                                 .getPropertyDescriptors()) {
            if (propertyDescriptor.getWriteMethod() != null && (method = propertyDescriptor.getReadMethod()) != null) {
                if (JdbcPersistable.class.isAssignableFrom(entityClass) && method.getName().equals(PERSISTABLE_IS_NEW_METHOD)) {
                    continue;
                }
                methodsMap.put(
                        SQLJavaNamingUtils.geColumnNameFromAttributeName(propertyDescriptor.getDisplayName()),
                        propertyDescriptor.getReadMethod());
            }
        }
    } catch (IntrospectionException e) {
        throw new RuntimeException(e);
    }
}
 
開發者ID:rubasace,項目名稱:spring-data-jdbc,代碼行數:20,代碼來源:ReflectionRowUnmapper.java

示例14: test

import java.beans.IntrospectionException; //導入依賴的package包/類
private static void test(StringBuilder sb) throws IntrospectionException {
    long time = 0L;
    if (sb != null) {
        sb.append("Time\t#Props\t#Events\t#Methods\tClass\n");
        sb.append("----------------------------------------");
        time = -System.currentTimeMillis();
    }
    for (Class type : TYPES) {
        test(sb, type);
    }
    if (sb != null) {
        time += System.currentTimeMillis();
        sb.append("\nTime: ").append(time).append(" ms\n");
        System.out.println(sb);
        sb.setLength(0);
    }
}
 
開發者ID:AdoptOpenJDK,項目名稱:openjdk-jdk10,代碼行數:18,代碼來源:TestIntrospector.java

示例15: deleteObject

import java.beans.IntrospectionException; //導入依賴的package包/類
@Override
public void deleteObject(T instance) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, IntrospectionException {
    // The file name of the Yaml file.
    PropertyDescriptor propertyDescriptor = new PropertyDescriptor("uniqueId", type);
    Method method = propertyDescriptor.getReadMethod();
    String fileName = (String) method.invoke(instance);
    if (!fileName.endsWith(".yml")) {
        fileName = fileName + ".yml";
    }
    File dataFolder = new File(plugin.getDataFolder(), DATABASE_FOLDER_NAME);
    File tableFolder = new File(dataFolder, type.getSimpleName());
    if (tableFolder.exists()) {
        File file = new File(tableFolder, fileName);
        file.delete();
    }
}
 
開發者ID:tastybento,項目名稱:bskyblock,代碼行數:17,代碼來源:FlatFileDatabaseHandler.java


注:本文中的java.beans.IntrospectionException類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。