diff --git a/jdk/src/share/classes/java/awt/Component.java b/jdk/src/share/classes/java/awt/Component.java index b48b8c552fda95007167dc9903b2712c0bcea485..6ab84df579dc99ef8794d90c7c919f7d2b16bb5a 100644 --- a/jdk/src/share/classes/java/awt/Component.java +++ b/jdk/src/share/classes/java/awt/Component.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -49,6 +49,7 @@ import java.io.ObjectInputStream; import java.io.IOException; import java.beans.PropertyChangeListener; import java.beans.PropertyChangeSupport; +import java.beans.Transient; import java.awt.event.InputMethodListener; import java.awt.event.InputMethodEvent; import java.awt.im.InputContext; @@ -1100,6 +1101,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #setVisible * @since JDK1.0 */ + @Transient public boolean isVisible() { return isVisible_NoClientCode(); } @@ -1531,6 +1533,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @beaninfo * bound: true */ + @Transient public Color getForeground() { Color foreground = this.foreground; if (foreground != null) { @@ -1585,6 +1588,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #setBackground * @since JDK1.0 */ + @Transient public Color getBackground() { Color background = this.background; if (background != null) { @@ -1644,6 +1648,7 @@ public abstract class Component implements ImageObserver, MenuContainer, * @see #setFont * @since JDK1.0 */ + @Transient public Font getFont() { return getFont_NoClientCode(); } diff --git a/jdk/src/share/classes/java/awt/Dimension.java b/jdk/src/share/classes/java/awt/Dimension.java index b2bad361340967c388f55634d5bbe6f318afffbd..c0e2c75525d48d05a94e3decff42c1efb93a93d9 100644 --- a/jdk/src/share/classes/java/awt/Dimension.java +++ b/jdk/src/share/classes/java/awt/Dimension.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.awt; import java.awt.geom.Dimension2D; +import java.beans.Transient; /** * The Dimension class encapsulates the width and @@ -165,6 +166,7 @@ public class Dimension extends Dimension2D implements java.io.Serializable { * @see java.awt.Component#getSize * @since 1.1 */ + @Transient public Dimension getSize() { return new Dimension(width, height); } diff --git a/jdk/src/share/classes/java/awt/Point.java b/jdk/src/share/classes/java/awt/Point.java index 73c4aa3e79f2e70d4f6ad5827ced788079b33ba7..9bbe03469554dc2ccc52aa7c1c792846980d4bcb 100644 --- a/jdk/src/share/classes/java/awt/Point.java +++ b/jdk/src/share/classes/java/awt/Point.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.awt; import java.awt.geom.Point2D; +import java.beans.Transient; /** * A point representing a location in {@code (x,y)} coordinate space, @@ -119,6 +120,7 @@ public class Point extends Point2D implements java.io.Serializable { * @see java.awt.Point#setLocation(int, int) * @since 1.1 */ + @Transient public Point getLocation() { return new Point(x, y); } diff --git a/jdk/src/share/classes/java/awt/Rectangle.java b/jdk/src/share/classes/java/awt/Rectangle.java index 1457b4d07bc6b80dc1fa7616a16a06f074f0c7ab..bf51092ef1f822a9d759ade67667c4a67a74788b 100644 --- a/jdk/src/share/classes/java/awt/Rectangle.java +++ b/jdk/src/share/classes/java/awt/Rectangle.java @@ -1,5 +1,5 @@ /* - * Copyright 1995-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1995-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -26,6 +26,7 @@ package java.awt; import java.awt.geom.Rectangle2D; +import java.beans.Transient; /** * A Rectangle specifies an area in a coordinate space that is @@ -308,6 +309,7 @@ public class Rectangle extends Rectangle2D * @see #setBounds(int, int, int, int) * @since 1.1 */ + @Transient public Rectangle getBounds() { return new Rectangle(x, y, width, height); } diff --git a/jdk/src/share/classes/java/awt/ScrollPane.java b/jdk/src/share/classes/java/awt/ScrollPane.java index f4303c0aea4bc666e6ea7132055cb4fe420a510f..b34c978474fa814c244119da2949dc4edc5c14cd 100644 --- a/jdk/src/share/classes/java/awt/ScrollPane.java +++ b/jdk/src/share/classes/java/awt/ScrollPane.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,6 +32,7 @@ import sun.awt.ScrollPaneWheelScroller; import sun.awt.SunToolkit; import java.beans.ConstructorProperties; +import java.beans.Transient; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; import java.io.IOException; @@ -390,6 +391,7 @@ public class ScrollPane extends Container implements Accessible { * @throws NullPointerException if the scrollpane does not contain * a child */ + @Transient public Point getScrollPosition() { if (ncomponents <= 0) { throw new NullPointerException("child is null"); diff --git a/jdk/src/share/classes/java/awt/geom/RectangularShape.java b/jdk/src/share/classes/java/awt/geom/RectangularShape.java index 9e733e90c2c30185b103a563816b2b3724800aba..32cbbe678f2793a2010cb59b430a3c6b6ddefb54 100644 --- a/jdk/src/share/classes/java/awt/geom/RectangularShape.java +++ b/jdk/src/share/classes/java/awt/geom/RectangularShape.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ package java.awt.geom; import java.awt.Shape; import java.awt.Rectangle; +import java.beans.Transient; /** * RectangularShape is the base class for a number of @@ -171,6 +172,7 @@ public abstract class RectangularShape implements Shape, Cloneable { * @see #setFrame(Rectangle2D) * @since 1.2 */ + @Transient public Rectangle2D getFrame() { return new Rectangle2D.Double(getX(), getY(), getWidth(), getHeight()); } diff --git a/jdk/src/share/classes/java/awt/im/InputContext.java b/jdk/src/share/classes/java/awt/im/InputContext.java index 9e5d7fa3623161482c04ede885baa3a31acac8ce..0da7fcb42ff2c5f47d4c161985d9f3cd4d46464b 100644 --- a/jdk/src/share/classes/java/awt/im/InputContext.java +++ b/jdk/src/share/classes/java/awt/im/InputContext.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,7 @@ package java.awt.im; import java.awt.Component; import java.util.Locale; import java.awt.AWTEvent; +import java.beans.Transient; import java.lang.Character.Subset; import sun.awt.im.InputMethodContext; @@ -231,6 +232,7 @@ public class InputContext { * @see #setCompositionEnabled * @since 1.3 */ + @Transient public boolean isCompositionEnabled() { // real implementation is in sun.awt.im.InputContext return false; diff --git a/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java b/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java index 9970d53dbba2bf37fa3b8993fd1aa4e0b6a7ff4b..6553a517200cb5df5f82c759508f9b1af8fc32e1 100644 --- a/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java +++ b/jdk/src/share/classes/java/beans/DefaultPersistenceDelegate.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -164,53 +164,19 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { return new Expression(oldInstance, oldInstance.getClass(), "new", constructorArgs); } - private Method findMethod(Class type, String property) throws IntrospectionException { + private Method findMethod(Class type, String property) { if (property == null) { throw new IllegalArgumentException("Property name is null"); } - BeanInfo info = Introspector.getBeanInfo(type); - for (PropertyDescriptor pd : info.getPropertyDescriptors()) { - if (property.equals(pd.getName())) { - Method method = pd.getReadMethod(); - if (method != null) { - return method; - } - throw new IllegalStateException("Could not find getter for the property " + property); - } - } - throw new IllegalStateException("Could not find property by the name " + property); - } - - // This is a workaround for a bug in the introspector. - // PropertyDescriptors are not shared amongst subclasses. - private boolean isTransient(Class type, PropertyDescriptor pd) { - if (type == null) { - return false; + PropertyDescriptor pd = getPropertyDescriptor(type, property); + if (pd == null) { + throw new IllegalStateException("Could not find property by the name " + property); } - // This code was mistakenly deleted - it may be fine and - // is more efficient than the code below. This should - // all disappear anyway when property descriptors are shared - // by the introspector. - /* - Method getter = pd.getReadMethod(); - Class declaringClass = getter.getDeclaringClass(); - if (declaringClass == type) { - return Boolean.TRUE.equals(pd.getValue("transient")); - } - */ - String pName = pd.getName(); - BeanInfo info = MetaData.getBeanInfo(type); - PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors(); - for (int i = 0; i < propertyDescriptors.length; ++i ) { - PropertyDescriptor pd2 = propertyDescriptors[i]; - if (pName.equals(pd2.getName())) { - Object value = pd2.getValue("transient"); - if (value != null) { - return Boolean.TRUE.equals(value); - } - } + Method method = pd.getReadMethod(); + if (method == null) { + throw new IllegalStateException("Could not find getter for the property " + property); } - return isTransient(type.getSuperclass(), pd); + return method; } private static boolean equals(Object o1, Object o2) { @@ -221,7 +187,7 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { Method getter = pd.getReadMethod(); Method setter = pd.getWriteMethod(); - if (getter != null && setter != null && !isTransient(type, pd)) { + if (getter != null && setter != null) { Expression oldGetExp = new Expression(oldInstance, getter.getName(), new Object[]{}); Expression newGetExp = new Expression(newInstance, getter.getName(), new Object[]{}); Object oldValue = oldGetExp.getValue(); @@ -254,14 +220,19 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { // Write out the properties of this instance. private void initBean(Class type, Object oldInstance, Object newInstance, Encoder out) { - // System.out.println("initBean: " + oldInstance); - BeanInfo info = MetaData.getBeanInfo(type); - + BeanInfo info; + try { + info = Introspector.getBeanInfo(type); + } catch (IntrospectionException exception) { + return; + } // Properties - PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors(); - for (int i = 0; i < propertyDescriptors.length; ++i ) { + for (PropertyDescriptor d : info.getPropertyDescriptors()) { + if (d.isTransient()) { + continue; + } try { - doProperty(type, propertyDescriptors[i], oldInstance, newInstance, out); + doProperty(type, d, oldInstance, newInstance, out); } catch (Exception e) { out.getExceptionListener().exceptionThrown(e); @@ -295,9 +266,10 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { if (!java.awt.Component.class.isAssignableFrom(type)) { return; // Just handle the listeners of Components for now. } - EventSetDescriptor[] eventSetDescriptors = info.getEventSetDescriptors(); - for (int e = 0; e < eventSetDescriptors.length; e++) { - EventSetDescriptor d = eventSetDescriptors[e]; + for (EventSetDescriptor d : info.getEventSetDescriptors()) { + if (d.isTransient()) { + continue; + } Class listenerType = d.getListenerType(); @@ -408,4 +380,15 @@ public class DefaultPersistenceDelegate extends PersistenceDelegate { initBean(type, oldInstance, newInstance, out); } } + + private static PropertyDescriptor getPropertyDescriptor(Class type, String property) { + try { + for (PropertyDescriptor pd : Introspector.getBeanInfo(type).getPropertyDescriptors()) { + if (property.equals(pd.getName())) + return pd; + } + } catch (IntrospectionException exception) { + } + return null; + } } diff --git a/jdk/src/share/classes/java/beans/EventSetDescriptor.java b/jdk/src/share/classes/java/beans/EventSetDescriptor.java index 8c30657e0c3d2e9aec82e37ba3cb34fef6d56351..05b62d8caf19f19ad89e54f34c791350df8942ea 100644 --- a/jdk/src/share/classes/java/beans/EventSetDescriptor.java +++ b/jdk/src/share/classes/java/beans/EventSetDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2005 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -369,6 +369,7 @@ public class EventSetDescriptor extends FeatureDescriptor { setClass0(method.getDeclaringClass()); } addMethodDescriptor = new MethodDescriptor(method); + setTransient(method.getAnnotation(Transient.class)); } /** @@ -389,6 +390,7 @@ public class EventSetDescriptor extends FeatureDescriptor { setClass0(method.getDeclaringClass()); } removeMethodDescriptor = new MethodDescriptor(method); + setTransient(method.getAnnotation(Transient.class)); } /** @@ -411,6 +413,7 @@ public class EventSetDescriptor extends FeatureDescriptor { setClass0(method.getDeclaringClass()); } getMethodDescriptor = new MethodDescriptor(method); + setTransient(method.getAnnotation(Transient.class)); } /** diff --git a/jdk/src/share/classes/java/beans/FeatureDescriptor.java b/jdk/src/share/classes/java/beans/FeatureDescriptor.java index eea5a29d81c13ca61b82f08499d9755905e82caf..36adbc044d6f7c352155f2de5e94cd36acf7ae3d 100644 --- a/jdk/src/share/classes/java/beans/FeatureDescriptor.java +++ b/jdk/src/share/classes/java/beans/FeatureDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,7 +32,9 @@ import java.lang.ref.WeakReference; import java.lang.ref.SoftReference; import java.lang.reflect.Method; -import java.lang.reflect.Type; + +import java.util.Enumeration; +import java.util.Hashtable; /** * The FeatureDescriptor class is the common baseclass for PropertyDescriptor, @@ -46,6 +48,7 @@ import java.lang.reflect.Type; */ public class FeatureDescriptor { + private static final String TRANSIENT = "transient"; private Reference classRef; @@ -187,10 +190,7 @@ public class FeatureDescriptor { * @param value The value. */ public void setValue(String attributeName, Object value) { - if (table == null) { - table = new java.util.Hashtable(); - } - table.put(attributeName, value); + getTable().put(attributeName, value); } /** @@ -201,10 +201,9 @@ public class FeatureDescriptor { * the attribute is unknown. */ public Object getValue(String attributeName) { - if (table == null) { - return null; - } - return table.get(attributeName); + return (this.table != null) + ? this.table.get(attributeName) + : null; } /** @@ -214,11 +213,8 @@ public class FeatureDescriptor { * @return An enumeration of the locale-independent names of any * attributes that have been registered with setValue. */ - public java.util.Enumeration attributeNames() { - if (table == null) { - table = new java.util.Hashtable(); - } - return table.keys(); + public Enumeration attributeNames() { + return getTable().keys(); } /** @@ -268,61 +264,66 @@ public class FeatureDescriptor { addTable(old.table); } - private void addTable(java.util.Hashtable t) { - if (t == null) { - return; - } - java.util.Enumeration keys = t.keys(); - while (keys.hasMoreElements()) { - String key = (String)keys.nextElement(); - Object value = t.get(key); - setValue(key, value); + /** + * Copies all values from the specified attribute table. + * If some attribute is exist its value should be overridden. + * + * @param table the attribute table with new values + */ + private void addTable(Hashtable table) { + if ((table != null) && !table.isEmpty()) { + getTable().putAll(table); } } - // Package private methods for recreating the weak/soft referent - - void setClass0(Class cls) { - this.classRef = getWeakReference(cls); - } - - Class getClass0() { - return (this.classRef != null) - ? this.classRef.get() - : null; - } - /** - * Create a Reference wrapper for the object. + * Returns the initialized attribute table. * - * @param obj object that will be wrapped - * @param soft true if a SoftReference should be created; otherwise Soft - * @return a Reference or null if obj is null. + * @return the initialized attribute table */ - static Reference createReference(Object obj, boolean soft) { - Reference ref = null; - if (obj != null) { - if (soft) { - ref = new SoftReference(obj); - } else { - ref = new WeakReference(obj); - } + private Hashtable getTable() { + if (this.table == null) { + this.table = new Hashtable(); } - return ref; + return this.table; } - // Convenience method which creates a WeakReference. - static Reference createReference(Object obj) { - return createReference(obj, false); + /** + * Sets the "transient" attribute according to the annotation. + * If the "transient" attribute is already set + * it should not be changed. + * + * @param annotation the annotation of the element of the feature + */ + void setTransient(Transient annotation) { + if ((annotation != null) && (null == getValue(TRANSIENT))) { + setValue(TRANSIENT, annotation.value()); + } } /** - * Returns an object from a Reference wrapper. + * Indicates whether the feature is transient. * - * @return the Object in a wrapper or null. + * @return {@code true} if the feature is transient, + * {@code false} otherwise */ - static Object getObject(Reference ref) { - return (ref == null) ? null : (Object)ref.get(); + boolean isTransient() { + Object value = getValue(TRANSIENT); + return (value instanceof Boolean) + ? (Boolean) value + : false; + } + + // Package private methods for recreating the weak/soft referent + + void setClass0(Class cls) { + this.classRef = getWeakReference(cls); + } + + Class getClass0() { + return (this.classRef != null) + ? this.classRef.get() + : null; } /** @@ -391,5 +392,5 @@ public class FeatureDescriptor { private String shortDescription; private String name; private String displayName; - private java.util.Hashtable table; + private Hashtable table; } diff --git a/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java b/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java index 3b1a39e38a4a2ec098b9df52fcab81ca3705f10a..fa5b404c239c6cffe0a3e6887bfdd171eaa7c77c 100644 --- a/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java +++ b/jdk/src/share/classes/java/beans/IndexedPropertyDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -231,6 +231,7 @@ perty. indexedReadMethodName = readMethod.getName(); this.indexedReadMethodRef = getSoftReference(readMethod); + setTransient(readMethod.getAnnotation(Transient.class)); } @@ -303,6 +304,7 @@ perty. indexedWriteMethodName = writeMethod.getName(); this.indexedWriteMethodRef = getSoftReference(writeMethod); + setTransient(writeMethod.getAnnotation(Transient.class)); } /** diff --git a/jdk/src/share/classes/java/beans/MetaData.java b/jdk/src/share/classes/java/beans/MetaData.java index 7b9f6ced377be2fc97df923bdcab31aad6c0dfc2..9bcd505c215773b0f6589eb2b300055d6f522a7d 100644 --- a/jdk/src/share/classes/java/beans/MetaData.java +++ b/jdk/src/share/classes/java/beans/MetaData.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2000-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -1352,7 +1352,6 @@ final class sun_swing_PrintColorUIResource_PersistenceDelegate extends Persisten class MetaData { private static Hashtable internalPersistenceDelegates = new Hashtable(); - private static Hashtable transientProperties = new Hashtable(); private static PersistenceDelegate nullPersistenceDelegate = new NullPersistenceDelegate(); private static PersistenceDelegate enumPersistenceDelegate = new EnumPersistenceDelegate(); @@ -1383,94 +1382,6 @@ class MetaData { internalPersistenceDelegates.put("java.util.JumboEnumSet", new java_util_EnumSet_PersistenceDelegate()); internalPersistenceDelegates.put("java.util.RegularEnumSet", new java_util_EnumSet_PersistenceDelegate()); - -// Transient properties - - // awt - - // Infinite graphs. - removeProperty("java.awt.geom.RectangularShape", "frame"); - // removeProperty("java.awt.Rectangle2D", "frame"); - // removeProperty("java.awt.Rectangle", "frame"); - - removeProperty("java.awt.Rectangle", "bounds"); - removeProperty("java.awt.Dimension", "size"); - removeProperty("java.awt.Point", "location"); - - // The color and font properties in Component need special treatment, see above. - removeProperty("java.awt.Component", "foreground"); - removeProperty("java.awt.Component", "background"); - removeProperty("java.awt.Component", "font"); - - // The visible property of Component needs special treatment because of Windows. - removeProperty("java.awt.Component", "visible"); - - // This property throws an exception if accessed when there is no child. - removeProperty("java.awt.ScrollPane", "scrollPosition"); - - // 4917458 this should be removed for XAWT since it may throw - // an unsupported exception if there isn't any input methods. - // This shouldn't be a problem since these are added behind - // the scenes automatically. - removeProperty("java.awt.im.InputContext", "compositionEnabled"); - - // swing - - // The size properties in JComponent need special treatment, see above. - removeProperty("javax.swing.JComponent", "minimumSize"); - removeProperty("javax.swing.JComponent", "preferredSize"); - removeProperty("javax.swing.JComponent", "maximumSize"); - - // These properties have platform specific implementations - // and should not appear in archives. - removeProperty("javax.swing.ImageIcon", "image"); - removeProperty("javax.swing.ImageIcon", "imageObserver"); - - // This property unconditionally throws a "not implemented" exception. - removeProperty("javax.swing.JMenuBar", "helpMenu"); - - // The scrollBars in a JScrollPane are dynamic and should not - // be archived. The row and columns headers are changed by - // components like JTable on "addNotify". - removeProperty("javax.swing.JScrollPane", "verticalScrollBar"); - removeProperty("javax.swing.JScrollPane", "horizontalScrollBar"); - removeProperty("javax.swing.JScrollPane", "rowHeader"); - removeProperty("javax.swing.JScrollPane", "columnHeader"); - - removeProperty("javax.swing.JViewport", "extentSize"); - - // Renderers need special treatment, since their properties - // change during rendering. - removeProperty("javax.swing.table.JTableHeader", "defaultRenderer"); - removeProperty("javax.swing.JList", "cellRenderer"); - - removeProperty("javax.swing.JList", "selectedIndices"); - - // The lead and anchor selection indexes are best ignored. - // Selection is rarely something that should persist from - // development to deployment. - removeProperty("javax.swing.DefaultListSelectionModel", "leadSelectionIndex"); - removeProperty("javax.swing.DefaultListSelectionModel", "anchorSelectionIndex"); - - // The selection must come after the text itself. - removeProperty("javax.swing.JComboBox", "selectedIndex"); - - // All selection information should come after the JTabbedPane is built - removeProperty("javax.swing.JTabbedPane", "selectedIndex"); - removeProperty("javax.swing.JTabbedPane", "selectedComponent"); - - // PENDING: The "disabledIcon" property is often computed from the icon property. - removeProperty("javax.swing.AbstractButton", "disabledIcon"); - removeProperty("javax.swing.JLabel", "disabledIcon"); - - // The caret property throws errors when it it set beyond - // the extent of the text. We could just set it after the - // text, but this is probably not something we want to archive anyway. - removeProperty("javax.swing.text.JTextComponent", "caret"); - removeProperty("javax.swing.text.JTextComponent", "caretPosition"); - // The selectionStart must come after the text itself. - removeProperty("javax.swing.text.JTextComponent", "selectionStart"); - removeProperty("javax.swing.text.JTextComponent", "selectionEnd"); } /*pp*/ static boolean equals(Object o1, Object o2) { @@ -1509,18 +1420,6 @@ class MetaData { // } String typeName = type.getName(); - - // Check to see if there are properties that have been lazily registered for removal. - if (getBeanAttribute(type, "transient_init") == null) { - Vector tp = (Vector)transientProperties.get(typeName); - if (tp != null) { - for(int i = 0; i < tp.size(); i++) { - setPropertyAttribute(type, (String)tp.get(i), "transient", Boolean.TRUE); - } - } - setBeanAttribute(type, "transient_init", Boolean.TRUE); - } - PersistenceDelegate pd = (PersistenceDelegate)getBeanAttribute(type, "persistenceDelegate"); if (pd == null) { pd = (PersistenceDelegate)internalPersistenceDelegates.get(typeName); @@ -1583,55 +1482,11 @@ class MetaData { return true; } - // Wrapper for Introspector.getBeanInfo to handle exception handling. - // Note: this relys on new 1.4 Introspector semantics which cache the BeanInfos - public static BeanInfo getBeanInfo(Class type) { - BeanInfo info = null; - try { - info = Introspector.getBeanInfo(type); - } catch (Throwable e) { - e.printStackTrace(); - } - - return info; - } - - private static PropertyDescriptor getPropertyDescriptor(Class type, String propertyName) { - BeanInfo info = getBeanInfo(type); - PropertyDescriptor[] propertyDescriptors = info.getPropertyDescriptors(); - // System.out.println("Searching for: " + propertyName + " in " + type); - for(int i = 0; i < propertyDescriptors.length; i++) { - PropertyDescriptor pd = propertyDescriptors[i]; - if (propertyName.equals(pd.getName())) { - return pd; - } - } - return null; - } - - private static void setPropertyAttribute(Class type, String property, String attribute, Object value) { - PropertyDescriptor pd = getPropertyDescriptor(type, property); - if (pd == null) { - System.err.println("Warning: property " + property + " is not defined on " + type); - return; - } - pd.setValue(attribute, value); - } - - private static void setBeanAttribute(Class type, String attribute, Object value) { - getBeanInfo(type).getBeanDescriptor().setValue(attribute, value); - } - private static Object getBeanAttribute(Class type, String attribute) { - return getBeanInfo(type).getBeanDescriptor().getValue(attribute); - } - - private static void removeProperty(String typeName, String property) { - Vector tp = (Vector)transientProperties.get(typeName); - if (tp == null) { - tp = new Vector(); - transientProperties.put(typeName, tp); + try { + return Introspector.getBeanInfo(type).getBeanDescriptor().getValue(attribute); + } catch (IntrospectionException exception) { + return null; } - tp.add(property); } } diff --git a/jdk/src/share/classes/java/beans/PropertyDescriptor.java b/jdk/src/share/classes/java/beans/PropertyDescriptor.java index 775b213c31d5afc99323c1a80ab66569c5fdb920..08ae9a45f4242d696d8f030271aca6507b784bd1 100644 --- a/jdk/src/share/classes/java/beans/PropertyDescriptor.java +++ b/jdk/src/share/classes/java/beans/PropertyDescriptor.java @@ -1,5 +1,5 @@ /* - * Copyright 1996-2004 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1996-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -256,6 +256,7 @@ public class PropertyDescriptor extends FeatureDescriptor { readMethodName = readMethod.getName(); this.readMethodRef = getSoftReference(readMethod); + setTransient(readMethod.getAnnotation(Transient.class)); } /** @@ -320,7 +321,7 @@ public class PropertyDescriptor extends FeatureDescriptor { writeMethodName = writeMethod.getName(); this.writeMethodRef = getSoftReference(writeMethod); - + setTransient(writeMethod.getAnnotation(Transient.class)); } private Method getReadMethod0() { diff --git a/jdk/src/share/classes/java/beans/Transient.java b/jdk/src/share/classes/java/beans/Transient.java new file mode 100644 index 0000000000000000000000000000000000000000..302152e7cb97ca4cb29a06ecf5a80c252983f8a9 --- /dev/null +++ b/jdk/src/share/classes/java/beans/Transient.java @@ -0,0 +1,68 @@ +/* + * Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. Sun designates this + * particular file as subject to the "Classpath" exception as provided + * by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +package java.beans; + +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +import static java.lang.annotation.ElementType.METHOD; +import static java.lang.annotation.RetentionPolicy.RUNTIME; + +/** + * Indicates that an attribute called "transient" + * should be declared with the given {@code value} + * when the {@link Introspector} constructs + * a {@link PropertyDescriptor} or {@link EventSetDescriptor} + * classes associated with the annotated code element. + * A {@code true} value for the "transient" attribute + * indicates to encoders derived from {@link Encoder} + * that this feature should be ignored. + *

