当前位置: 首页>>代码示例>>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;未经允许,请勿转载。