Merge of the beans separation into the fully buildable JDK
authorJaroslav Tulach <jtulach@netbeans.org>
Fri, 19 Jun 2009 15:50:04 +0200
changeset 1244f2029f449786
parent 1243 10e566202519
parent 1241 e38683764572
child 1245 1f8950ac34bf
Merge of the beans separation into the fully buildable JDK
build.xml
     1.1 --- a/build.xml	Fri Jun 19 15:33:12 2009 +0200
     1.2 +++ b/build.xml	Fri Jun 19 15:50:04 2009 +0200
     1.3 @@ -98,7 +98,7 @@
     1.4              <filename name="**/*-*"/>
     1.5              <filename name="java/dyn/**"/>
     1.6              <filename name="sun/dyn/**"/>
     1.7 -
     1.8 +            
     1.9              <filename name="com/sun/script/javascript/**"/>
    1.10              <filename name="sun/dc/**"/>
    1.11              <filename name="sun/nio/fs/Solaris**"/>
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/src/share/classes/META-INF/services/sun.beans.AppletProxy	Fri Jun 19 15:50:04 2009 +0200
     2.3 @@ -0,0 +1,1 @@
     2.4 +sun.applet.BeansBridge
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/src/share/classes/java/beans/BeanFactory.java	Fri Jun 19 15:50:04 2009 +0200
     3.3 @@ -0,0 +1,402 @@
     3.4 +/*
     3.5 + * Copyright 1996-2009 Sun Microsystems, Inc.  All Rights Reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.  Sun designates this
    3.11 + * particular file as subject to the "Classpath" exception as provided
    3.12 + * by Sun in the LICENSE file that accompanied this code.
    3.13 + *
    3.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.17 + * version 2 for more details (a copy is included in the LICENSE file that
    3.18 + * accompanied this code).
    3.19 + *
    3.20 + * You should have received a copy of the GNU General Public License version
    3.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.23 + *
    3.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    3.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    3.26 + * have any questions.
    3.27 + */
    3.28 +
    3.29 +package java.beans;
    3.30 +
    3.31 +import com.sun.beans.finder.ClassFinder;
    3.32 +
    3.33 +import java.awt.GraphicsEnvironment;
    3.34 +
    3.35 +import java.beans.beancontext.BeanContext;
    3.36 +
    3.37 +import java.io.IOException;
    3.38 +import java.io.InputStream;
    3.39 +import java.io.ObjectInputStream;
    3.40 +import java.io.ObjectStreamClass;
    3.41 +import java.io.StreamCorruptedException;
    3.42 +
    3.43 +
    3.44 +import java.security.AccessController;
    3.45 +import java.security.PrivilegedAction;
    3.46 +
    3.47 +import java.util.Iterator;
    3.48 +import java.util.ServiceLoader;
    3.49 +
    3.50 +import sun.awt.AppContext;
    3.51 +import sun.beans.AppletProxy;
    3.52 +
    3.53 +/**
    3.54 + * This class provides some general purpose beans control methods.
    3.55 + * @since 1.7
    3.56 + */
    3.57 +public class BeanFactory {
    3.58 +    private static final Object DESIGN_TIME = new Object();
    3.59 +    private static final Object GUI_AVAILABLE = new Object();
    3.60 +
    3.61 +    /**
    3.62 +     * <p>
    3.63 +     * Instantiate a JavaBean.
    3.64 +     * </p>
    3.65 +     *
    3.66 +     * @param     cls         the class-loader from which we should create
    3.67 +     *                        the bean.  If this is null, then the system
    3.68 +     *                        class-loader is used.
    3.69 +     * @param     beanName    the name of the bean within the class-loader.
    3.70 +     *                        For example "sun.beanbox.foobah"
    3.71 +     *
    3.72 +     * @exception ClassNotFoundException if the class of a serialized
    3.73 +     *              object could not be found.
    3.74 +     * @exception IOException if an I/O error occurs.
    3.75 +     */
    3.76 +
    3.77 +    public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException {
    3.78 +        return BeanFactory.instantiate(cls, beanName, null, null);
    3.79 +    }
    3.80 +
    3.81 +    /**
    3.82 +     * <p>
    3.83 +     * Instantiate a JavaBean.
    3.84 +     * </p>
    3.85 +     *
    3.86 +     * @param     cls         the class-loader from which we should create
    3.87 +     *                        the bean.  If this is null, then the system
    3.88 +     *                        class-loader is used.
    3.89 +     * @param     beanName    the name of the bean within the class-loader.
    3.90 +     *                        For example "sun.beanbox.foobah"
    3.91 +     * @param     beanContext The BeanContext in which to nest the new bean
    3.92 +     *
    3.93 +     * @exception ClassNotFoundException if the class of a serialized
    3.94 +     *              object could not be found.
    3.95 +     * @exception IOException if an I/O error occurs.
    3.96 +     */
    3.97 +
    3.98 +    public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException {
    3.99 +        return BeanFactory.instantiate(cls, beanName, beanContext, null);
   3.100 +    }
   3.101 +
   3.102 +    /**
   3.103 +     * Instantiate a bean.
   3.104 +     * <p>
   3.105 +     * The bean is created based on a name relative to a class-loader.
   3.106 +     * This name should be a dot-separated name such as "a.b.c".
   3.107 +     * <p>
   3.108 +     * In Beans 1.0 the given name can indicate either a serialized object
   3.109 +     * or a class.  Other mechanisms may be added in the future.  In
   3.110 +     * beans 1.0 we first try to treat the beanName as a serialized object
   3.111 +     * name then as a class name.
   3.112 +     * <p>
   3.113 +     * When using the beanName as a serialized object name we convert the
   3.114 +     * given beanName to a resource pathname and add a trailing ".ser" suffix.
   3.115 +     * We then try to load a serialized object from that resource.
   3.116 +     * <p>
   3.117 +     * For example, given a beanName of "x.y", Beans.instantiate would first
   3.118 +     * try to read a serialized object from the resource "x/y.ser" and if
   3.119 +     * that failed it would try to load the class "x.y" and create an
   3.120 +     * instance of that class.
   3.121 +     * <p>
   3.122 +     * If the bean is a subtype of java.applet.Applet, then it is given
   3.123 +     * some special initialization.  First, it is supplied with a default
   3.124 +     * AppletStub and AppletContext.  Second, if it was instantiated from
   3.125 +     * a classname the applet's "init" method is called.  (If the bean was
   3.126 +     * deserialized this step is skipped.)
   3.127 +     * <p>
   3.128 +     * Note that for beans which are applets, it is the caller's responsiblity
   3.129 +     * to call "start" on the applet.  For correct behaviour, this should be done
   3.130 +     * after the applet has been added into a visible AWT container.
   3.131 +     * <p>
   3.132 +     * Note that applets created via beans.instantiate run in a slightly
   3.133 +     * different environment than applets running inside browsers.  In
   3.134 +     * particular, bean applets have no access to "parameters", so they may
   3.135 +     * wish to provide property get/set methods to set parameter values.  We
   3.136 +     * advise bean-applet developers to test their bean-applets against both
   3.137 +     * the JDK appletviewer (for a reference browser environment) and the
   3.138 +     * BDK BeanBox (for a reference bean container).
   3.139 +     *
   3.140 +     * @param     cls         the class-loader from which we should create
   3.141 +     *                        the bean.  If this is null, then the system
   3.142 +     *                        class-loader is used.
   3.143 +     * @param     beanName    the name of the bean within the class-loader.
   3.144 +     *                        For example "sun.beanbox.foobah"
   3.145 +     * @param     beanContext The BeanContext in which to nest the new bean
   3.146 +     * @param     initializer The AppletInitializer for the new bean
   3.147 +     *
   3.148 +     * @exception ClassNotFoundException if the class of a serialized
   3.149 +     *              object could not be found.
   3.150 +     * @exception IOException if an I/O error occurs.
   3.151 +     */
   3.152 +    static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, Object initializer)
   3.153 +                        throws IOException, ClassNotFoundException {
   3.154 +
   3.155 +        InputStream ins;
   3.156 +        ObjectInputStream oins = null;
   3.157 +        Object result = null;
   3.158 +        boolean serialized = false;
   3.159 +        IOException serex = null;
   3.160 +
   3.161 +        // If the given classloader is null, we check if an
   3.162 +        // system classloader is available and (if so)
   3.163 +        // use that instead.
   3.164 +        // Note that calls on the system class loader will
   3.165 +        // look in the bootstrap class loader first.
   3.166 +        if (cls == null) {
   3.167 +            try {
   3.168 +                cls = ClassLoader.getSystemClassLoader();
   3.169 +            } catch (SecurityException ex) {
   3.170 +                // We're not allowed to access the system class loader.
   3.171 +                // Drop through.
   3.172 +            }
   3.173 +        }
   3.174 +
   3.175 +        // Try to find a serialized object with this name
   3.176 +        final String serName = beanName.replace('.','/').concat(".ser");
   3.177 +        final ClassLoader loader = cls;
   3.178 +        ins = (InputStream)AccessController.doPrivileged
   3.179 +            (new PrivilegedAction() {
   3.180 +                public Object run() {
   3.181 +                    if (loader == null)
   3.182 +                        return ClassLoader.getSystemResourceAsStream(serName);
   3.183 +                    else
   3.184 +                        return loader.getResourceAsStream(serName);
   3.185 +                }
   3.186 +        });
   3.187 +        if (ins != null) {
   3.188 +            try {
   3.189 +                if (cls == null) {
   3.190 +                    oins = new ObjectInputStream(ins);
   3.191 +                } else {
   3.192 +                    oins = new ObjectInputStreamWithLoader(ins, cls);
   3.193 +                }
   3.194 +                result = oins.readObject();
   3.195 +                serialized = true;
   3.196 +                oins.close();
   3.197 +            } catch (IOException ex) {
   3.198 +                ins.close();
   3.199 +                // Drop through and try opening the class.  But remember
   3.200 +                // the exception in case we can't find the class either.
   3.201 +                serex = ex;
   3.202 +            } catch (ClassNotFoundException ex) {
   3.203 +                ins.close();
   3.204 +                throw ex;
   3.205 +            }
   3.206 +        }
   3.207 +
   3.208 +        if (result == null) {
   3.209 +            // No serialized object, try just instantiating the class
   3.210 +            Class cl;
   3.211 +
   3.212 +            try {
   3.213 +                cl = ClassFinder.findClass(beanName, cls);
   3.214 +            } catch (ClassNotFoundException ex) {
   3.215 +                // There is no appropriate class.  If we earlier tried to
   3.216 +                // deserialize an object and got an IO exception, throw that,
   3.217 +                // otherwise rethrow the ClassNotFoundException.
   3.218 +                if (serex != null) {
   3.219 +                    throw serex;
   3.220 +                }
   3.221 +                throw ex;
   3.222 +            }
   3.223 +
   3.224 +            /*
   3.225 +             * Try to instantiate the class.
   3.226 +             */
   3.227 +
   3.228 +                try {
   3.229 +                result = cl.newInstance();
   3.230 +            } catch (Exception ex) {
   3.231 +                // We have to remap the exception to one in our signature.
   3.232 +                // But we pass extra information in the detail message.
   3.233 +                throw new ClassNotFoundException("" + cl + " : " + ex, ex);
   3.234 +            }
   3.235 +        }
   3.236 +
   3.237 +        if (result != null) {
   3.238 +
   3.239 +            // Ok, if the result is an applet initialize it.
   3.240 +            Iterator<AppletProxy> it = ServiceLoader.load(AppletProxy.class).iterator();
   3.241 +            AppletProxy ap = it.hasNext() ? it.next() : null;
   3.242 +            if (ap != null || !ap.initialize(
   3.243 +                result, initializer, serialized, beanName, beanContext, cls
   3.244 +            )) {
   3.245 +                if (beanContext != null) beanContext.add(result);
   3.246 +            }
   3.247 +        }
   3.248 +
   3.249 +        return result;
   3.250 +    }
   3.251 +
   3.252 +
   3.253 +    /**
   3.254 +     * From a given bean, obtain an object representing a specified
   3.255 +     * type view of that source object.
   3.256 +     * <p>
   3.257 +     * The result may be the same object or a different object.  If
   3.258 +     * the requested target view isn't available then the given
   3.259 +     * bean is returned.
   3.260 +     * <p>
   3.261 +     * This method is provided in Beans 1.0 as a hook to allow the
   3.262 +     * addition of more flexible bean behaviour in the future.
   3.263 +     *
   3.264 +     * @param bean        Object from which we want to obtain a view.
   3.265 +     * @param targetType  The type of view we'd like to get.
   3.266 +     *
   3.267 +     */
   3.268 +    public static Object getInstanceOf(Object bean, Class<?> targetType) {
   3.269 +        return bean;
   3.270 +    }
   3.271 +
   3.272 +    /**
   3.273 +     * Check if a bean can be viewed as a given target type.
   3.274 +     * The result will be true if the Beans.getInstanceof method
   3.275 +     * can be used on the given bean to obtain an object that
   3.276 +     * represents the specified targetType type view.
   3.277 +     *
   3.278 +     * @param bean  Bean from which we want to obtain a view.
   3.279 +     * @param targetType  The type of view we'd like to get.
   3.280 +     * @return "true" if the given bean supports the given targetType.
   3.281 +     *
   3.282 +     */
   3.283 +    public static boolean isInstanceOf(Object bean, Class<?> targetType) {
   3.284 +        return Introspector.isSubclass(bean.getClass(), targetType);
   3.285 +    }
   3.286 +
   3.287 +
   3.288 +    /**
   3.289 +     * Test if we are in design-mode.
   3.290 +     *
   3.291 +     * @return  True if we are running in an application construction
   3.292 +     *          environment.
   3.293 +     *
   3.294 +     * @see DesignMode
   3.295 +     */
   3.296 +    public static boolean isDesignTime() {
   3.297 +        Object value = AppContext.getAppContext().get(DESIGN_TIME);
   3.298 +        return (value instanceof Boolean) && (Boolean) value;
   3.299 +    }
   3.300 +
   3.301 +    /**
   3.302 +     * Determines whether beans can assume a GUI is available.
   3.303 +     *
   3.304 +     * @return  True if we are running in an environment where beans
   3.305 +     *     can assume that an interactive GUI is available, so they
   3.306 +     *     can pop up dialog boxes, etc.  This will normally return
   3.307 +     *     true in a windowing environment, and will normally return
   3.308 +     *     false in a server environment or if an application is
   3.309 +     *     running as part of a batch job.
   3.310 +     *
   3.311 +     * @see Visibility
   3.312 +     *
   3.313 +     */
   3.314 +    public static boolean isGuiAvailable() {
   3.315 +        Object value = AppContext.getAppContext().get(GUI_AVAILABLE);
   3.316 +        return (value instanceof Boolean) ? (Boolean) value : !GraphicsEnvironment.isHeadless();
   3.317 +    }
   3.318 +
   3.319 +    /**
   3.320 +     * Used to indicate whether of not we are running in an application
   3.321 +     * builder environment.
   3.322 +     *
   3.323 +     * <p>Note that this method is security checked
   3.324 +     * and is not available to (for example) untrusted applets.
   3.325 +     * More specifically, if there is a security manager,
   3.326 +     * its <code>checkPropertiesAccess</code>
   3.327 +     * method is called. This could result in a SecurityException.
   3.328 +     *
   3.329 +     * @param isDesignTime  True if we're in an application builder tool.
   3.330 +     * @exception  SecurityException  if a security manager exists and its
   3.331 +     *             <code>checkPropertiesAccess</code> method doesn't allow setting
   3.332 +     *              of system properties.
   3.333 +     * @see SecurityManager#checkPropertiesAccess
   3.334 +     */
   3.335 +
   3.336 +    public static void setDesignTime(boolean isDesignTime)
   3.337 +                        throws SecurityException {
   3.338 +        SecurityManager sm = System.getSecurityManager();
   3.339 +        if (sm != null) {
   3.340 +            sm.checkPropertiesAccess();
   3.341 +        }
   3.342 +        AppContext.getAppContext().put(DESIGN_TIME, Boolean.valueOf(isDesignTime));
   3.343 +    }
   3.344 +
   3.345 +    /**
   3.346 +     * Used to indicate whether of not we are running in an environment
   3.347 +     * where GUI interaction is available.
   3.348 +     *
   3.349 +     * <p>Note that this method is security checked
   3.350 +     * and is not available to (for example) untrusted applets.
   3.351 +     * More specifically, if there is a security manager,
   3.352 +     * its <code>checkPropertiesAccess</code>
   3.353 +     * method is called. This could result in a SecurityException.
   3.354 +     *
   3.355 +     * @param isGuiAvailable  True if GUI interaction is available.
   3.356 +     * @exception  SecurityException  if a security manager exists and its
   3.357 +     *             <code>checkPropertiesAccess</code> method doesn't allow setting
   3.358 +     *              of system properties.
   3.359 +     * @see SecurityManager#checkPropertiesAccess
   3.360 +     */
   3.361 +
   3.362 +    public static void setGuiAvailable(boolean isGuiAvailable)
   3.363 +                        throws SecurityException {
   3.364 +        SecurityManager sm = System.getSecurityManager();
   3.365 +        if (sm != null) {
   3.366 +            sm.checkPropertiesAccess();
   3.367 +        }
   3.368 +        AppContext.getAppContext().put(GUI_AVAILABLE, Boolean.valueOf(isGuiAvailable));
   3.369 +    }
   3.370 +}
   3.371 +
   3.372 +/**
   3.373 + * This subclass of ObjectInputStream delegates loading of classes to
   3.374 + * an existing ClassLoader.
   3.375 + */
   3.376 +
   3.377 +class ObjectInputStreamWithLoader extends ObjectInputStream
   3.378 +{
   3.379 +    private ClassLoader loader;
   3.380 +
   3.381 +    /**
   3.382 +     * Loader must be non-null;
   3.383 +     */
   3.384 +
   3.385 +    public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
   3.386 +            throws IOException, StreamCorruptedException {
   3.387 +
   3.388 +        super(in);
   3.389 +        if (loader == null) {
   3.390 +            throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
   3.391 +        }
   3.392 +        this.loader = loader;
   3.393 +    }
   3.394 +
   3.395 +    /**
   3.396 +     * Use the given ClassLoader rather than using the system class
   3.397 +     */
   3.398 +    protected Class resolveClass(ObjectStreamClass classDesc)
   3.399 +        throws IOException, ClassNotFoundException {
   3.400 +
   3.401 +        String cname = classDesc.getName();
   3.402 +        return ClassFinder.resolveClass(cname, this.loader);
   3.403 +    }
   3.404 +}
   3.405 +
     4.1 --- a/src/share/classes/java/beans/Beans.java	Fri Jun 19 15:33:12 2009 +0200
     4.2 +++ b/src/share/classes/java/beans/Beans.java	Fri Jun 19 15:50:04 2009 +0200
     4.3 @@ -27,13 +27,7 @@
     4.4  
     4.5  import com.sun.beans.finder.ClassFinder;
     4.6  
     4.7 -import java.applet.Applet;
     4.8 -import java.applet.AppletContext;
     4.9 -import java.applet.AppletStub;
    4.10 -import java.applet.AudioClip;
    4.11 -
    4.12  import java.awt.GraphicsEnvironment;
    4.13 -import java.awt.Image;
    4.14  
    4.15  import java.beans.beancontext.BeanContext;
    4.16  
    4.17 @@ -43,17 +37,15 @@
    4.18  import java.io.ObjectStreamClass;
    4.19  import java.io.StreamCorruptedException;
    4.20  
    4.21 -import java.net.URL;
    4.22  
    4.23  import java.security.AccessController;
    4.24  import java.security.PrivilegedAction;
    4.25  
    4.26 -import java.util.Enumeration;
    4.27 -import java.util.Hashtable;
    4.28  import java.util.Iterator;
    4.29 -import java.util.Vector;
    4.30 +import java.util.ServiceLoader;
    4.31  
    4.32  import sun.awt.AppContext;
    4.33 +import sun.beans.AppletProxy;
    4.34  
    4.35  /**
    4.36   * This class provides some general purpose beans control methods.
    4.37 @@ -77,10 +69,11 @@
    4.38       * @exception ClassNotFoundException if the class of a serialized
    4.39       *              object could not be found.
    4.40       * @exception IOException if an I/O error occurs.
    4.41 +     * @deprecated Use {@link BeanFactory}
    4.42       */
    4.43  
    4.44      public static Object instantiate(ClassLoader cls, String beanName) throws IOException, ClassNotFoundException {
    4.45 -        return Beans.instantiate(cls, beanName, null, null);
    4.46 +        return BeanFactory.instantiate(cls, beanName, null, null);
    4.47      }
    4.48  
    4.49      /**
    4.50 @@ -98,10 +91,11 @@
    4.51       * @exception ClassNotFoundException if the class of a serialized
    4.52       *              object could not be found.
    4.53       * @exception IOException if an I/O error occurs.
    4.54 +     * @deprecated Use {@link BeanFactory}
    4.55       */
    4.56  
    4.57      public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext) throws IOException, ClassNotFoundException {
    4.58 -        return Beans.instantiate(cls, beanName, beanContext, null);
    4.59 +        return BeanFactory.instantiate(cls, beanName, beanContext, null);
    4.60      }
    4.61  
    4.62      /**
    4.63 @@ -157,198 +151,8 @@
    4.64  
    4.65      public static Object instantiate(ClassLoader cls, String beanName, BeanContext beanContext, AppletInitializer initializer)
    4.66                          throws IOException, ClassNotFoundException {
    4.67 -
    4.68 -        InputStream ins;
    4.69 -        ObjectInputStream oins = null;
    4.70 -        Object result = null;
    4.71 -        boolean serialized = false;
    4.72 -        IOException serex = null;
    4.73 -
    4.74 -        // If the given classloader is null, we check if an
    4.75 -        // system classloader is available and (if so)
    4.76 -        // use that instead.
    4.77 -        // Note that calls on the system class loader will
    4.78 -        // look in the bootstrap class loader first.
    4.79 -        if (cls == null) {
    4.80 -            try {
    4.81 -                cls = ClassLoader.getSystemClassLoader();
    4.82 -            } catch (SecurityException ex) {
    4.83 -                // We're not allowed to access the system class loader.
    4.84 -                // Drop through.
    4.85 -            }
    4.86 -        }
    4.87 -
    4.88 -        // Try to find a serialized object with this name
    4.89 -        final String serName = beanName.replace('.','/').concat(".ser");
    4.90 -        final ClassLoader loader = cls;
    4.91 -        ins = (InputStream)AccessController.doPrivileged
    4.92 -            (new PrivilegedAction() {
    4.93 -                public Object run() {
    4.94 -                    if (loader == null)
    4.95 -                        return ClassLoader.getSystemResourceAsStream(serName);
    4.96 -                    else
    4.97 -                        return loader.getResourceAsStream(serName);
    4.98 -                }
    4.99 -        });
   4.100 -        if (ins != null) {
   4.101 -            try {
   4.102 -                if (cls == null) {
   4.103 -                    oins = new ObjectInputStream(ins);
   4.104 -                } else {
   4.105 -                    oins = new ObjectInputStreamWithLoader(ins, cls);
   4.106 -                }
   4.107 -                result = oins.readObject();
   4.108 -                serialized = true;
   4.109 -                oins.close();
   4.110 -            } catch (IOException ex) {
   4.111 -                ins.close();
   4.112 -                // Drop through and try opening the class.  But remember
   4.113 -                // the exception in case we can't find the class either.
   4.114 -                serex = ex;
   4.115 -            } catch (ClassNotFoundException ex) {
   4.116 -                ins.close();
   4.117 -                throw ex;
   4.118 -            }
   4.119 -        }
   4.120 -
   4.121 -        if (result == null) {
   4.122 -            // No serialized object, try just instantiating the class
   4.123 -            Class cl;
   4.124 -
   4.125 -            try {
   4.126 -                cl = ClassFinder.findClass(beanName, cls);
   4.127 -            } catch (ClassNotFoundException ex) {
   4.128 -                // There is no appropriate class.  If we earlier tried to
   4.129 -                // deserialize an object and got an IO exception, throw that,
   4.130 -                // otherwise rethrow the ClassNotFoundException.
   4.131 -                if (serex != null) {
   4.132 -                    throw serex;
   4.133 -                }
   4.134 -                throw ex;
   4.135 -            }
   4.136 -
   4.137 -            /*
   4.138 -             * Try to instantiate the class.
   4.139 -             */
   4.140 -
   4.141 -            try {
   4.142 -                result = cl.newInstance();
   4.143 -            } catch (Exception ex) {
   4.144 -                // We have to remap the exception to one in our signature.
   4.145 -                // But we pass extra information in the detail message.
   4.146 -                throw new ClassNotFoundException("" + cl + " : " + ex, ex);
   4.147 -            }
   4.148 -        }
   4.149 -
   4.150 -        if (result != null) {
   4.151 -
   4.152 -            // Ok, if the result is an applet initialize it.
   4.153 -
   4.154 -            AppletStub stub = null;
   4.155 -
   4.156 -            if (result instanceof Applet) {
   4.157 -                Applet  applet      = (Applet) result;
   4.158 -                boolean needDummies = initializer == null;
   4.159 -
   4.160 -                if (needDummies) {
   4.161 -
   4.162 -                    // Figure our the codebase and docbase URLs.  We do this
   4.163 -                    // by locating the URL for a known resource, and then
   4.164 -                    // massaging the URL.
   4.165 -
   4.166 -                    // First find the "resource name" corresponding to the bean
   4.167 -                    // itself.  So a serialzied bean "a.b.c" would imply a
   4.168 -                    // resource name of "a/b/c.ser" and a classname of "x.y"
   4.169 -                    // would imply a resource name of "x/y.class".
   4.170 -
   4.171 -                    final String resourceName;
   4.172 -
   4.173 -                    if (serialized) {
   4.174 -                        // Serialized bean
   4.175 -                        resourceName = beanName.replace('.','/').concat(".ser");
   4.176 -                    } else {
   4.177 -                        // Regular class
   4.178 -                        resourceName = beanName.replace('.','/').concat(".class");
   4.179 -                    }
   4.180 -
   4.181 -                    URL objectUrl = null;
   4.182 -                    URL codeBase  = null;
   4.183 -                    URL docBase   = null;
   4.184 -
   4.185 -                    // Now get the URL correponding to the resource name.
   4.186 -
   4.187 -                    final ClassLoader cloader = cls;
   4.188 -                    objectUrl = (URL)
   4.189 -                        AccessController.doPrivileged
   4.190 -                        (new PrivilegedAction() {
   4.191 -                            public Object run() {
   4.192 -                                if (cloader == null)
   4.193 -                                    return ClassLoader.getSystemResource
   4.194 -                                                                (resourceName);
   4.195 -                                else
   4.196 -                                    return cloader.getResource(resourceName);
   4.197 -                            }
   4.198 -                    });
   4.199 -
   4.200 -                    // If we found a URL, we try to locate the docbase by taking
   4.201 -                    // of the final path name component, and the code base by taking
   4.202 -                    // of the complete resourceName.
   4.203 -                    // So if we had a resourceName of "a/b/c.class" and we got an
   4.204 -                    // objectURL of "file://bert/classes/a/b/c.class" then we would
   4.205 -                    // want to set the codebase to "file://bert/classes/" and the
   4.206 -                    // docbase to "file://bert/classes/a/b/"
   4.207 -
   4.208 -                    if (objectUrl != null) {
   4.209 -                        String s = objectUrl.toExternalForm();
   4.210 -
   4.211 -                        if (s.endsWith(resourceName)) {
   4.212 -                            int ix   = s.length() - resourceName.length();
   4.213 -                            codeBase = new URL(s.substring(0,ix));
   4.214 -                            docBase  = codeBase;
   4.215 -
   4.216 -                            ix = s.lastIndexOf('/');
   4.217 -
   4.218 -                            if (ix >= 0) {
   4.219 -                                docBase = new URL(s.substring(0,ix+1));
   4.220 -                            }
   4.221 -                        }
   4.222 -                    }
   4.223 -
   4.224 -                    // Setup a default context and stub.
   4.225 -                    BeansAppletContext context = new BeansAppletContext(applet);
   4.226 -
   4.227 -                    stub = (AppletStub)new BeansAppletStub(applet, context, codeBase, docBase);
   4.228 -                    applet.setStub(stub);
   4.229 -                } else {
   4.230 -                    initializer.initialize(applet, beanContext);
   4.231 -                }
   4.232 -
   4.233 -                // now, if there is a BeanContext, add the bean, if applicable.
   4.234 -
   4.235 -                if (beanContext != null) {
   4.236 -                    beanContext.add(result);
   4.237 -                }
   4.238 -
   4.239 -                // If it was deserialized then it was already init-ed.
   4.240 -                // Otherwise we need to initialize it.
   4.241 -
   4.242 -                if (!serialized) {
   4.243 -                    // We need to set a reasonable initial size, as many
   4.244 -                    // applets are unhappy if they are started without
   4.245 -                    // having been explicitly sized.
   4.246 -                    applet.setSize(100,100);
   4.247 -                    applet.init();
   4.248 -                }
   4.249 -
   4.250 -                if (needDummies) {
   4.251 -                  ((BeansAppletStub)stub).active = true;
   4.252 -                } else initializer.activate(applet);
   4.253 -
   4.254 -            } else if (beanContext != null) beanContext.add(result);
   4.255 -        }
   4.256 -
   4.257 -        return result;
   4.258 -    }
   4.259 +        return BeanFactory.instantiate(cls, beanName, beanContext, initializer);
   4.260 +   }
   4.261  
   4.262  
   4.263      /**
   4.264 @@ -364,7 +168,7 @@
   4.265       *
   4.266       * @param bean        Object from which we want to obtain a view.
   4.267       * @param targetType  The type of view we'd like to get.
   4.268 -     *
   4.269 +     * @deprecated Use {@link BeanFactory}
   4.270       */
   4.271      public static Object getInstanceOf(Object bean, Class<?> targetType) {
   4.272          return bean;
   4.273 @@ -379,10 +183,10 @@
   4.274       * @param bean  Bean from which we want to obtain a view.
   4.275       * @param targetType  The type of view we'd like to get.
   4.276       * @return "true" if the given bean supports the given targetType.
   4.277 -     *
   4.278 +     * @deprecated Use {@link BeanFactory#isInstanceOf}
   4.279       */
   4.280      public static boolean isInstanceOf(Object bean, Class<?> targetType) {
   4.281 -        return Introspector.isSubclass(bean.getClass(), targetType);
   4.282 +        return BeanFactory.isInstanceOf(bean, targetType);
   4.283      }
   4.284  
   4.285  
   4.286 @@ -393,10 +197,10 @@
   4.287       *          environment.
   4.288       *
   4.289       * @see DesignMode
   4.290 +     * @deprecated Use {@link BeanFactory}
   4.291       */
   4.292      public static boolean isDesignTime() {
   4.293 -        Object value = AppContext.getAppContext().get(DESIGN_TIME);
   4.294 -        return (value instanceof Boolean) && (Boolean) value;
   4.295 +        return BeanFactory.isDesignTime();
   4.296      }
   4.297  
   4.298      /**
   4.299 @@ -410,11 +214,10 @@
   4.300       *     running as part of a batch job.
   4.301       *
   4.302       * @see Visibility
   4.303 -     *
   4.304 +     * @deprecated Use {@link BeanFactory}
   4.305       */
   4.306      public static boolean isGuiAvailable() {
   4.307 -        Object value = AppContext.getAppContext().get(GUI_AVAILABLE);
   4.308 -        return (value instanceof Boolean) ? (Boolean) value : !GraphicsEnvironment.isHeadless();
   4.309 +        return BeanFactory.isGuiAvailable();
   4.310      }
   4.311  
   4.312      /**
   4.313 @@ -436,11 +239,7 @@
   4.314  
   4.315      public static void setDesignTime(boolean isDesignTime)
   4.316                          throws SecurityException {
   4.317 -        SecurityManager sm = System.getSecurityManager();
   4.318 -        if (sm != null) {
   4.319 -            sm.checkPropertiesAccess();
   4.320 -        }
   4.321 -        AppContext.getAppContext().put(DESIGN_TIME, Boolean.valueOf(isDesignTime));
   4.322 +        BeanFactory.setDesignTime(isDesignTime);
   4.323      }
   4.324  
   4.325      /**
   4.326 @@ -458,180 +257,10 @@
   4.327       *             <code>checkPropertiesAccess</code> method doesn't allow setting
   4.328       *              of system properties.
   4.329       * @see SecurityManager#checkPropertiesAccess
   4.330 +     * @deprecated Use {@link BeanFactory}
   4.331       */
   4.332 -
   4.333      public static void setGuiAvailable(boolean isGuiAvailable)
   4.334                          throws SecurityException {
   4.335 -        SecurityManager sm = System.getSecurityManager();
   4.336 -        if (sm != null) {
   4.337 -            sm.checkPropertiesAccess();
   4.338 -        }
   4.339 -        AppContext.getAppContext().put(GUI_AVAILABLE, Boolean.valueOf(isGuiAvailable));
   4.340 +        BeanFactory.setGuiAvailable(isGuiAvailable);
   4.341      }
   4.342  }
   4.343 -
   4.344 -/**
   4.345 - * This subclass of ObjectInputStream delegates loading of classes to
   4.346 - * an existing ClassLoader.
   4.347 - */
   4.348 -
   4.349 -class ObjectInputStreamWithLoader extends ObjectInputStream
   4.350 -{
   4.351 -    private ClassLoader loader;
   4.352 -
   4.353 -    /**
   4.354 -     * Loader must be non-null;
   4.355 -     */
   4.356 -
   4.357 -    public ObjectInputStreamWithLoader(InputStream in, ClassLoader loader)
   4.358 -            throws IOException, StreamCorruptedException {
   4.359 -
   4.360 -        super(in);
   4.361 -        if (loader == null) {
   4.362 -            throw new IllegalArgumentException("Illegal null argument to ObjectInputStreamWithLoader");
   4.363 -        }
   4.364 -        this.loader = loader;
   4.365 -    }
   4.366 -
   4.367 -    /**
   4.368 -     * Use the given ClassLoader rather than using the system class
   4.369 -     */
   4.370 -    protected Class resolveClass(ObjectStreamClass classDesc)
   4.371 -        throws IOException, ClassNotFoundException {
   4.372 -
   4.373 -        String cname = classDesc.getName();
   4.374 -        return ClassFinder.resolveClass(cname, this.loader);
   4.375 -    }
   4.376 -}
   4.377 -
   4.378 -/**
   4.379 - * Package private support class.  This provides a default AppletContext
   4.380 - * for beans which are applets.
   4.381 - */
   4.382 -
   4.383 -class BeansAppletContext implements AppletContext {
   4.384 -    Applet target;
   4.385 -    Hashtable imageCache = new Hashtable();
   4.386 -
   4.387 -    BeansAppletContext(Applet target) {
   4.388 -        this.target = target;
   4.389 -    }
   4.390 -
   4.391 -    public AudioClip getAudioClip(URL url) {
   4.392 -        // We don't currently support audio clips in the Beans.instantiate
   4.393 -        // applet context, unless by some luck there exists a URL content
   4.394 -        // class that can generate an AudioClip from the audio URL.
   4.395 -        try {
   4.396 -            return (AudioClip) url.getContent();
   4.397 -        } catch (Exception ex) {
   4.398 -            return null;
   4.399 -        }
   4.400 -    }
   4.401 -
   4.402 -    public synchronized Image getImage(URL url) {
   4.403 -        Object o = imageCache.get(url);
   4.404 -        if (o != null) {
   4.405 -            return (Image)o;
   4.406 -        }
   4.407 -        try {
   4.408 -            o = url.getContent();
   4.409 -            if (o == null) {
   4.410 -                return null;
   4.411 -            }
   4.412 -            if (o instanceof Image) {
   4.413 -                imageCache.put(url, o);
   4.414 -                return (Image) o;
   4.415 -            }
   4.416 -            // Otherwise it must be an ImageProducer.
   4.417 -            Image img = target.createImage((java.awt.image.ImageProducer)o);
   4.418 -            imageCache.put(url, img);
   4.419 -            return img;
   4.420 -
   4.421 -        } catch (Exception ex) {
   4.422 -            return null;
   4.423 -        }
   4.424 -    }
   4.425 -
   4.426 -    public Applet getApplet(String name) {
   4.427 -        return null;
   4.428 -    }
   4.429 -
   4.430 -    public Enumeration getApplets() {
   4.431 -        Vector applets = new Vector();
   4.432 -        applets.addElement(target);
   4.433 -        return applets.elements();
   4.434 -    }
   4.435 -
   4.436 -    public void showDocument(URL url) {
   4.437 -        // We do nothing.
   4.438 -    }
   4.439 -
   4.440 -    public void showDocument(URL url, String target) {
   4.441 -        // We do nothing.
   4.442 -    }
   4.443 -
   4.444 -    public void showStatus(String status) {
   4.445 -        // We do nothing.
   4.446 -    }
   4.447 -
   4.448 -    public void setStream(String key, InputStream stream)throws IOException{
   4.449 -        // We do nothing.
   4.450 -    }
   4.451 -
   4.452 -    public InputStream getStream(String key){
   4.453 -        // We do nothing.
   4.454 -        return null;
   4.455 -    }
   4.456 -
   4.457 -    public Iterator getStreamKeys(){
   4.458 -        // We do nothing.
   4.459 -        return null;
   4.460 -    }
   4.461 -}
   4.462 -
   4.463 -/**
   4.464 - * Package private support class.  This provides an AppletStub
   4.465 - * for beans which are applets.
   4.466 - */
   4.467 -class BeansAppletStub implements AppletStub {
   4.468 -    transient boolean active;
   4.469 -    transient Applet target;
   4.470 -    transient AppletContext context;
   4.471 -    transient URL codeBase;
   4.472 -    transient URL docBase;
   4.473 -
   4.474 -    BeansAppletStub(Applet target,
   4.475 -                AppletContext context, URL codeBase,
   4.476 -                                URL docBase) {
   4.477 -        this.target = target;
   4.478 -        this.context = context;
   4.479 -        this.codeBase = codeBase;
   4.480 -        this.docBase = docBase;
   4.481 -    }
   4.482 -
   4.483 -    public boolean isActive() {
   4.484 -        return active;
   4.485 -    }
   4.486 -
   4.487 -    public URL getDocumentBase() {
   4.488 -        // use the root directory of the applet's class-loader
   4.489 -        return docBase;
   4.490 -    }
   4.491 -
   4.492 -    public URL getCodeBase() {
   4.493 -        // use the directory where we found the class or serialized object.
   4.494 -        return codeBase;
   4.495 -    }
   4.496 -
   4.497 -    public String getParameter(String name) {
   4.498 -        return null;
   4.499 -    }
   4.500 -
   4.501 -    public AppletContext getAppletContext() {
   4.502 -        return context;
   4.503 -    }
   4.504 -
   4.505 -    public void appletResize(int width, int height) {
   4.506 -        // we do nothing.
   4.507 -    }
   4.508 -}
     5.1 --- a/src/share/classes/java/beans/beancontext/BeanContextSupport.java	Fri Jun 19 15:33:12 2009 +0200
     5.2 +++ b/src/share/classes/java/beans/beancontext/BeanContextSupport.java	Fri Jun 19 15:50:04 2009 +0200
     5.3 @@ -28,17 +28,13 @@
     5.4  import java.awt.Component;
     5.5  import java.awt.Container;
     5.6  
     5.7 -import java.beans.Beans;
     5.8 -import java.beans.AppletInitializer;
     5.9 +import java.beans.BeanFactory;
    5.10  
    5.11 -import java.beans.DesignMode;
    5.12  
    5.13  import java.beans.PropertyChangeEvent;
    5.14  import java.beans.PropertyChangeListener;
    5.15 -import java.beans.PropertyChangeSupport;
    5.16  
    5.17  import java.beans.VetoableChangeListener;
    5.18 -import java.beans.VetoableChangeSupport;
    5.19  import java.beans.PropertyVetoException;
    5.20  
    5.21  import java.beans.Visibility;
    5.22 @@ -197,7 +193,7 @@
    5.23             throws IOException, ClassNotFoundException {
    5.24          BeanContext bc = getBeanContextPeer();
    5.25  
    5.26 -        return Beans.instantiate(bc.getClass().getClassLoader(), beanName, bc);
    5.27 +        return BeanFactory.instantiate(bc.getClass().getClassLoader(), beanName, bc);
    5.28      }
    5.29  
    5.30      /**
     6.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     6.2 +++ b/src/share/classes/sun/applet/BeansBridge.java	Fri Jun 19 15:50:04 2009 +0200
     6.3 @@ -0,0 +1,298 @@
     6.4 +/*
     6.5 + * Copyright 1996-2009 Sun Microsystems, Inc.  All Rights Reserved.
     6.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     6.7 + *
     6.8 + * This code is free software; you can redistribute it and/or modify it
     6.9 + * under the terms of the GNU General Public License version 2 only, as
    6.10 + * published by the Free Software Foundation.  Sun designates this
    6.11 + * particular file as subject to the "Classpath" exception as provided
    6.12 + * by Sun in the LICENSE file that accompanied this code.
    6.13 + *
    6.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    6.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    6.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    6.17 + * version 2 for more details (a copy is included in the LICENSE file that
    6.18 + * accompanied this code).
    6.19 + *
    6.20 + * You should have received a copy of the GNU General Public License version
    6.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    6.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    6.23 + *
    6.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    6.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    6.26 + * have any questions.
    6.27 + */
    6.28 +
    6.29 +package sun.applet;
    6.30 +
    6.31 +import java.applet.Applet;
    6.32 +import java.applet.AppletContext;
    6.33 +import java.applet.AppletStub;
    6.34 +import java.applet.AudioClip;
    6.35 +import java.awt.Image;
    6.36 +import java.beans.AppletInitializer;
    6.37 +import java.beans.beancontext.BeanContext;
    6.38 +import java.io.IOException;
    6.39 +import java.io.InputStream;
    6.40 +import java.net.MalformedURLException;
    6.41 +import java.net.URL;
    6.42 +import java.security.AccessController;
    6.43 +import java.security.PrivilegedAction;
    6.44 +import java.util.Enumeration;
    6.45 +import java.util.Hashtable;
    6.46 +import java.util.Iterator;
    6.47 +import java.util.Vector;
    6.48 +import sun.beans.AppletProxy;
    6.49 +
    6.50 +/**
    6.51 + * Implementaiton of the bridge between
    6.52 + * java.beans module and java.applet module.
    6.53 + * 
    6.54 + * @author Jaroslav Tulach
    6.55 + */
    6.56 +
    6.57 +public class BeansBridge extends AppletProxy {
    6.58 +    public boolean initialize(
    6.59 +        Object result, Object init, boolean serialized,
    6.60 +        String beanName, BeanContext beanContext, ClassLoader cls
    6.61 +    ) throws MalformedURLException {
    6.62 +        if (!(result instanceof Applet)) {
    6.63 +            return false;
    6.64 +        }
    6.65 +        AppletInitializer initializer = (AppletInitializer)init;
    6.66 +
    6.67 +        AppletStub stub = null;
    6.68 +        Applet applet = (Applet) result;
    6.69 +        boolean needDummies = initializer == null;
    6.70 +
    6.71 +        if (needDummies) {
    6.72 +
    6.73 +            // Figure our the codebase and docbase URLs.  We do this
    6.74 +            // by locating the URL for a known resource, and then
    6.75 +            // massaging the URL.
    6.76 +
    6.77 +            // First find the "resource name" corresponding to the bean
    6.78 +            // itself.  So a serialzied bean "a.b.c" would imply a
    6.79 +            // resource name of "a/b/c.ser" and a classname of "x.y"
    6.80 +            // would imply a resource name of "x/y.class".
    6.81 +
    6.82 +            final String resourceName;
    6.83 +
    6.84 +            if (serialized) {
    6.85 +                // Serialized bean
    6.86 +                resourceName = beanName.replace('.', '/').concat(".ser");
    6.87 +            } else {
    6.88 +                // Regular class
    6.89 +                resourceName = beanName.replace('.', '/').concat(".class");
    6.90 +            }
    6.91 +
    6.92 +            URL objectUrl = null;
    6.93 +            URL codeBase = null;
    6.94 +            URL docBase = null;
    6.95 +
    6.96 +            // Now get the URL correponding to the resource name.
    6.97 +
    6.98 +            final ClassLoader cloader = cls;
    6.99 +            objectUrl = (URL) AccessController.doPrivileged(new PrivilegedAction() {
   6.100 +
   6.101 +                public Object run() {
   6.102 +                    if (cloader == null) {
   6.103 +                        return ClassLoader.getSystemResource(resourceName);
   6.104 +                    } else {
   6.105 +                        return cloader.getResource(resourceName);
   6.106 +                    }
   6.107 +                }
   6.108 +            });
   6.109 +
   6.110 +            // If we found a URL, we try to locate the docbase by taking
   6.111 +            // of the final path name component, and the code base by taking
   6.112 +            // of the complete resourceName.
   6.113 +            // So if we had a resourceName of "a/b/c.class" and we got an
   6.114 +            // objectURL of "file://bert/classes/a/b/c.class" then we would
   6.115 +            // want to set the codebase to "file://bert/classes/" and the
   6.116 +            // docbase to "file://bert/classes/a/b/"
   6.117 +
   6.118 +            if (objectUrl != null) {
   6.119 +                String s = objectUrl.toExternalForm();
   6.120 +
   6.121 +                if (s.endsWith(resourceName)) {
   6.122 +                    int ix = s.length() - resourceName.length();
   6.123 +                    codeBase = new URL(s.substring(0, ix));
   6.124 +                    docBase = codeBase;
   6.125 +
   6.126 +                    ix = s.lastIndexOf('/');
   6.127 +
   6.128 +                    if (ix >= 0) {
   6.129 +                        docBase = new URL(s.substring(0, ix + 1));
   6.130 +                    }
   6.131 +                }
   6.132 +            }
   6.133 +
   6.134 +            // Setup a default context and stub.
   6.135 +            BeansAppletContext context = new BeansAppletContext(applet);
   6.136 +
   6.137 +            stub = (AppletStub) new BeansAppletStub(applet, context, codeBase, docBase);
   6.138 +            applet.setStub(stub);
   6.139 +        } else {
   6.140 +            initializer.initialize(applet, beanContext);
   6.141 +        }
   6.142 +
   6.143 +        // now, if there is a BeanContext, add the bean, if applicable.
   6.144 +
   6.145 +        if (beanContext != null) {
   6.146 +            beanContext.add(result);
   6.147 +        }
   6.148 +
   6.149 +        // If it was deserialized then it was already init-ed.
   6.150 +        // Otherwise we need to initialize it.
   6.151 +
   6.152 +        if (!serialized) {
   6.153 +            // We need to set a reasonable initial size, as many
   6.154 +            // applets are unhappy if they are started without
   6.155 +            // having been explicitly sized.
   6.156 +            applet.setSize(100, 100);
   6.157 +            applet.init();
   6.158 +        }
   6.159 +
   6.160 +        if (needDummies) {
   6.161 +            ((BeansAppletStub) stub).active = true;
   6.162 +        } else {
   6.163 +            initializer.activate(applet);
   6.164 +        }
   6.165 +
   6.166 +        return true;
   6.167 +    }
   6.168 +}
   6.169 +
   6.170 +
   6.171 +/**
   6.172 + * Package private support class.  This provides a default AppletContext
   6.173 + * for beans which are applets.
   6.174 + */
   6.175 +
   6.176 +class BeansAppletContext implements AppletContext {
   6.177 +    Applet target;
   6.178 +    Hashtable imageCache = new Hashtable();
   6.179 +
   6.180 +    BeansAppletContext(Applet target) {
   6.181 +        this.target = target;
   6.182 +    }
   6.183 +
   6.184 +    public AudioClip getAudioClip(URL url) {
   6.185 +        // We don't currently support audio clips in the Beans.instantiate
   6.186 +        // applet context, unless by some luck there exists a URL content
   6.187 +        // class that can generate an AudioClip from the audio URL.
   6.188 +        try {
   6.189 +            return (AudioClip) url.getContent();
   6.190 +        } catch (Exception ex) {
   6.191 +            return null;
   6.192 +        }
   6.193 +    }
   6.194 +
   6.195 +    public synchronized Image getImage(URL url) {
   6.196 +        Object o = imageCache.get(url);
   6.197 +        if (o != null) {
   6.198 +            return (Image)o;
   6.199 +        }
   6.200 +        try {
   6.201 +            o = url.getContent();
   6.202 +            if (o == null) {
   6.203 +                return null;
   6.204 +            }
   6.205 +            if (o instanceof Image) {
   6.206 +                imageCache.put(url, o);
   6.207 +                return (Image) o;
   6.208 +            }
   6.209 +            // Otherwise it must be an ImageProducer.
   6.210 +            Image img = target.createImage((java.awt.image.ImageProducer)o);
   6.211 +            imageCache.put(url, img);
   6.212 +            return img;
   6.213 +
   6.214 +        } catch (Exception ex) {
   6.215 +            return null;
   6.216 +        }
   6.217 +    }
   6.218 +
   6.219 +    public Applet getApplet(String name) {
   6.220 +        return null;
   6.221 +    }
   6.222 +
   6.223 +    public Enumeration getApplets() {
   6.224 +        Vector applets = new Vector();
   6.225 +        applets.addElement(target);
   6.226 +        return applets.elements();
   6.227 +    }
   6.228 +
   6.229 +    public void showDocument(URL url) {
   6.230 +        // We do nothing.
   6.231 +    }
   6.232 +
   6.233 +    public void showDocument(URL url, String target) {
   6.234 +        // We do nothing.
   6.235 +    }
   6.236 +
   6.237 +    public void showStatus(String status) {
   6.238 +        // We do nothing.
   6.239 +    }
   6.240 +
   6.241 +    public void setStream(String key, InputStream stream)throws IOException{
   6.242 +        // We do nothing.
   6.243 +    }
   6.244 +
   6.245 +    public InputStream getStream(String key){
   6.246 +        // We do nothing.
   6.247 +        return null;
   6.248 +    }
   6.249 +
   6.250 +    public Iterator getStreamKeys(){
   6.251 +        // We do nothing.
   6.252 +        return null;
   6.253 +    }
   6.254 +}
   6.255 +
   6.256 +/**
   6.257 + * Package private support class.  This provides an AppletStub
   6.258 + * for beans which are applets.
   6.259 + */
   6.260 +class BeansAppletStub implements AppletStub {
   6.261 +    transient boolean active;
   6.262 +    transient Applet target;
   6.263 +    transient AppletContext context;
   6.264 +    transient URL codeBase;
   6.265 +    transient URL docBase;
   6.266 +
   6.267 +    BeansAppletStub(Applet target,
   6.268 +                AppletContext context, URL codeBase,
   6.269 +                                URL docBase) {
   6.270 +        this.target = target;
   6.271 +        this.context = context;
   6.272 +        this.codeBase = codeBase;
   6.273 +        this.docBase = docBase;
   6.274 +    }
   6.275 +
   6.276 +    public boolean isActive() {
   6.277 +        return active;
   6.278 +    }
   6.279 +
   6.280 +    public URL getDocumentBase() {
   6.281 +        // use the root directory of the applet's class-loader
   6.282 +        return docBase;
   6.283 +    }
   6.284 +
   6.285 +    public URL getCodeBase() {
   6.286 +        // use the directory where we found the class or serialized object.
   6.287 +        return codeBase;
   6.288 +    }
   6.289 +
   6.290 +    public String getParameter(String name) {
   6.291 +        return null;
   6.292 +    }
   6.293 +
   6.294 +    public AppletContext getAppletContext() {
   6.295 +        return context;
   6.296 +    }
   6.297 +
   6.298 +    public void appletResize(int width, int height) {
   6.299 +        // we do nothing.
   6.300 +    }
   6.301 +}
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/share/classes/sun/beans/AppletProxy.java	Fri Jun 19 15:50:04 2009 +0200
     7.3 @@ -0,0 +1,42 @@
     7.4 +/*
     7.5 + * Copyright 1996-2009 Sun Microsystems, Inc.  All Rights Reserved.
     7.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     7.7 + *
     7.8 + * This code is free software; you can redistribute it and/or modify it
     7.9 + * under the terms of the GNU General Public License version 2 only, as
    7.10 + * published by the Free Software Foundation.  Sun designates this
    7.11 + * particular file as subject to the "Classpath" exception as provided
    7.12 + * by Sun in the LICENSE file that accompanied this code.
    7.13 + *
    7.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    7.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    7.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    7.17 + * version 2 for more details (a copy is included in the LICENSE file that
    7.18 + * accompanied this code).
    7.19 + *
    7.20 + * You should have received a copy of the GNU General Public License version
    7.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    7.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    7.23 + *
    7.24 + * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
    7.25 + * CA 95054 USA or visit www.sun.com if you need additional information or
    7.26 + * have any questions.
    7.27 + */
    7.28 +
    7.29 +package sun.beans;
    7.30 +
    7.31 +import java.beans.beancontext.BeanContext;
    7.32 +import java.net.MalformedURLException;
    7.33 +
    7.34 +
    7.35 +/**
    7.36 + * Bridge between java.beans module and java.applet module.
    7.37 + * @author Jaroslav Tulach
    7.38 + */
    7.39 +
    7.40 +public abstract class AppletProxy {
    7.41 +    public abstract boolean initialize(
    7.42 +        Object result, Object init, boolean serialized,
    7.43 +        String beanName, BeanContext beanContext, ClassLoader cls
    7.44 +    ) throws MalformedURLException;
    7.45 +}