jdk/src/share/classes/java/beans/Introspector.java

Print this page




 730                 // Complete indexed properties set
 731                 // Merge any classic property descriptors
 732                 if (gpd != null) {
 733                     PropertyDescriptor tpd = mergePropertyDescriptor(igpd, gpd);
 734                     if (tpd instanceof IndexedPropertyDescriptor) {
 735                         igpd = (IndexedPropertyDescriptor)tpd;
 736                     }
 737                 }
 738                 if (spd != null) {
 739                     PropertyDescriptor tpd = mergePropertyDescriptor(ispd, spd);
 740                     if (tpd instanceof IndexedPropertyDescriptor) {
 741                         ispd = (IndexedPropertyDescriptor)tpd;
 742                     }
 743                 }
 744                 if (igpd == ispd) {
 745                     pd = igpd;
 746                 } else {
 747                     pd = mergePropertyDescriptor(igpd, ispd);
 748                 }
 749             } else if (gpd != null && spd != null) {






 750                 // Complete simple properties set
 751                 if (gpd == spd) {
 752                     pd = gpd;




 753                 } else {
 754                     pd = mergePropertyDescriptor(gpd, spd);
 755                 }
 756             } else if (ispd != null) {
 757                 // indexed setter
 758                 pd = ispd;
 759                 // Merge any classic property descriptors
 760                 if (spd != null) {
 761                     pd = mergePropertyDescriptor(ispd, spd);
 762                 }
 763                 if (gpd != null) {
 764                     pd = mergePropertyDescriptor(ispd, gpd);
 765                 }
 766             } else if (igpd != null) {
 767                 // indexed getter
 768                 pd = igpd;
 769                 // Merge any classic property descriptors
 770                 if (gpd != null) {
 771                     pd = mergePropertyDescriptor(igpd, gpd);
 772                 }


 790                 if (ipd.getIndexedReadMethod() == null && ipd.getIndexedWriteMethod() == null) {
 791                     pd = new PropertyDescriptor(ipd);
 792                 }
 793             }
 794 
 795             // Find the first property descriptor
 796             // which does not have getter and setter methods.
 797             // See regression bug 4984912.
 798             if ( (pd == null) && (list.size() > 0) ) {
 799                 pd = list.get(0);
 800             }
 801 
 802             if (pd != null) {
 803                 properties.put(pd.getName(), pd);
 804             }
 805         }
 806     }
 807 
 808     private static boolean isAssignable(Class<?> current, Class<?> candidate) {
 809         return current == null ? candidate == null : current.isAssignableFrom(candidate);










 810     }
 811 
 812     /**
 813      * Adds the property descriptor to the indexedproperty descriptor only if the
 814      * types are the same.
 815      *
 816      * The most specific property descriptor will take precedence.
 817      */
 818     private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd,
 819                                                        PropertyDescriptor pd) {
 820         PropertyDescriptor result = null;
 821 
 822         Class<?> propType = pd.getPropertyType();
 823         Class<?> ipropType = ipd.getIndexedPropertyType();
 824 
 825         if (propType.isArray() && propType.getComponentType() == ipropType) {
 826             if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
 827                 result = new IndexedPropertyDescriptor(pd, ipd);
 828             } else {
 829                 result = new IndexedPropertyDescriptor(ipd, pd);




 730                 // Complete indexed properties set
 731                 // Merge any classic property descriptors
 732                 if (gpd != null) {
 733                     PropertyDescriptor tpd = mergePropertyDescriptor(igpd, gpd);
 734                     if (tpd instanceof IndexedPropertyDescriptor) {
 735                         igpd = (IndexedPropertyDescriptor)tpd;
 736                     }
 737                 }
 738                 if (spd != null) {
 739                     PropertyDescriptor tpd = mergePropertyDescriptor(ispd, spd);
 740                     if (tpd instanceof IndexedPropertyDescriptor) {
 741                         ispd = (IndexedPropertyDescriptor)tpd;
 742                     }
 743                 }
 744                 if (igpd == ispd) {
 745                     pd = igpd;
 746                 } else {
 747                     pd = mergePropertyDescriptor(igpd, ispd);
 748                 }
 749             } else if (gpd != null && spd != null) {
 750                 if (igpd != null) {
 751                     gpd = mergePropertyWithIndexedProperty(gpd, igpd);
 752                 }
 753                 if (ispd != null) {
 754                     spd = mergePropertyWithIndexedProperty(spd, ispd);
 755                 }
 756                 // Complete simple properties set
 757                 if (gpd == spd) {
 758                     pd = gpd;
 759                 } else if (spd instanceof IndexedPropertyDescriptor) {
 760                     pd = mergePropertyWithIndexedProperty(gpd, (IndexedPropertyDescriptor) spd);
 761                 } else if (gpd instanceof IndexedPropertyDescriptor) {
 762                     pd = mergePropertyWithIndexedProperty(spd, (IndexedPropertyDescriptor) gpd);
 763                 } else {
 764                     pd = mergePropertyDescriptor(gpd, spd);
 765                 }
 766             } else if (ispd != null) {
 767                 // indexed setter
 768                 pd = ispd;
 769                 // Merge any classic property descriptors
 770                 if (spd != null) {
 771                     pd = mergePropertyDescriptor(ispd, spd);
 772                 }
 773                 if (gpd != null) {
 774                     pd = mergePropertyDescriptor(ispd, gpd);
 775                 }
 776             } else if (igpd != null) {
 777                 // indexed getter
 778                 pd = igpd;
 779                 // Merge any classic property descriptors
 780                 if (gpd != null) {
 781                     pd = mergePropertyDescriptor(igpd, gpd);
 782                 }


 800                 if (ipd.getIndexedReadMethod() == null && ipd.getIndexedWriteMethod() == null) {
 801                     pd = new PropertyDescriptor(ipd);
 802                 }
 803             }
 804 
 805             // Find the first property descriptor
 806             // which does not have getter and setter methods.
 807             // See regression bug 4984912.
 808             if ( (pd == null) && (list.size() > 0) ) {
 809                 pd = list.get(0);
 810             }
 811 
 812             if (pd != null) {
 813                 properties.put(pd.getName(), pd);
 814             }
 815         }
 816     }
 817 
 818     private static boolean isAssignable(Class<?> current, Class<?> candidate) {
 819         return current == null ? candidate == null : current.isAssignableFrom(candidate);
 820     }
 821 
 822     private PropertyDescriptor mergePropertyWithIndexedProperty(PropertyDescriptor pd, IndexedPropertyDescriptor ipd) {
 823         Class<?> type = pd.getPropertyType();
 824         if (type.isArray() && (type.getComponentType() == ipd.getIndexedPropertyType())) {
 825             return pd.getClass0().isAssignableFrom(ipd.getClass0())
 826                     ? new IndexedPropertyDescriptor(pd, ipd)
 827                     : new IndexedPropertyDescriptor(ipd, pd);
 828         }
 829         return pd;
 830     }
 831 
 832     /**
 833      * Adds the property descriptor to the indexedproperty descriptor only if the
 834      * types are the same.
 835      *
 836      * The most specific property descriptor will take precedence.
 837      */
 838     private PropertyDescriptor mergePropertyDescriptor(IndexedPropertyDescriptor ipd,
 839                                                        PropertyDescriptor pd) {
 840         PropertyDescriptor result = null;
 841 
 842         Class<?> propType = pd.getPropertyType();
 843         Class<?> ipropType = ipd.getIndexedPropertyType();
 844 
 845         if (propType.isArray() && propType.getComponentType() == ipropType) {
 846             if (pd.getClass0().isAssignableFrom(ipd.getClass0())) {
 847                 result = new IndexedPropertyDescriptor(pd, ipd);
 848             } else {
 849                 result = new IndexedPropertyDescriptor(ipd, pd);