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


Java Introspector类代码示例

本文整理汇总了Java中java.beans.Introspector的典型用法代码示例。如果您正苦于以下问题:Java Introspector类的具体用法?Java Introspector怎么用?Java Introspector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


Introspector类属于java.beans包,在下文中一共展示了Introspector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import java.beans.Introspector; //导入依赖的package包/类
public void run() {
    Introspector.flushCaches();

    test(FirstBean.class, FirstBeanBeanInfo.class);
    test(SecondBean.class, null);
    test(ThirdBean.class, null);
    test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);

    Introspector.setBeanInfoSearchPath(SEARCH_PATH);
    Introspector.flushCaches();

    test(FirstBean.class, FirstBeanBeanInfo.class);
    test(SecondBean.class, SecondBeanBeanInfo.class);
    test(ThirdBean.class, null);
    test(ThirdBeanBeanInfo.class, ThirdBeanBeanInfo.class);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:TestBeanInfo.java

示例2: getAttributes

import java.beans.Introspector; //导入依赖的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

示例3: main

import java.beans.Introspector; //导入依赖的package包/类
public static void main(String[] args) throws IntrospectionException {
    StringBuilder sb = null;
    if (args.length > 0) {
        if (args[0].equals("show")) {
            sb = new StringBuilder(65536);
        }
    }
    Introspector.flushCaches();
    int count = (sb != null) ? 10 : 100;
    long time = -System.currentTimeMillis();
    for (int i = 0; i < count; i++) {
        test(sb);
        test(sb);
        Introspector.flushCaches();
    }
    time += System.currentTimeMillis();
    System.out.println("Time (average): " + time / count);
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:TestIntrospector.java

示例4: resolveParamProperties

import java.beans.Introspector; //导入依赖的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

示例5: findGetter

import java.beans.Introspector; //导入依赖的package包/类
/**
 * Cache the method if possible, using the classname and property name to
 * allow for similar named methods.
 * @param data The bean to introspect
 * @param property The property to get the accessor for
 * @return The getter method
 * @throws IntrospectionException
 */
protected Method findGetter(Object data, String property) throws IntrospectionException
{
    String key = data.getClass().getName() + ":" + property;

    Method method = (Method) methods.get(key);
    if (method == null)
    {
        PropertyDescriptor[] props = Introspector.getBeanInfo(data.getClass()).getPropertyDescriptors();
        for (int i = 0; i < props.length; i++)
        {
            if (props[i].getName().equalsIgnoreCase(property))
            {
                method = props[i].getReadMethod();
            }
        }

        methods.put(key, method);
    }

    return method;
}
 
开发者ID:parabuild-ci,项目名称:parabuild-ci,代码行数:30,代码来源:H3BeanConverter.java

示例6: getDescription

import java.beans.Introspector; //导入依赖的package包/类
private String getDescription (Lookup.Item item) {
    String id = item.getId ();
    String result = null;
    try {
        result = Introspector.getBeanInfo(item.getInstance().getClass()).getBeanDescriptor().getShortDescription();
    } catch (IntrospectionException ie) {
        //do nothing
    }
    String toCheck = item.getInstance().getClass().getName();
    toCheck = toCheck.lastIndexOf('.')!=-1 ? 
        toCheck.substring(toCheck.lastIndexOf('.')+1) : toCheck; //NOI18N
    if (toCheck.equals(result)) {
        result = null;
    } 
    return result;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:17,代码来源:ObjectEditor.java

示例7: getBeanInfo

import java.beans.Introspector; //导入依赖的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:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:17,代码来源:Test4520754.java

示例8: findIndexedPropertyName

import java.beans.Introspector; //导入依赖的package包/类
/** Based on names of indexedGetter and indexedSetter resolves the name
 * of the indexed property.
 * @return Name of the indexed property
 */ 
String findIndexedPropertyName() {
    String superName = findPropertyName();

    if ( superName == null ) {
        String methodName = null;

        if ( indexedGetterMethod != null )
            methodName = nameAsString(indexedGetterMethod);
        else if ( indexedSetterMethod != null )
            methodName = nameAsString(indexedSetterMethod);
        else
            throw new InternalError( "Indexed property with all methods == null" ); // NOI18N

        return methodName.startsWith( IS_PREFIX ) ? // NOI18N
               Introspector.decapitalize( methodName.substring(2) ) :
               Introspector.decapitalize( methodName.substring(3) );
    }
    else
        return superName;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:25,代码来源:TmpPattern.java

示例9: Reflection

import java.beans.Introspector; //导入依赖的package包/类
/** Create a support with method objects specified.
* The methods must be public.
* @param instance (Bean) object to work on
* @param valueType type of the property
* @param getter getter method, can be <code>null</code>
* @param setter setter method, can be <code>null</code>
* @throws IllegalArgumentException if the methods are not public
*/
public Reflection(Object instance, Class<T> valueType, Method getter, Method setter) {
    super(valueType);

    if ((getter != null) && !Modifier.isPublic(getter.getModifiers())) {
        throw new IllegalArgumentException("Cannot use a non-public getter " + getter); // NOI18N
    }

    if ((setter != null) && !Modifier.isPublic(setter.getModifiers())) {
        throw new IllegalArgumentException("Cannot use a non-public setter " + setter); // NOI18N
    }

    if (getter != null) {
        setName(Introspector.decapitalize(getter.getName().replaceFirst("^(get|is|has)", "")));
    } else if (setter != null) {
        setName(Introspector.decapitalize(setter.getName().replaceFirst("^set", "")));
    }

    this.instance = instance;
    this.setter = setter;
    this.getter = getter;
}
 
开发者ID:apache,项目名称:incubator-netbeans,代码行数:30,代码来源:PropertySupport.java

示例10: main

import java.beans.Introspector; //导入依赖的package包/类
public static void main(String[] args) throws IntrospectionException {
    if (!BeanUtils.findPropertyDescriptor(MyBean.class, "test").isBound()) {
        throw new Error("a simple property is not bound");
    }
    if (!BeanUtils.findPropertyDescriptor(MyBean.class, "list").isBound()) {
        throw new Error("a generic property is not bound");
    }
    if (!BeanUtils.findPropertyDescriptor(MyBean.class, "readOnly").isBound()) {
        throw new Error("a read-only property is not bound");
    }
    PropertyDescriptor[] pds = Introspector.getBeanInfo(MyBean.class, BaseBean.class).getPropertyDescriptors();
    for (PropertyDescriptor pd : pds) {
        if (pd.getName().equals("test") && pd.isBound()) {
            throw new Error("a simple property is bound without superclass");
        }
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:18,代码来源:Test7192955.java

示例11: transMap2Bean

import java.beans.Introspector; //导入依赖的package包/类
public static void transMap2Bean(Map<String, Object> map, Object obj) {
	try {
		BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
		PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
		for (PropertyDescriptor property : propertyDescriptors) {
			String key = property.getName();
			if (map.containsKey(key)) {
				Object value = map.get(key);
				// 得到property对应的setter方法
				Method setter = property.getWriteMethod();
				setter.invoke(obj, value);
			}
		}
	} catch (Exception e) {
		System.out.println("transMap2Bean Error " + e);
	}
	return;
}
 
开发者ID:tb544731152,项目名称:iBase4J,代码行数:19,代码来源:InstanceUtil.java

示例12: 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:DomKing,项目名称:springbootWeb,代码行数:25,代码来源:RootClassInfo.java

示例13: main

import java.beans.Introspector; //导入依赖的package包/类
public static void main(String[] arg) throws Exception {
    BeanInfo info = Introspector.getBeanInfo(My.class);
    if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
        throw new Error("Unexpected behavior");
    }
    try {
        int[] array = new int[1024];
        while (true) {
            array = new int[array.length << 1];
        }
    }
    catch (OutOfMemoryError error) {
        System.gc();
    }
    if (null == info.getIcon(BeanInfo.ICON_COLOR_16x16)) {
        throw new Error("Explicit BeanInfo is collected");
    }
}
 
开发者ID:lambdalab-mirror,项目名称:jdk8u-jdk,代码行数:19,代码来源:Test7195106.java

示例14: collectParameters

import java.beans.Introspector; //导入依赖的package包/类
private static void collectParameters(Collection<Parameters> parameters, Parameter parameter, Annotation a,
		boolean isPathVariable) {
	if (a != null) {
		String typeStr = parameter.getType().getSimpleName();
		Type type = parameter.getParameterizedType();
		if (type instanceof ParameterizedType) {
			typeStr = ((Class<?>) ((ParameterizedType) type).getActualTypeArguments()[0]).getSimpleName();
		}
		parameters.add(new Parameters((boolean) AnnotationUtils.getValue(a, "required"),
				(String) (AnnotationUtils.getValue(a).equals("") ? parameter.getName()
						: AnnotationUtils.getValue(a)),
				typeStr));
	} else if (Pageable.class.isAssignableFrom(parameter.getType()) && !isPathVariable) {
		try {
			for (PropertyDescriptor propertyDescriptor : Introspector.getBeanInfo(parameter.getType())
					.getPropertyDescriptors()) {
				parameters.add(new Parameters(false, propertyDescriptor.getName(),
						propertyDescriptor.getPropertyType().getSimpleName()));
			}
		} catch (IntrospectionException e) {
			LOGGER.error("Problemas al obtener el Pageable: {}", parameter, e);
		}
	}
}
 
开发者ID:damianwajser,项目名称:spring-rest-commons-options,代码行数:25,代码来源:ReflectionUtils.java

示例15: transMap2Bean

import java.beans.Introspector; //导入依赖的package包/类
public static void transMap2Bean(Map<String, Object> map, Object obj) {
    try {
        BeanInfo beanInfo = Introspector.getBeanInfo(obj.getClass());
        PropertyDescriptor[] propertyDescriptors = beanInfo.getPropertyDescriptors();
        for (PropertyDescriptor property : propertyDescriptors) {
            String key = property.getName();
            if (map.containsKey(key)) {
                Object value = map.get(key);
                // 得到property对应的setter方法
                Method setter = property.getWriteMethod();
                setter.invoke(obj, value);
            }
        }
    } catch (Exception e) {
        System.out.println("transMap2Bean Error " + e);
    }
    return;
}
 
开发者ID:youngMen1,项目名称:JAVA-,代码行数:19,代码来源:InstanceUtil.java


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