+ * The {@code Transient} annotation may be be used + * in any of the methods that are involved + * in a {@link FeatureDescriptor} subclass + * to identify the transient feature in the annotated class and its subclasses. + * Normally, the method that starts with "get" is the best place + * to put the annotation and it is this declaration + * that takes precedence in the case of multiple annotations + * being defined for the same feature. + *

+ * To declare a feature non-transient in a class + * whose superclass declares it transient, + * use {@code @Transient(false)}. + * In all cases, the {@link Introspector} decides + * if a feature is transient by referring to the annotation + * on the most specific superclass. + * If no {@code Transient} annotation is present + * in any superclass the feature is not transient. + * + * @since 1.7 + */ +@Target({METHOD}) +@Retention(RUNTIME) +public @interface Transient { + boolean value() default true; +} diff --git a/jdk/src/share/classes/javax/swing/AbstractButton.java b/jdk/src/share/classes/javax/swing/AbstractButton.java index b4d4ae1e29a87ed344286c7489299bd29cca6eba..53cb6139c998ebe665f9ac292ea08bf18ab9edb2 100644 --- a/jdk/src/share/classes/javax/swing/AbstractButton.java +++ b/jdk/src/share/classes/javax/swing/AbstractButton.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,7 +29,9 @@ import java.awt.event.*; import java.awt.image.*; import java.text.*; import java.awt.geom.*; -import java.beans.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.Transient; import java.util.Enumeration; import java.util.Vector; import java.io.Serializable; @@ -645,6 +647,7 @@ public abstract class AbstractButton extends JComponent implements ItemSelectabl * @see #setDisabledIcon * @see javax.swing.LookAndFeel#getDisabledIcon */ + @Transient public Icon getDisabledIcon() { if (disabledIcon == null) { disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, getIcon()); diff --git a/jdk/src/share/classes/javax/swing/DefaultListSelectionModel.java b/jdk/src/share/classes/javax/swing/DefaultListSelectionModel.java index 78caa194139ea45f272a5efdc35028c0c4f09939..329fa38b44aea52278ef7f43f0eece42bed4fdec 100644 --- a/jdk/src/share/classes/javax/swing/DefaultListSelectionModel.java +++ b/jdk/src/share/classes/javax/swing/DefaultListSelectionModel.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -28,6 +28,7 @@ package javax.swing; import java.util.EventListener; import java.util.BitSet; import java.io.Serializable; +import java.beans.Transient; import javax.swing.event.*; @@ -714,11 +715,13 @@ public class DefaultListSelectionModel implements ListSelectionModel, Cloneable, } /** {@inheritDoc} */ + @Transient public int getAnchorSelectionIndex() { return anchorIndex; } /** {@inheritDoc} */ + @Transient public int getLeadSelectionIndex() { return leadIndex; } diff --git a/jdk/src/share/classes/javax/swing/ImageIcon.java b/jdk/src/share/classes/javax/swing/ImageIcon.java index 38a9f22f224bcd8a2e50bcf4541a13b7fda33185..74788f1a8039575092a3a877e867dfb402c9b499 100644 --- a/jdk/src/share/classes/javax/swing/ImageIcon.java +++ b/jdk/src/share/classes/javax/swing/ImageIcon.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,6 +27,7 @@ package javax.swing; import java.awt.*; import java.awt.image.*; import java.beans.ConstructorProperties; +import java.beans.Transient; import java.net.URL; import java.io.Serializable; @@ -336,6 +337,7 @@ public class ImageIcon implements Icon, Serializable, Accessible { * Returns this icon's Image. * @return the Image object for this ImageIcon */ + @Transient public Image getImage() { return image; } @@ -436,6 +438,7 @@ public class ImageIcon implements Icon, Serializable, Accessible { * * @return the image observer, which may be null */ + @Transient public ImageObserver getImageObserver() { return imageObserver; } diff --git a/jdk/src/share/classes/javax/swing/JComboBox.java b/jdk/src/share/classes/javax/swing/JComboBox.java index a4d92427eea720a07597a0babcd0763dc8acbbaa..2230147f4a97c1b111eaa0d58499fa760f082929 100644 --- a/jdk/src/share/classes/javax/swing/JComboBox.java +++ b/jdk/src/share/classes/javax/swing/JComboBox.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -24,7 +24,9 @@ */ package javax.swing; -import java.beans.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.Transient; import java.util.*; import java.awt.*; @@ -636,6 +638,7 @@ implements ItemSelectable,ListDataListener,ActionListener, Accessible { * or -1 if no item is selected or if * the currently selected item is not in the list */ + @Transient public int getSelectedIndex() { Object sObject = dataModel.getSelectedItem(); int i,c; diff --git a/jdk/src/share/classes/javax/swing/JComponent.java b/jdk/src/share/classes/javax/swing/JComponent.java index d26ec12ebd6ff648141cb8d3134d9b6a2b93f74b..7d3881a1c0589a19178a546db765c49c6bcb5da9 100644 --- a/jdk/src/share/classes/javax/swing/JComponent.java +++ b/jdk/src/share/classes/javax/swing/JComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,7 +43,10 @@ import java.awt.Graphics2D; import java.awt.peer.LightweightPeer; import java.awt.dnd.DropTarget; import java.awt.font.FontRenderContext; -import java.beans.*; +import java.beans.PropertyChangeListener; +import java.beans.VetoableChangeListener; +import java.beans.VetoableChangeSupport; +import java.beans.Transient; import java.applet.Applet; @@ -1634,6 +1637,7 @@ public abstract class JComponent extends Container implements Serializable, * @see #setPreferredSize * @see ComponentUI */ + @Transient public Dimension getPreferredSize() { if (isPreferredSizeSet()) { return super.getPreferredSize(); @@ -1675,6 +1679,7 @@ public abstract class JComponent extends Container implements Serializable, * @see #setMaximumSize * @see ComponentUI */ + @Transient public Dimension getMaximumSize() { if (isMaximumSizeSet()) { return super.getMaximumSize(); @@ -1714,6 +1719,7 @@ public abstract class JComponent extends Container implements Serializable, * @see #setMinimumSize * @see ComponentUI */ + @Transient public Dimension getMinimumSize() { if (isMinimumSizeSet()) { return super.getMinimumSize(); diff --git a/jdk/src/share/classes/javax/swing/JLabel.java b/jdk/src/share/classes/javax/swing/JLabel.java index 1d51add5cac83047d620d8d67669e5b753980417..417892a83234ead1e849da8512333fe9f1e50436 100644 --- a/jdk/src/share/classes/javax/swing/JLabel.java +++ b/jdk/src/share/classes/javax/swing/JLabel.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,6 +31,7 @@ import java.awt.Image; import java.awt.*; import java.text.*; import java.awt.geom.*; +import java.beans.Transient; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; @@ -422,6 +423,7 @@ public class JLabel extends JComponent implements SwingConstants, Accessible * @see javax.swing.LookAndFeel#getDisabledIcon * @see ImageIcon */ + @Transient public Icon getDisabledIcon() { if (!disabledIconSet && disabledIcon == null && defaultIcon != null) { disabledIcon = UIManager.getLookAndFeel().getDisabledIcon(this, defaultIcon); diff --git a/jdk/src/share/classes/javax/swing/JList.java b/jdk/src/share/classes/javax/swing/JList.java index 8446d05a88b0e2651c98a21c04f139d4af4b001a..a83a4c94e4c560cef9b819d4d79a3d5858cdba35 100644 --- a/jdk/src/share/classes/javax/swing/JList.java +++ b/jdk/src/share/classes/javax/swing/JList.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -31,7 +31,9 @@ import java.awt.*; import java.util.Vector; import java.util.Locale; -import java.beans.*; +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.Transient; import javax.swing.event.*; import javax.accessibility.*; @@ -724,6 +726,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @return the value of the {@code cellRenderer} property * @see #setCellRenderer */ + @Transient public ListCellRenderer getCellRenderer() { return cellRenderer; } @@ -2153,6 +2156,7 @@ public class JList extends JComponent implements Scrollable, Accessible * @see #removeSelectionInterval * @see #addListSelectionListener */ + @Transient public int[] getSelectedIndices() { ListSelectionModel sm = getSelectionModel(); int iMin = sm.getMinSelectionIndex(); diff --git a/jdk/src/share/classes/javax/swing/JMenuBar.java b/jdk/src/share/classes/javax/swing/JMenuBar.java index f10a84bf34d1f0f4a3bfd7c8417fef332d01ec5a..d6f04fbb42755dee5eb5331c2085219ea4ff40c6 100644 --- a/jdk/src/share/classes/javax/swing/JMenuBar.java +++ b/jdk/src/share/classes/javax/swing/JMenuBar.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -32,6 +32,7 @@ import java.awt.Insets; import java.awt.Point; import java.awt.Rectangle; import java.awt.event.*; +import java.beans.Transient; import java.util.Vector; import java.util.Enumeration; @@ -236,6 +237,7 @@ public class JMenuBar extends JComponent implements Accessible,MenuElement * * @return the JMenu that delivers help to the user */ + @Transient public JMenu getHelpMenu() { throw new Error("getHelpMenu() not yet implemented."); } diff --git a/jdk/src/share/classes/javax/swing/JScrollPane.java b/jdk/src/share/classes/javax/swing/JScrollPane.java index 1db9e459f0ce73c2c686c7049bbe584e9bc8df88..13c1365c025e7f485823adbe943f4dc4f84f4d39 100644 --- a/jdk/src/share/classes/javax/swing/JScrollPane.java +++ b/jdk/src/share/classes/javax/swing/JScrollPane.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -43,8 +43,9 @@ import java.io.ObjectOutputStream; import java.io.ObjectInputStream; import java.io.IOException; -import java.beans.*; - +import java.beans.PropertyChangeEvent; +import java.beans.PropertyChangeListener; +import java.beans.Transient; /** * Provides a scrollable view of a lightweight component. @@ -822,6 +823,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the horizontalScrollBar property * @see #setHorizontalScrollBar */ + @Transient public JScrollBar getHorizontalScrollBar() { return horizontalScrollBar; } @@ -880,6 +882,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the verticalScrollBar property * @see #setVerticalScrollBar */ + @Transient public JScrollBar getVerticalScrollBar() { return verticalScrollBar; } @@ -1012,6 +1015,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the rowHeader property * @see #setRowHeader */ + @Transient public JViewport getRowHeader() { return rowHeader; } @@ -1081,6 +1085,7 @@ public class JScrollPane extends JComponent implements ScrollPaneConstants, Acce * @return the columnHeader property * @see #setColumnHeader */ + @Transient public JViewport getColumnHeader() { return columnHeader; } diff --git a/jdk/src/share/classes/javax/swing/JTabbedPane.java b/jdk/src/share/classes/javax/swing/JTabbedPane.java index defffc711a4f58dd5695ebeb86415af89591d1f6..706fc3732db2d5cbad662a1a555ef21dca2966b0 100644 --- a/jdk/src/share/classes/javax/swing/JTabbedPane.java +++ b/jdk/src/share/classes/javax/swing/JTabbedPane.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -27,7 +27,7 @@ package javax.swing; import java.awt.*; import java.awt.event.*; -import java.beans.*; +import java.beans.Transient; import java.util.*; import javax.swing.event.*; import javax.swing.plaf.*; @@ -563,6 +563,7 @@ public class JTabbedPane extends JComponent * @return the index of the selected tab * @see #setSelectedIndex */ + @Transient public int getSelectedIndex() { return model.getSelectedIndex(); } @@ -648,6 +649,7 @@ public class JTabbedPane extends JComponent * @return the component corresponding to the selected tab * @see #setSelectedComponent */ + @Transient public Component getSelectedComponent() { int index = getSelectedIndex(); if (index == -1) { diff --git a/jdk/src/share/classes/javax/swing/JViewport.java b/jdk/src/share/classes/javax/swing/JViewport.java index 1825c79017e238714aa01086e3911c24339b0161..f5a16bbd2c6c0022343c8c884344934f94a44707 100644 --- a/jdk/src/share/classes/javax/swing/JViewport.java +++ b/jdk/src/share/classes/javax/swing/JViewport.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -30,6 +30,7 @@ import java.awt.event.*; import java.awt.image.VolatileImage; import java.awt.peer.ComponentPeer; import java.applet.Applet; +import java.beans.Transient; import javax.swing.plaf.ViewportUI; import javax.swing.event.*; @@ -1257,6 +1258,7 @@ public class JViewport extends JComponent implements Accessible * * @return a Dimension object giving the size of the view */ + @Transient public Dimension getExtentSize() { return getSize(); } diff --git a/jdk/src/share/classes/javax/swing/table/JTableHeader.java b/jdk/src/share/classes/javax/swing/table/JTableHeader.java index fb99e058d784cff59fb6116c2ccbc36a5021ebc9..78099608949fb7418e47d5a7a8e09661e78eb072 100644 --- a/jdk/src/share/classes/javax/swing/table/JTableHeader.java +++ b/jdk/src/share/classes/javax/swing/table/JTableHeader.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -37,6 +37,7 @@ import javax.swing.plaf.*; import javax.accessibility.*; import java.beans.PropertyChangeListener; +import java.beans.Transient; import java.io.ObjectOutputStream; import java.io.ObjectInputStream; @@ -325,6 +326,7 @@ public class JTableHeader extends JComponent implements TableColumnModelListener * @return the default renderer * @since 1.3 */ + @Transient public TableCellRenderer getDefaultRenderer() { return defaultRenderer; } diff --git a/jdk/src/share/classes/javax/swing/text/JTextComponent.java b/jdk/src/share/classes/javax/swing/text/JTextComponent.java index d340f281eff99c85cf8bad972507753c6de45812..e4531003597f043b4958e7e4780a0a8ce8b3ae56 100644 --- a/jdk/src/share/classes/javax/swing/text/JTextComponent.java +++ b/jdk/src/share/classes/javax/swing/text/JTextComponent.java @@ -1,5 +1,5 @@ /* - * Copyright 1997-2006 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 1997-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -29,6 +29,7 @@ import java.lang.reflect.Method; import java.security.AccessController; import java.security.PrivilegedAction; +import java.beans.Transient; import java.util.Collections; import java.util.HashMap; import java.util.Hashtable; @@ -571,6 +572,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @return the caret */ + @Transient public Caret getCaret() { return caret; } @@ -1672,6 +1674,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * @return the position of the text insertion caret for the * text component >= 0 */ + @Transient public int getCaretPosition() { return caret.getDot(); } @@ -1797,6 +1800,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @return the start position >= 0 */ + @Transient public int getSelectionStart() { int start = Math.min(caret.getDot(), caret.getMark()); return start; @@ -1829,6 +1833,7 @@ public abstract class JTextComponent extends JComponent implements Scrollable, A * * @return the end position >= 0 */ + @Transient public int getSelectionEnd() { int end = Math.max(caret.getDot(), caret.getMark()); return end; diff --git a/jdk/test/java/beans/Introspector/BeanUtils.java b/jdk/test/java/beans/Introspector/BeanUtils.java index 4b1e76335412ac906b522b7fcb741690048d2dd1..63c58195218e3bf8773c7e4ea3961e2386ed71e2 100644 --- a/jdk/test/java/beans/Introspector/BeanUtils.java +++ b/jdk/test/java/beans/Introspector/BeanUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2003-2007 Sun Microsystems, Inc. All Rights Reserved. + * Copyright 2003-2008 Sun Microsystems, Inc. All Rights Reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -21,6 +21,7 @@ * have any questions. */ +import java.beans.BeanDescriptor; import java.beans.EventSetDescriptor; import java.beans.IndexedPropertyDescriptor; import java.beans.IntrospectionException; @@ -38,6 +39,20 @@ public final class BeanUtils { private BeanUtils() { } + /** + * Returns a bean descriptor for specified class. + * + * @param type the class to introspect + * @return a bean descriptor + */ + public static BeanDescriptor getBeanDescriptor(Class type) { + try { + return Introspector.getBeanInfo(type).getBeanDescriptor(); + } catch (IntrospectionException exception) { + throw new Error("unexpected exception", exception); + } + } + /** * Returns an array of property descriptors for specified class. * @@ -45,7 +60,6 @@ public final class BeanUtils { * @return an array of property descriptors */ public static PropertyDescriptor[] getPropertyDescriptors(Class type) { - System.out.println(type); try { return Introspector.getBeanInfo(type).getPropertyDescriptors(); } catch (IntrospectionException exception) { @@ -53,6 +67,38 @@ public final class BeanUtils { } } + /** + * Returns an array of event set descriptors for specified class. + * + * @param type the class to introspect + * @return an array of event set descriptors + */ + public static EventSetDescriptor[] getEventSetDescriptors(Class type) { + try { + return Introspector.getBeanInfo(type).getEventSetDescriptors(); + } catch (IntrospectionException exception) { + throw new Error("unexpected exception", exception); + } + } + + /** + * Finds an event set descriptor for the class + * that matches the event set name. + * + * @param type the class to introspect + * @param name the name of the event set to search + * @return the {@code EventSetDescriptor} or {@code null} + */ + public static EventSetDescriptor findEventSetDescriptor(Class type, String name) { + EventSetDescriptor[] esds = getEventSetDescriptors(type); + for (EventSetDescriptor esd : esds) { + if (esd.getName().equals(name)) { + return esd; + } + } + return null; + } + /** * Finds a property descriptor for the class * that matches the property name. @@ -71,6 +117,22 @@ public final class BeanUtils { return null; } + /** + * Returns a event set descriptor for the class + * that matches the property name. + * + * @param type the class to introspect + * @param name the name of the event set to search + * @return the {@code EventSetDescriptor} + */ + public static EventSetDescriptor getEventSetDescriptor(Class type, String name) { + EventSetDescriptor esd = findEventSetDescriptor(type, name); + if (esd != null) { + return esd; + } + throw new Error("could not find event set '" + name + "' in " + type); + } + /** * Returns a property descriptor for the class * that matches the property name. diff --git a/jdk/test/java/beans/Introspector/Test4896879.java b/jdk/test/java/beans/Introspector/Test4896879.java index 8ccab4d54d4adf318e14eef1e8ed59ddb16bac73..2423841c79890385c47f377e7ca748f5131bf34d 100644 --- a/jdk/test/java/beans/Introspector/Test4896879.java +++ b/jdk/test/java/beans/Introspector/Test4896879.java @@ -28,22 +28,16 @@ * @author Mark Davidson */ -import java.beans.BeanInfo; -import java.beans.EventSetDescriptor; -import java.beans.IntrospectionException; -import java.beans.Introspector; import java.util.EventListener; public class Test4896879 { - public static void main(String[] args) throws IntrospectionException { + public static void main(String[] args) { test(A.class); test(B.class); } - private static void test(Class type) throws IntrospectionException { - BeanInfo info = Introspector.getBeanInfo(type); - EventSetDescriptor[] descriptors = info.getEventSetDescriptors(); - if (descriptors.length != 0) { + private static void test(Class type) { + if (BeanUtils.getEventSetDescriptors(type).length != 0) { throw new Error("Should not have any EventSetDescriptors"); } } diff --git a/jdk/test/java/beans/Introspector/Test4935607.java b/jdk/test/java/beans/Introspector/Test4935607.java new file mode 100644 index 0000000000000000000000000000000000000000..7ce48c9b6c89a8b470b231e7012d8c95ff89b11f --- /dev/null +++ b/jdk/test/java/beans/Introspector/Test4935607.java @@ -0,0 +1,404 @@ +/* + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test %I% %G% + * @bug 4935607 + * @summary Tests transient properties + * @author Sergey Malenkov + */ + +import java.awt.Component; +import java.awt.Dimension; +import java.awt.Point; +import java.awt.Rectangle; +import java.awt.ScrollPane; +import java.awt.geom.RectangularShape; +import java.awt.im.InputContext; + +import java.beans.FeatureDescriptor; +import java.beans.Transient; + +import java.util.EventListener; + +import javax.swing.AbstractButton; +import javax.swing.DefaultListSelectionModel; +import javax.swing.ImageIcon; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JList; +import javax.swing.JMenuBar; +import javax.swing.JScrollPane; +import javax.swing.JTabbedPane; +import javax.swing.JViewport; +import javax.swing.table.JTableHeader; +import javax.swing.text.JTextComponent; + +public class Test4935607 { + public static void main(String[] args) { + // test all possible cases + test(Null.class); + test(True.class); + test(False.class); + test(NullNull.class); + test(TrueNull.class); + test(FalseNull.class); + test(NullTrue.class); + test(TrueTrue.class); + test(FalseTrue.class); + test(NullFalse.class); + test(TrueFalse.class); + test(FalseFalse.class); + // test transient properties in AWT + test(RectangularShape.class, "frame"); // NON-NLS: getFrame() + test(Rectangle.class, "bounds"); // NON-NLS: getBounds() + test(Dimension.class, "size"); // NON-NLS: getSize() + test(Point.class, "location"); // NON-NLS: getLocation() + test(Component.class, "foreground"); // NON-NLS: getForeground() + test(Component.class, "background"); // NON-NLS: getBackground() + test(Component.class, "font"); // NON-NLS: getFont() + test(Component.class, "visible"); // NON-NLS: getVisible() + test(ScrollPane.class, "scrollPosition"); // NON-NLS: getScrollPosition() + test(InputContext.class, "compositionEnabled"); // NON-NLS: getCompositionEnabled() + // test transient properties in Swing + test(JComponent.class, "minimumSize"); // NON-NLS: getMinimumSize() + test(JComponent.class, "preferredSize"); // NON-NLS: getPreferredSize() + test(JComponent.class, "maximumSize"); // NON-NLS: getMaximumSize() + test(ImageIcon.class, "image"); // NON-NLS: getImage() + test(ImageIcon.class, "imageObserver"); // NON-NLS: getImageObserver() + test(JMenuBar.class, "helpMenu"); // NON-NLS: getHelpMenu() + test(JScrollPane.class, "verticalScrollBar"); // NON-NLS: getVerticalScrollBar() + test(JScrollPane.class, "horizontalScrollBar"); // NON-NLS: getHorizontalScrollBar() + test(JScrollPane.class, "rowHeader"); // NON-NLS: getRowHeader() + test(JScrollPane.class, "columnHeader"); // NON-NLS: getColumnHeader() + test(JViewport.class, "extentSize"); // NON-NLS: getExtentSize() + test(JTableHeader.class, "defaultRenderer"); // NON-NLS: getDefaultRenderer() + test(JList.class, "cellRenderer"); // NON-NLS: getCellRenderer() + test(JList.class, "selectedIndices"); // NON-NLS: getSelectedIndices() + test(DefaultListSelectionModel.class, "leadSelectionIndex"); // NON-NLS: getLeadSelectionIndex() + test(DefaultListSelectionModel.class, "anchorSelectionIndex"); // NON-NLS: getAnchorSelectionIndex() + test(JComboBox.class, "selectedIndex"); // NON-NLS: getSelectedIndex() + test(JTabbedPane.class, "selectedIndex"); // NON-NLS: getSelectedIndex() + test(JTabbedPane.class, "selectedComponent"); // NON-NLS: getSelectedComponent() + test(AbstractButton.class, "disabledIcon"); // NON-NLS: getDisabledIcon() + test(JLabel.class, "disabledIcon"); // NON-NLS: getDisabledIcon() + test(JTextComponent.class, "caret"); // NON-NLS: getCaret() + test(JTextComponent.class, "caretPosition"); // NON-NLS: getCaretPosition() + test(JTextComponent.class, "selectionStart"); // NON-NLS: getSelectionStart() + test(JTextComponent.class, "selectionEnd"); // NON-NLS: getSelectionEnd() + } + + private static void test(Class type) { + Object value = getExpectedValue(type); + test(value, BeanUtils.getPropertyDescriptor(type, "property")); // NON-NLS: the property to check + test(value, BeanUtils.getEventSetDescriptor(type, "eventSet")); // NON-NLS: the event set to check + System.out.println(); + } + + private static void test(Class type, String property) { + System.out.print(type.getName() + ": "); + test(Boolean.TRUE, BeanUtils.getPropertyDescriptor(type, property)); + } + + private static void test(Object expected, FeatureDescriptor fd) { + System.out.println(fd.getName()); + Object actual = fd.getValue("transient"); // NON-NLS: the attribute name + if ((actual == null) ? (expected != null) : !actual.equals(expected)) + throw new Error("expected " + expected + " value, but actual value is " + actual); + } + + private static Object getExpectedValue(Class type) { + try { + return type.getField("VALUE").get(type); // NON-NLS: the field name with expected value + } catch (NoSuchFieldException exception) { + return null; + } catch (IllegalAccessException exception) { + throw new Error("unexpected error", exception); + } + } + + + public static class Null { + public Object getProperty() { + return this; + } + + public void setProperty(Object object) { + } + + public void addEventSetListener(EventSetListener listener) { + } + + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class True { + public static final Boolean VALUE = Boolean.TRUE; + + @Transient + public Object getProperty() { + return this; + } + + @Transient + public void setProperty(Object object) { + } + + @Transient + public void addEventSetListener(EventSetListener listener) { + } + + @Transient + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class False { + public static final Boolean VALUE = Boolean.FALSE; + + @Transient(false) + public Object getProperty() { + return this; + } + + @Transient(false) + public void setProperty(Object object) { + } + + @Transient(false) + public void addEventSetListener(EventSetListener listener) { + } + + @Transient(false) + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class NullNull extends Null { + @Override + public Object getProperty() { + return this; + } + + @Override + public void setProperty(Object object) { + } + + @Override + public void addEventSetListener(EventSetListener listener) { + } + + @Override + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class TrueNull extends Null { + public static final Boolean VALUE = Boolean.TRUE; + + @Override + @Transient + public Object getProperty() { + return this; + } + + @Override + @Transient + public void setProperty(Object object) { + } + + @Override + @Transient + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class FalseNull extends Null { + public static final Boolean VALUE = Boolean.FALSE; + + @Override + @Transient(false) + public Object getProperty() { + return this; + } + + @Override + @Transient(false) + public void setProperty(Object object) { + } + + @Override + @Transient(false) + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient(false) + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class NullTrue extends True { + @Override + public Object getProperty() { + return this; + } + + @Override + public void setProperty(Object object) { + } + + @Override + public void addEventSetListener(EventSetListener listener) { + } + + @Override + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class TrueTrue extends True { + @Override + @Transient + public Object getProperty() { + return this; + } + + @Override + @Transient + public void setProperty(Object object) { + } + + @Override + @Transient + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class FalseTrue extends True { + public static final Boolean VALUE = Boolean.FALSE; + + @Override + @Transient(false) + public Object getProperty() { + return this; + } + + @Override + @Transient(false) + public void setProperty(Object object) { + } + + @Override + @Transient(false) + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient(false) + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class NullFalse extends False { + @Override + public Object getProperty() { + return this; + } + + @Override + public void setProperty(Object object) { + } + + @Override + public void addEventSetListener(EventSetListener listener) { + } + + @Override + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class TrueFalse extends False { + public static final Boolean VALUE = Boolean.TRUE; + + @Override + @Transient + public Object getProperty() { + return this; + } + + @Override + @Transient + public void setProperty(Object object) { + } + + @Override + @Transient + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static class FalseFalse extends False { + @Override + @Transient(false) + public Object getProperty() { + return this; + } + + @Override + @Transient(false) + public void setProperty(Object object) { + } + + @Override + @Transient(false) + public void addEventSetListener(EventSetListener listener) { + } + + @Override + @Transient(false) + public void removeEventSetListener(EventSetListener listener) { + } + } + + public static final class EventSetListener implements EventListener { + } +} diff --git a/jdk/test/java/beans/XMLEncoder/Test4935607.java b/jdk/test/java/beans/XMLEncoder/Test4935607.java new file mode 100644 index 0000000000000000000000000000000000000000..3d5e70e6df1522b9878db47a16711e47c5820430 --- /dev/null +++ b/jdk/test/java/beans/XMLEncoder/Test4935607.java @@ -0,0 +1,83 @@ +/* + * Copyright 2007 Sun Microsystems, Inc. All Rights Reserved. + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * This code is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License version 2 only, as + * published by the Free Software Foundation. + * + * 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, + * CA 95054 USA or visit www.sun.com if you need additional information or + * have any questions. + */ + +/* + * @test %I% %G% + * @bug 4935607 + * @summary Tests transient properties + * @author Sergey Malenkov + */ + +import java.beans.Transient; + +public class Test4935607 extends AbstractTest { + public static void main(String[] args) { + new Test4935607().test(true); + } + + @Override + protected TransientBean getObject() { + TransientBean bean = new TransientBean(); + bean.setName("some string"); // NON-NLS: some string + return bean; + } + + @Override + protected TransientBean getAnotherObject() { + TransientBean bean = new TransientBean(); + bean.setName("another string"); // NON-NLS: another string + bean.setComment("some comment"); // NON-NLS: some comment + return bean; + } + + @Override + protected void validate(TransientBean before, TransientBean after) { + if (!before.getName().equals(after.getName())) + throw new Error("the name property incorrectly encoded"); + + if (null != after.getComment()) + throw new Error("the comment property should be encoded"); + } + + public static class TransientBean { + private String name; + private String comment; + + public String getName() { + return this.name; + } + + public void setName(String name) { + this.name = name; + } + + @Transient + public String getComment() { + return this.comment; + } + + public void setComment(String comment) { + this.comment = comment; + } + } +}