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