/*
* Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
* ORACLE PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package java.beans;
import com.sun.beans.finder.PrimitiveWrapperMap;
import java.awt.AWTKeyStroke;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Color;
import java.awt.Font;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.event.KeyEvent;
import java.awt.font.TextAttribute;
import java.lang.reflect.Array;
import java.lang.reflect.Constructor;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.lang.reflect.InvocationTargetException;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.*;
import javax.swing.Box;
import javax.swing.JLayeredPane;
import javax.swing.border.MatteBorder;
import javax.swing.plaf.ColorUIResource;
import sun.swing.PrintColorUIResource;
import static sun.reflect.misc.ReflectUtil.isPackageAccessible;
/*
* Like the Intropector
, the MetaData
class
* contains meta objects that describe the way
* classes should express their state in terms of their
* own public APIs.
*
* @see java.beans.Intropector
*
* @author Philip Milne
* @author Steve Langley
*/
class MetaData {
static final class NullPersistenceDelegate extends PersistenceDelegate {
// Note this will be called by all classes when they reach the
// top of their superclass chain.
protected void initialize(Class> type, Object oldInstance, Object newInstance, Encoder out) {
}
protected Expression instantiate(Object oldInstance, Encoder out) { return null; }
public void writeObject(Object oldInstance, Encoder out) {
// System.out.println("NullPersistenceDelegate:writeObject " + oldInstance);
}
}
/**
* The persistence delegate for enum
classes.
*
* @author Sergey A. Malenkov
*/
static final class EnumPersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance == newInstance;
}
protected Expression instantiate(Object oldInstance, Encoder out) {
Enum> e = (Enum>) oldInstance;
return new Expression(e, Enum.class, "valueOf", new Object[]{e.getDeclaringClass(), e.name()});
}
}
static final class PrimitivePersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return oldInstance.equals(newInstance);
}
protected Expression instantiate(Object oldInstance, Encoder out) {
return new Expression(oldInstance, oldInstance.getClass(),
"new", new Object[]{oldInstance.toString()});
}
}
static final class ArrayPersistenceDelegate extends PersistenceDelegate {
protected boolean mutatesTo(Object oldInstance, Object newInstance) {
return (newInstance != null &&
oldInstance.getClass() == newInstance.getClass() && // Also ensures the subtype is correct.
Array.getLength(oldInstance) == Array.getLength(newInstance));
}
protected Expression instantiate(Object oldInstance, Encoder out) {
// System.out.println("instantiate: " + type + " " + oldInstance);
Class> oldClass = oldInstance.getClass();
return new Expression(oldInstance, Array.class, "newInstance",
new Object[]{oldClass.getComponentType(),
new Integer(Array.getLength(oldInstance))});
}
protected void initialize(Class> type, Object oldInstance, Object newInstance, Encoder out) {
int n = Array.getLength(oldInstance);
for (int i = 0; i < n; i++) {
Object index = new Integer(i);
// Expression oldGetExp = new Expression(Array.class, "get", new Object[]{oldInstance, index});
// Expression newGetExp = new Expression(Array.class, "get", new Object[]{newInstance, index});
Expression oldGetExp = new Expression(oldInstance, "get", new Object[]{index});
Expression newGetExp = new Expression(newInstance, "get", new Object[]{index});
try {
Object oldValue = oldGetExp.getValue();
Object newValue = newGetExp.getValue();
out.writeExpression(oldGetExp);
if (!Objects.equals(newValue, out.get(oldValue))) {
// System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
// invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
DefaultPersistenceDelegate.invokeStatement(oldInstance, "set", new Object[]{index, oldValue}, out);
}
}
catch (Exception e) {
// System.err.println("Warning:: failed to write: " + oldGetExp);
out.getExceptionListener().exceptionThrown(e);
}
}
}
}
static final class ProxyPersistenceDelegate extends PersistenceDelegate {
protected Expression instantiate(Object oldInstance, Encoder out) {
Class> type = oldInstance.getClass();
java.lang.reflect.Proxy p = (java.lang.reflect.Proxy)oldInstance;
// This unappealing hack is not required but makes the
// representation of EventHandlers much more concise.
java.lang.reflect.InvocationHandler ih = java.lang.reflect.Proxy.getInvocationHandler(p);
if (ih instanceof EventHandler) {
EventHandler eh = (EventHandler)ih;
Vector