jdk/src/share/classes/java/beans/MetaData.java
changeset 9548 225dbdc1cb74
parent 7668 d4a77089c587
child 11120 f8576c769572
equal deleted inserted replaced
9547:454881baaca0 9548:225dbdc1cb74
    54 import javax.swing.border.MatteBorder;
    54 import javax.swing.border.MatteBorder;
    55 import javax.swing.plaf.ColorUIResource;
    55 import javax.swing.plaf.ColorUIResource;
    56 
    56 
    57 import sun.swing.PrintColorUIResource;
    57 import sun.swing.PrintColorUIResource;
    58 
    58 
       
    59 import java.util.Objects;
       
    60 
    59 /*
    61 /*
    60  * Like the <code>Intropector</code>, the <code>MetaData</code> class
    62  * Like the <code>Intropector</code>, the <code>MetaData</code> class
    61  * contains <em>meta</em> objects that describe the way
    63  * contains <em>meta</em> objects that describe the way
    62  * classes should express their state in terms of their
    64  * classes should express their state in terms of their
    63  * own public APIs.
    65  * own public APIs.
   132             Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
   134             Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
   133             try {
   135             try {
   134                 Object oldValue = oldGetExp.getValue();
   136                 Object oldValue = oldGetExp.getValue();
   135                 Object newValue = newGetExp.getValue();
   137                 Object newValue = newGetExp.getValue();
   136                 out.writeExpression(oldGetExp);
   138                 out.writeExpression(oldGetExp);
   137                 if (!MetaData.equals(newValue, out.get(oldValue))) {
   139                 if (!Objects.equals(newValue, out.get(oldValue))) {
   138                     // System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
   140                     // System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
   139                     // invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
   141                     // invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
   140                     DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
   142                     DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
   141                 }
   143                 }
   142             }
   144             }
   633             Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
   635             Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
   634             try {
   636             try {
   635                 Object oldValue = oldGetExp.getValue();
   637                 Object oldValue = oldGetExp.getValue();
   636                 Object newValue = newGetExp.getValue();
   638                 Object newValue = newGetExp.getValue();
   637                 out.writeExpression(oldGetExp);
   639                 out.writeExpression(oldGetExp);
   638                 if (!MetaData.equals(newValue, out.get(oldValue))) {
   640                 if (!Objects.equals(newValue, out.get(oldValue))) {
   639                     invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
   641                     invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
   640                 }
   642                 }
   641             }
   643             }
   642             catch (Exception e) {
   644             catch (Exception e) {
   643                 out.getExceptionListener().exceptionThrown(e);
   645                 out.getExceptionListener().exceptionThrown(e);
   673             Expression newGetExp = new Expression(newInstance, "get", new Object[]{oldKey});
   675             Expression newGetExp = new Expression(newInstance, "get", new Object[]{oldKey});
   674             try {
   676             try {
   675                 Object oldValue = oldGetExp.getValue();
   677                 Object oldValue = oldGetExp.getValue();
   676                 Object newValue = newGetExp.getValue();
   678                 Object newValue = newGetExp.getValue();
   677                 out.writeExpression(oldGetExp);
   679                 out.writeExpression(oldGetExp);
   678                 if (!MetaData.equals(newValue, out.get(oldValue))) {
   680                 if (!Objects.equals(newValue, out.get(oldValue))) {
   679                     invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
   681                     invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
   680                 } else if ((newValue == null) && !newMap.containsKey(oldKey)) {
   682                 } else if ((newValue == null) && !newMap.containsKey(oldKey)) {
   681                     // put oldValue(=null?) if oldKey is absent in newMap
   683                     // put oldValue(=null?) if oldKey is absent in newMap
   682                     invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
   684                     invokeStatement(oldInstance, "put", new Object[]{oldKey, oldValue}, out);
   683                 }
   685                 }
   897         // null to defined values after the Windows are made visible -
   899         // null to defined values after the Windows are made visible -
   898         // special case them for now.
   900         // special case them for now.
   899         if (!(oldInstance instanceof java.awt.Window)) {
   901         if (!(oldInstance instanceof java.awt.Window)) {
   900             Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
   902             Object oldBackground = c.isBackgroundSet() ? c.getBackground() : null;
   901             Object newBackground = c2.isBackgroundSet() ? c2.getBackground() : null;
   903             Object newBackground = c2.isBackgroundSet() ? c2.getBackground() : null;
   902             if (!MetaData.equals(oldBackground, newBackground)) {
   904             if (!Objects.equals(oldBackground, newBackground)) {
   903                 invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
   905                 invokeStatement(oldInstance, "setBackground", new Object[] { oldBackground }, out);
   904             }
   906             }
   905             Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
   907             Object oldForeground = c.isForegroundSet() ? c.getForeground() : null;
   906             Object newForeground = c2.isForegroundSet() ? c2.getForeground() : null;
   908             Object newForeground = c2.isForegroundSet() ? c2.getForeground() : null;
   907             if (!MetaData.equals(oldForeground, newForeground)) {
   909             if (!Objects.equals(oldForeground, newForeground)) {
   908                 invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
   910                 invokeStatement(oldInstance, "setForeground", new Object[] { oldForeground }, out);
   909             }
   911             }
   910             Object oldFont = c.isFontSet() ? c.getFont() : null;
   912             Object oldFont = c.isFontSet() ? c.getFont() : null;
   911             Object newFont = c2.isFontSet() ? c2.getFont() : null;
   913             Object newFont = c2.isFontSet() ? c2.getFont() : null;
   912             if (!MetaData.equals(oldFont, newFont)) {
   914             if (!Objects.equals(oldFont, newFont)) {
   913                 invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
   915                 invokeStatement(oldInstance, "setFont", new Object[] { oldFont }, out);
   914             }
   916             }
   915         }
   917         }
   916 
   918 
   917         // Bounds
   919         // Bounds
  1302         internalPersistenceDelegates.put("java.sql.Date", new java_util_Date_PersistenceDelegate());
  1304         internalPersistenceDelegates.put("java.sql.Date", new java_util_Date_PersistenceDelegate());
  1303         internalPersistenceDelegates.put("java.sql.Time", new java_util_Date_PersistenceDelegate());
  1305         internalPersistenceDelegates.put("java.sql.Time", new java_util_Date_PersistenceDelegate());
  1304 
  1306 
  1305         internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate());
  1307         internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate());
  1306         internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
  1308         internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
  1307     }
       
  1308 
       
  1309     /*pp*/ static boolean equals(Object o1, Object o2) {
       
  1310         return (o1 == null) ? (o2 == null) : o1.equals(o2);
       
  1311     }
  1309     }
  1312 
  1310 
  1313     public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
  1311     public synchronized static PersistenceDelegate getPersistenceDelegate(Class type) {
  1314         if (type == null) {
  1312         if (type == null) {
  1315             return nullPersistenceDelegate;
  1313             return nullPersistenceDelegate;