src/share/classes/java/beans/MetaData.java

Print this page




1384         String[] names = null;
1385         int length = 0;
1386         for (Constructor<?> constructor : type.getConstructors()) {
1387             String[] value = getAnnotationValue(constructor);
1388             if ((value != null) && (length < value.length) && isValid(constructor, value)) {
1389                 names = value;
1390                 length = value.length;
1391             }
1392         }
1393         return names;
1394     }
1395 
1396     private static String[] getAnnotationValue(Constructor<?> constructor) {
1397         ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
1398         return (annotation != null)
1399                 ? annotation.value()
1400                 : null;
1401     }
1402 
1403     private static boolean isValid(Constructor<?> constructor, String[] names) {
1404         Class[] parameters = constructor.getParameterTypes();
1405         if (names.length != parameters.length) {
1406             return false;
1407         }
1408         for (String name : names) {
1409             if (name == null) {
1410                 return false;
1411             }
1412         }
1413         return true;
1414     }
1415 
1416     private static Object getBeanAttribute(Class<?> type, String attribute) {
1417         try {
1418             return Introspector.getBeanInfo(type).getBeanDescriptor().getValue(attribute);
1419         } catch (IntrospectionException exception) {
1420             return null;
1421         }
1422     }
1423 
1424     static Object getPrivateFieldValue(Object instance, String name) {




1384         String[] names = null;
1385         int length = 0;
1386         for (Constructor<?> constructor : type.getConstructors()) {
1387             String[] value = getAnnotationValue(constructor);
1388             if ((value != null) && (length < value.length) && isValid(constructor, value)) {
1389                 names = value;
1390                 length = value.length;
1391             }
1392         }
1393         return names;
1394     }
1395 
1396     private static String[] getAnnotationValue(Constructor<?> constructor) {
1397         ConstructorProperties annotation = constructor.getAnnotation(ConstructorProperties.class);
1398         return (annotation != null)
1399                 ? annotation.value()
1400                 : null;
1401     }
1402 
1403     private static boolean isValid(Constructor<?> constructor, String[] names) {
1404         Class<?>[] parameters = constructor.getParameterTypes();
1405         if (names.length != parameters.length) {
1406             return false;
1407         }
1408         for (String name : names) {
1409             if (name == null) {
1410                 return false;
1411             }
1412         }
1413         return true;
1414     }
1415 
1416     private static Object getBeanAttribute(Class<?> type, String attribute) {
1417         try {
1418             return Introspector.getBeanInfo(type).getBeanDescriptor().getValue(attribute);
1419         } catch (IntrospectionException exception) {
1420             return null;
1421         }
1422     }
1423 
1424     static Object getPrivateFieldValue(Object instance, String name) {