/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/*
* Like the <code>Intropector</code>, the <code>MetaData</code> class
* contains <em>meta</em> 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 {
// Note this will be called by all classes when they reach the
// top of their superclass chain.
}
// System.out.println("NullPersistenceDelegate:writeObject " + oldInstance);
}
}
/**
* The persistence delegate for <CODE>enum</CODE> classes.
*
* @author Sergey A. Malenkov
*/
return oldInstance == newInstance;
}
}
}
}
}
}
return (newInstance != null &&
}
// System.out.println("instantiate: " + type + " " + oldInstance);
}
for (int i = 0; i < n; i++) {
// Expression oldGetExp = new Expression(Array.class, "get", new Object[]{oldInstance, index});
// Expression newGetExp = new Expression(Array.class, "get", new Object[]{newInstance, index});
try {
// System.out.println("Not equal: " + newGetExp + " != " + actualGetExp);
// invokeStatement(Array.class, "set", new Object[]{oldInstance, index, oldValue}, out);
}
}
catch (Exception e) {
// System.err.println("Warning:: failed to write: " + oldGetExp);
}
}
}
}
// This unappealing hack is not required but makes the
// representation of EventHandlers much more concise.
if (ih instanceof EventHandler) {
}
}
return new Expression(oldInstance,
EventHandler.class,
"create",
}
return new Expression(oldInstance,
"newProxyInstance",
ih});
}
}
// Strings
// System.out.println("NullPersistenceDelegate:writeObject " + oldInstance);
}
}
// Classes
}
// As of 1.3 it is not possible to call Class.forName("int"),
// so we have to generate different code for primitive types.
// This is needed for arrays whose subtype may be primitive.
if (c.isPrimitive()) {
try {
} catch (NoSuchFieldException ex) {
}
}
else if (oldInstance == String.class) {
}
else if (oldInstance == Class.class) {
}
else {
Expression newInstance = new Expression(oldInstance, Class.class, "forName", new Object[] { c.getName() });
return newInstance;
}
}
}
// Fields
}
return new Expression(oldInstance,
f.getDeclaringClass(),
"getField",
}
}
// Methods
}
return new Expression(oldInstance,
m.getDeclaringClass(),
"getMethod",
}
}
// Dates
/**
* The persistence delegate for <CODE>java.util.Date</CODE> classes.
* Do not extend DefaultPersistenceDelegate to improve performance and
* to avoid problems with <CODE>java.sql.Date</CODE>,
* <CODE>java.sql.Time</CODE> and <CODE>java.sql.Timestamp</CODE>.
*
* @author Sergey A. Malenkov
*/
return false;
}
}
}
}
/**
* The persistence delegate for <CODE>java.sql.Timestamp</CODE> classes.
* It supports nanoseconds.
*
* @author Sergey A. Malenkov
*/
static final class java_sql_Timestamp_PersistenceDelegate extends java_util_Date_PersistenceDelegate {
try {
return c.getMethod("getNanos");
} catch (ClassNotFoundException e) {
return null;
} catch (NoSuchMethodException e) {
throw new AssertionError(e);
}
}
/**
* Invoke Timstamp getNanos.
*/
if (getNanosMethod == null)
throw new AssertionError("Should not get here");
try {
} catch (InvocationTargetException e) {
if (cause instanceof RuntimeException)
throw (RuntimeException)cause;
throw new AssertionError(e);
} catch (IllegalAccessException iae) {
throw new AssertionError(iae);
}
}
// assumes oldInstance and newInstance are Timestamps
}
}
}
// Collections
/*
The Hashtable and AbstractMap classes have no common ancestor yet may
be handled with a single persistence delegate: one which uses the methods
of the Map insterface exclusively. Attatching the persistence delegates
to the interfaces themselves is fraught however since, in the case of
the Map, both the AbstractMap and HashMap classes are declared to
implement the Map interface, leaving the obvious implementation prone
to repeating their initialization. These issues and questions around
the ordering of delegates attached to interfaces have lead us to
ignore any delegates attached to interfaces and force all persistence
delegates to be registered with concrete classes.
*/
/**
* The base class for persistence delegates for inner classes
* that can be created using {@link Collections}.
*
* @author Sergey A. Malenkov
*/
return false;
}
if ((oldInstance instanceof List) || (oldInstance instanceof Set) || (oldInstance instanceof Map)) {
}
}
// do not initialize these custom collections in default way
}
}
}
}
}
}
}
}
}
return new Expression(oldInstance, Collections.class, "singleton", new Object[]{set.iterator().next()});
}
}
return new Expression(oldInstance, Collections.class, "singletonMap", new Object[]{key, map.get(key)});
}
}
return new Expression(oldInstance, Collections.class, "unmodifiableCollection", new Object[]{list});
}
}
}
}
}
}
}
}
}
}
}
}
}
}
return new Expression(oldInstance, Collections.class, "synchronizedCollection", new Object[]{list});
}
}
}
}
}
}
}
}
}
}
}
}
}
}
Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
return new Expression(oldInstance, Collections.class, "checkedCollection", new Object[]{list, type});
}
}
Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
}
}
Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
}
}
Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
}
}
Object type = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedCollection.type");
}
}
Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
return new Expression(oldInstance, Collections.class, "checkedMap", new Object[]{map, keyType, valueType});
}
}
Object keyType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.keyType");
Object valueType = MetaData.getPrivateFieldValue(oldInstance, "java.util.Collections$CheckedMap.valueType");
return new Expression(oldInstance, Collections.class, "checkedSortedMap", new Object[]{map, keyType, valueType});
}
}
}
/**
* The persistence delegate for <CODE>java.util.EnumMap</CODE> classes.
*
* @author Sergey A. Malenkov
*/
}
}
}
}
/**
* The persistence delegate for <CODE>java.util.EnumSet</CODE> classes.
*
* @author Sergey A. Malenkov
*/
}
}
}
}
// Collection
}
}
}
}
// List
newSize = 0;
}
for (int i = 0; i < newSize; i++) {
try {
}
}
catch (Exception e) {
}
}
}
}
}
// Map
// System.out.println("Initializing: " + newInstance);
// Remove the new elements.
// Do this first otherwise we undo the adding work.
// PENDING: This "key" is not in the right environment.
}
}
}
// Add the new elements.
// Pending: should use newKey.
try {
// put oldValue(=null?) if oldKey is absent in newMap
}
}
catch (Exception e) {
}
}
}
}
static final class java_util_AbstractCollection_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
static final class java_util_AbstractList_PersistenceDelegate extends java_util_List_PersistenceDelegate {}
static final class java_util_AbstractMap_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
static final class java_util_Hashtable_PersistenceDelegate extends java_util_Map_PersistenceDelegate {}
// Beans
static final class java_beans_beancontext_BeanContextSupport_PersistenceDelegate extends java_util_Collection_PersistenceDelegate {}
// AWT
/**
* The persistence delegate for {@link Insets}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because this class does not have any properties.
*
* @author Sergey A. Malenkov
*/
}
};
}
}
/**
* The persistence delegate for {@link Font}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because size of the font can be float value.
*
* @author Sergey A. Malenkov
*/
}
int count = 0;
int size = 12;
}
count++;
}
}
count++;
count++;
}
}
count++;
count++;
}
count++;
}
}
}
}
}
}
}
}
/**
* The persistence delegate for {@link AWTKeyStroke}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because this class have no public constructor.
*
* @author Sergey A. Malenkov
*/
}
args = !onKeyRelease
if (!onKeyRelease) {
} else if (mask == 0) {
}
}
}
// get short name of the class
if (index > 0) {
}
}
}
// Don't install primitives, their identity will not be preserved
// by wrapping.
}
}
}
}
}
}
}
// SystemColor
static final class java_awt_SystemColor_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
// TextAttribute
static final class java_awt_font_TextAttribute_PersistenceDelegate extends StaticFieldsPersistenceDelegate {}
// MenuShortcut
}
}
}
// Component
// The "background", "foreground" and "font" properties.
// The foreground and font properties of Windows change from
// null to defined values after the Windows are made visible -
// special case them for now.
}
}
}
}
// Bounds
// Use the most concise construct.
if (!locationCorrect && !sizeCorrect) {
}
else if (!locationCorrect) {
}
else if (!sizeCorrect) {
}
}
}
}
// Container
// Ignore the children of a JScrollPane.
// Pending(milne) find a better way to do this.
return;
}
java.awt.Component[] newChildren = (newC == null) ? new java.awt.Component[0] : newC.getComponents();
: null;
: null;
// Pending. Assume all the new children are unaltered.
: (oldLayeredPane != null)
: new Object[] {oldChildren[i]};
}
}
}
// Choice
for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
}
}
}
// Menu
for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
}
}
}
// MenuBar
for (int i = n.getMenuCount(); i < m.getMenuCount(); i++) {
}
}
}
// List
for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
}
}
}
// LayoutManagers
// BorderLayout
};
// Pending, assume any existing elements are OK.
}
}
}
}
// CardLayout
}
}
}
}
}
}
// GridBagLayout
}
}
}
}
return (Hashtable<?,?>) MetaData.getPrivateFieldValue(instance, "java.awt.GridBagLayout.comptable");
}
}
// Swing
// JFrame (If we do this for Window instead of JFrame, the setVisible call
// will be issued before we have added all the children to the JFrame and
// will appear blank).
// false means: don't execute this statement at write time.
out.executeStatements = false;
}
}
}
// Models
// DefaultListModel
static final class javax_swing_DefaultListModel_PersistenceDelegate extends DefaultPersistenceDelegate {
// Note, the "size" property will be set here.
}
}
}
// DefaultComboBoxModel
static final class javax_swing_DefaultComboBoxModel_PersistenceDelegate extends DefaultPersistenceDelegate {
for (int i = 0; i < m.getSize(); i++) {
}
}
}
// DefaultMutableTreeNode
static final class javax_swing_tree_DefaultMutableTreeNode_PersistenceDelegate extends DefaultPersistenceDelegate {
for (int i = n.getChildCount(); i < m.getChildCount(); i++) {
}
}
}
// ToolTipManager
"sharedInstance", new Object[]{});
}
}
// JTabbedPane
for (int i = 0; i < p.getTabCount(); i++) {
new Object[]{
p.getTitleAt(i),
p.getIconAt(i),
p.getComponentAt(i)}, out);
}
}
}
// Box
return super.mutatesTo(oldInstance, newInstance) && getAxis(oldInstance).equals(getAxis(newInstance));
}
return new Expression(oldInstance, oldInstance.getClass(), "new", new Object[] {getAxis(oldInstance)});
}
}
}
// JMenu
// Note that we do not need to state the initialiser for
// JMenuItems since the getComponents() method defined in
// Container will return all of the sub menu items that
// need to be added to the menu item.
// Not so for JMenu apparently.
for (int i = 0; i < c.length; i++) {
}
}
}
/**
* The persistence delegate for {@link MatteBorder}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because this class does not have writable properties.
*
* @author Sergey A. Malenkov
*/
}
};
}
}
/* XXX - doens't seem to work. Debug later.
static final class javax_swing_JMenu_PersistenceDelegate extends DefaultPersistenceDelegate {
protected void initialize(Class<?> type, Object oldInstance, Object newInstance, Encoder out) {
super.initialize(type, oldInstance, newInstance, out);
javax.swing.JMenu m = (javax.swing.JMenu)oldInstance;
javax.swing.JMenu n = (javax.swing.JMenu)newInstance;
for (int i = n.getItemCount(); i < m.getItemCount(); i++) {
invokeStatement(oldInstance, "add", new Object[]{m.getItem(i)}, out);
}
}
}
*/
/**
* The persistence delegate for {@link PrintColorUIResource}.
* It is impossible to use {@link DefaultPersistenceDelegate}
* because this class has special rule for serialization:
* it should be converted to {@link ColorUIResource}.
*
* @see PrintColorUIResource#writeReplace
*
* @author Sergey A. Malenkov
*/
}
}
}
private static final Map<String,Field> fields = Collections.synchronizedMap(new WeakHashMap<String, Field>());
private static PersistenceDelegate primitivePersistenceDelegate = new PrimitivePersistenceDelegate();
static {
new PrimitivePersistenceDelegate());
// it is possible because MatteBorder is assignable from MatteBorderUIResource
// it is possible because FontUIResource is supported by java_awt_Font_PersistenceDelegate
// it is possible because KeyStroke is supported by java_awt_AWTKeyStroke_PersistenceDelegate
internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate());
internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate());
}
return nullPersistenceDelegate;
}
return enumPersistenceDelegate;
}
return primitivePersistenceDelegate;
}
// The persistence delegate for arrays is non-trivial; instantiate it lazily.
if (arrayPersistenceDelegate == null) {
}
return arrayPersistenceDelegate;
}
// Handle proxies lazily for backward compatibility with 1.2.
try {
if (proxyPersistenceDelegate == null) {
}
return proxyPersistenceDelegate;
}
}
catch(Exception e) {}
// else if (type.getDeclaringClass() != null) {
// return new DefaultPersistenceDelegate(new String[]{"this$0"});
// }
return pd;
}
try {
+ "_PersistenceDelegate");
}
catch (ClassNotFoundException e) {
if (properties != null) {
}
}
catch (Exception e) {
}
}
}
int length = 0;
}
}
return names;
}
return (annotation != null)
? annotation.value()
: null;
}
return false;
}
return false;
}
}
return true;
}
try {
} catch (IntrospectionException exception) {
return null;
}
}
try {
field.setAccessible(true);
return field;
}
catch (ClassNotFoundException exception) {
}
catch (NoSuchFieldException exception) {
}
}
});
}
try {
}
catch (IllegalAccessException exception) {
}
}
}