You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/07/18 06:05:11 UTC
svn commit: r557139 [1/2] - in /harmony/enhanced/classlib/branches/java6: ./
make/ modules/beans/META-INF/ modules/beans/src/main/java/java/beans/
modules/beans/src/main/java/java/beans/beancontext/
modules/beans/src/main/java/org/apache/harmony/beans/...
Author: pyang
Date: Tue Jul 17 21:05:08 2007
New Revision: 557139
URL: http://svn.apache.org/viewvc?view=rev&rev=557139
Log:
Merge updates from classlib trunk@557124 since r556788
Added:
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/UtilCollectionPersistenceDelegate.java
- copied unchanged from r557124, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/java/beans/UtilCollectionPersistenceDelegate.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/PrimitiveWrapperPersistenceDelegate.java
- copied unchanged from r557124, harmony/enhanced/classlib/trunk/modules/beans/src/main/java/org/apache/harmony/beans/PrimitiveWrapperPersistenceDelegate.java
Modified:
harmony/enhanced/classlib/branches/java6/THIRD_PARTY_NOTICES.txt
harmony/enhanced/classlib/branches/java6/make/build-java.xml
harmony/enhanced/classlib/branches/java6/make/depends.properties
harmony/enhanced/classlib/branches/java6/make/depends.xml
harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Beans.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/beancontext/BeanContextSupport.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/internal/nls/messages.properties
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/BeansTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IndexedPropertyDescriptorTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyDescriptorTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerRegressionTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
harmony/enhanced/classlib/branches/java6/modules/beans/src/test/support/java/org/apache/harmony/beans/tests/support/mock/MockJavaBean.java
harmony/enhanced/classlib/branches/java6/modules/jndi/src/main/java/javax/naming/ldap/SortControl.java
harmony/enhanced/classlib/branches/java6/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/ldap/SortControlTest.java
harmony/enhanced/classlib/branches/java6/modules/lang-management/make/exclude.common
harmony/enhanced/classlib/branches/java6/modules/swing/src/main/java/common/javax/swing/plaf/basic/BasicSliderUI.java
Modified: harmony/enhanced/classlib/branches/java6/THIRD_PARTY_NOTICES.txt
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/THIRD_PARTY_NOTICES.txt?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/THIRD_PARTY_NOTICES.txt (original)
+++ harmony/enhanced/classlib/branches/java6/THIRD_PARTY_NOTICES.txt Tue Jul 17 21:05:08 2007
@@ -570,4 +570,106 @@
+===============================================================================
+===============================================================================
+
+License notice for the DejaVu fonts package
+==============================================
+
+Fonts are (c) Bitstream (see below). DejaVu changes are in public domain. Glyphs imported from Arev fonts are (c) Tavmjung Bah (see below)
+
+Bitstream Vera Fonts Copyright
+------------------------------
+
+Copyright (c) 2003 by Bitstream, Inc. All Rights Reserved. Bitstream Vera is
+a trademark of Bitstream, Inc.
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of the fonts accompanying this license ("Fonts") and associated
+documentation files (the "Font Software"), to reproduce and distribute the
+Font Software, including without limitation the rights to use, copy, merge,
+publish, distribute, and/or sell copies of the Font Software, and to permit
+persons to whom the Font Software is furnished to do so, subject to the
+following conditions:
+
+The above copyright and trademark notices and this permission notice shall
+be included in all copies of one or more of the Font Software typefaces.
+
+The Font Software may be modified, altered, or added to, and in particular
+the designs of glyphs or characters in the Fonts may be modified and
+additional glyphs or characters may be added to the Fonts, only if the fonts
+are renamed to names not containing either the words "Bitstream" or the word
+"Vera".
+
+This License becomes null and void to the extent applicable to Fonts or Font
+Software that has been modified and is distributed under the "Bitstream
+Vera" names.
+
+The Font Software may be sold as part of a larger software package but no
+copy of one or more of the Font Software typefaces may be sold by itself.
+
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT,
+TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL BITSTREAM OR THE GNOME
+FOUNDATION BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, INCLUDING
+ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
+WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
+THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE
+FONT SOFTWARE.
+
+Except as contained in this notice, the names of Gnome, the Gnome
+Foundation, and Bitstream Inc., shall not be used in advertising or
+otherwise to promote the sale, use or other dealings in this Font Software
+without prior written authorization from the Gnome Foundation or Bitstream
+Inc., respectively. For further information, contact: fonts at gnome dot
+org.
+
+Arev Fonts Copyright
+------------------------------
+
+Copyright (c) 2006 by Tavmjong Bah. All Rights Reserved.
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of the fonts accompanying this license ("Fonts") and
+associated documentation files (the "Font Software"), to reproduce
+and distribute the modifications to the Bitstream Vera Font Software,
+including without limitation the rights to use, copy, merge, publish,
+distribute, and/or sell copies of the Font Software, and to permit
+persons to whom the Font Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright and trademark notices and this permission notice
+shall be included in all copies of one or more of the Font Software
+typefaces.
+
+The Font Software may be modified, altered, or added to, and in
+particular the designs of glyphs or characters in the Fonts may be
+modified and additional glyphs or characters may be added to the
+Fonts, only if the fonts are renamed to names not containing either
+the words "Tavmjong Bah" or the word "Arev".
+
+This License becomes null and void to the extent applicable to Fonts
+or Font Software that has been modified and is distributed under the
+"Tavmjong Bah Arev" names.
+
+The Font Software may be sold as part of a larger software package but
+no copy of one or more of the Font Software typefaces may be sold by
+itself.
+
+THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT
+OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL
+TAVMJONG BAH BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL
+DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM
+OTHER DEALINGS IN THE FONT SOFTWARE.
+
+Except as contained in this notice, the name of Tavmjong Bah shall not
+be used in advertising or otherwise to promote the sale, use or other
+dealings in this Font Software without prior written authorization
+from Tavmjong Bah. For further information, contact: tavmjong @ free
+. fr.
Modified: harmony/enhanced/classlib/branches/java6/make/build-java.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/make/build-java.xml?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/make/build-java.xml (original)
+++ harmony/enhanced/classlib/branches/java6/make/build-java.xml Tue Jul 17 21:05:08 2007
@@ -305,6 +305,17 @@
<include name="rowset.properties" />
</fileset>
</copy>
+
+ <mkdir dir="${hy.jdk}/jre/lib/fonts" />
+ <copy todir="${hy.jdk}/jre/lib/fonts">
+ <fileset dir="${dejavu-fonts.fonts.dir}">
+ <include name="DejaVuSans.ttf" />
+ <include name="DejaVuSans-*.ttf" />
+ <exclude name="DejaVuSans-ExtraLight.ttf" />
+ <include name="DejaVuSerif.ttf" />
+ <include name="DejaVuSerif-*.ttf" />
+ </fileset>
+ </copy>
</target>
Modified: harmony/enhanced/classlib/branches/java6/make/depends.properties
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/make/depends.properties?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/make/depends.properties (original)
+++ harmony/enhanced/classlib/branches/java6/make/depends.properties Tue Jul 17 21:05:08 2007
@@ -125,3 +125,9 @@
awtdeps.extract.dir.x86_64=${depends.dir}/libs/build
awtdeps.testfile.x86_64=${awtdeps.extract.dir.x86_64}/win64_2007-02-08.txt
+dejavu-fonts.dir=${depends.dir}/dejavu-fonts
+dejavu-fonts.fonts.dir=${depends.dir}/dejavu-fonts/dejavu-ttf-2.18
+dejavu-fonts.zip=${dejavu-fonts.dir}/dejavu-ttf-2.18-1.zip
+dejavu-fonts.url=http://dfn.dl.sourceforge.net/sourceforge/dejavu/dejavu-ttf-2.18-1.zip
+dejavu-fonts.md5=72e0a87ec1f9c5c26c66eabcf1e2018e
+
Modified: harmony/enhanced/classlib/branches/java6/make/depends.xml
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/make/depends.xml?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/make/depends.xml (original)
+++ harmony/enhanced/classlib/branches/java6/make/depends.xml Tue Jul 17 21:05:08 2007
@@ -47,6 +47,7 @@
<check-one-file src="${jetty.url}" dest="${jetty.jar}" />
<check-one-file src="${jetty-util.url}" dest="${jetty-util.jar}" />
<check-one-file src="${servlet-api.url}" dest="${servlet-api.jar}" />
+ <check-one-file src="${dejavu-fonts.url}" dest="${dejavu-fonts.zip}" />
</target>
<target name="-check-win" if="is.windows" depends="-really-check-win" />
@@ -342,7 +343,11 @@
<download-one-file src="${servlet-api.url}" dest="${servlet-api.jar}"
md5="${servlet-api.md5}" />
-
+
+ <mkdir dir="${dejavu-fonts.dir}" />
+ <download-one-file src="${dejavu-fonts.url}" dest="${dejavu-fonts.zip}"
+ md5="${dejavu-fonts.md5}" />
+ <unzip src="${dejavu-fonts.zip}" dest="${dejavu-fonts.dir}" />
</target>
<target name="-download-win" if="is.windows" depends="-select-win-deps-x86_64,-select-win-deps-x86">
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/META-INF/MANIFEST.MF Tue Jul 17 21:05:08 2007
@@ -14,6 +14,7 @@
Import-Package: java.applet,
java.awt,
java.awt.event;resolution:=optional,
+ java.awt.font,
java.io,
java.lang,
java.lang.annotation,
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Beans.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Beans.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Beans.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Beans.java Tue Jul 17 21:05:08 2007
@@ -18,90 +18,221 @@
package java.beans;
import java.applet.Applet;
+import java.applet.AppletContext;
+import java.applet.AppletStub;
+import java.applet.AudioClip;
+import java.awt.Image;
import java.beans.beancontext.BeanContext;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.Vector;
+
import org.apache.harmony.beans.internal.nls.Messages;
+/**
+ * This class <code>Beans</code> provides some methods for manipulting bean
+ * controls.
+ *
+ */
+
public class Beans {
private static boolean designTime = false;
private static boolean guiAvailable = true;
+ /**
+ * Constructs a Beans instance.
+ */
public Beans() {
}
- public static Object instantiate(ClassLoader cls, String beanName,
- BeanContext beanContext, AppletInitializer initializer)
+ /**
+ * Obtains an instance of a JavaBean specified the bean name using the
+ * specified class loader.
+ * <p>
+ * If the specified class loader is null, the system class loader is used.
+ * </p>
+ *
+ * @param loader
+ * the specified class loader. It can be null.
+ * @param name
+ * the name of the JavaBean
+ * @return an isntance of the bean.
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ public static Object instantiate(ClassLoader loader, String name)
throws IOException, ClassNotFoundException {
- Object result = instantiate(cls, beanName, beanContext);
-
- if (result instanceof Applet) {
- initializer.initialize((Applet) result, beanContext);
- }
-
- return result;
+ return instantiate(loader, name, null, null);
}
- @SuppressWarnings("unchecked")
+ /**
+ * Obtains an instance of a JavaBean specified the bean name using the
+ * specified class loader, and adds the instance into the specified bean
+ * context.
+ *
+ * <p>
+ * If the specified class loader is null, the system class loader is used.
+ * </p>
+ *
+ * @param loader
+ * the specified class loader. It can be null.
+ * @param name
+ * the name of the JavaBean
+ * @param context
+ * the beancontext in which the bean instance will be added.
+ * @return an instance of the specified JavaBean.
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
public static Object instantiate(ClassLoader cls, String beanName,
- BeanContext beanContext) throws IOException, ClassNotFoundException {
- Object result = instantiate(cls, beanName);
-
- if (beanContext != null) {
- beanContext.add(result);
- }
-
- return result;
- }
-
- public static Object instantiate(ClassLoader cls, String beanName)
- throws IOException, ClassNotFoundException {
- Object result = null;
-
- String beanResourceName = getBeanResourceName(beanName);
-
- InputStream is = (cls == null) ? ClassLoader
- .getSystemResourceAsStream(beanResourceName) : cls
- .getResourceAsStream(beanResourceName);
-
- if (is != null) {
- ObjectInputStream ois = (cls == null) ? new ObjectInputStream(is) : new CustomizedObjectInputStream(is, cls);
- result = ois.readObject();
- }
-
- if (result == null) {
- try {
- Class<?> c = Class.forName(beanName, true,
- cls == null ? ClassLoader.getSystemClassLoader() : cls);
-
- try {
- result = c.newInstance();
+ BeanContext beanContext) throws IOException, ClassNotFoundException {
+ return instantiate(cls, beanName, beanContext, null);
- if (result instanceof Applet) {
- Applet applet = (Applet) result;
-
- applet.init();
- }
- } catch (IllegalAccessException iae) {
- throw new ClassNotFoundException(iae.getClass() + ": " //$NON-NLS-1$
- + iae.getMessage());
- }
- } catch (InstantiationException ie) {
- throw new ClassNotFoundException(ie.getClass() + ": " //$NON-NLS-1$
- + ie.getMessage());
- }
- }
-
- return result;
- }
+ }
+ /**
+ * Obtains an instance of a JavaBean specified by the bean name using the
+ * specified class loader, and adds the instance into the specified bean
+ * context.
+ * <p>
+ * The parameter name must be a qualified name relative to the specified
+ * class loader. For example, "java.awt.Button" and "x.y.z".
+ * </p>
+ * <p>
+ * If the specified class loader is null, the system class loader is used.
+ * </p>
+ * <p>
+ * Firstly, The class <code>Beans</code> regards the bean name as a
+ * serialized object name. The class <code>Beans</code> convert bean name
+ * into pathname, append a suffix ".ser" to the pathname. then try to load
+ * the resource using the specified class loader. If <code>Beans</code>
+ * fails to load the resource, <code>Beans</code> will regard the
+ * <code>name</code> as a class name and construct a new instance of the
+ * bean class.
+ * </p>
+ * <p>
+ * For example, if the name is specified as "x.y.z", The class
+ * <code>Beans</code> will try to load the serialized object from the
+ * resource "x/y/z.ser"; If <code>Beans</code> fails to load the resource
+ * "x/y/z.ser", it will create a new instance of "x.y.z".
+ * </p>
+ * <p>
+ * If the bean is an instance of java.applet.Applet, <code>Beans</code>
+ * will do some special initialization for this applet bean. First,
+ * <code>Beans</code> will set the default AppletStub and AppletContext
+ * for the applet bean (If the specified <code>AppletInitializer</code> is
+ * not null, <code>Beans</code> will call the
+ * <code>AppletInitializer.initialize</code> to set the default AppletStub
+ * and AppletContext for the applet bean). Second, <code>Beans</code> will
+ * call the <code>init</code> method of the applet. (If the applet bean is
+ * loaded as a serialized object, the <code>init</code> method will not be
+ * called.)
+ * </p>
+ *
+ * @param loader
+ * the specified class loader. It can be null.
+ * @param name
+ * the name of the JavaBean
+ * @param context
+ * the beancontext in which the bean instance will be added.
+ * @param initializer
+ * the AppletInitializer for applet bean instance.
+ * @return Obtains an instance of the JavaBean.
+ * @throws IOException
+ * @throws ClassNotFoundException
+ */
+ @SuppressWarnings("unchecked")
+ public static Object instantiate(ClassLoader cls, String beanName,
+ BeanContext context, AppletInitializer initializer)
+ throws IOException, ClassNotFoundException {
+ Object result = null;
+
+ boolean deserialized = true;
+
+ ClassLoader loader = null;
+
+ String beanResourceName = getBeanResourceName(beanName);
+
+ InputStream is = (cls == null) ? ClassLoader
+ .getSystemResourceAsStream(beanResourceName) : cls
+ .getResourceAsStream(beanResourceName);
+
+ if (is != null) {
+ ObjectInputStream ois = (cls == null) ? new ObjectInputStream(is)
+ : new CustomizedObjectInputStream(is, cls);
+ result = ois.readObject();
+ }
+
+ if (result == null) {
+ deserialized = false;
+ try {
+ loader = cls == null ? ClassLoader.getSystemClassLoader() : cls;
+ Class<?> c = Class.forName(beanName, true, loader);
+
+ try {
+ result = c.newInstance();
+
+ } catch (IllegalAccessException iae) {
+ throw new ClassNotFoundException(iae.getClass() + ": " //$NON-NLS-1$
+ + iae.getMessage());
+ }
+ } catch (InstantiationException ie) {
+ throw new ClassNotFoundException(ie.getClass() + ": " //$NON-NLS-1$
+ + ie.getMessage());
+ }
+ }
+
+ if (result != null) {
+ // Applet specific initialization
+ if (result instanceof Applet) {
+ appletLoaded((Applet) result, loader, beanName, context,
+ initializer, deserialized);
+ }
+ if (null != context) {
+ context.add(result);
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Obtain an alternative type view of the given bean. The view type is
+ * specified by the parameter <code>type</code>.
+ * <p>
+ * If the type view cannot be obtained, the original bean object is
+ * returned.
+ * </p>
+ *
+ * @param bean
+ * the original bean object.
+ * @param type
+ * the specified view type.
+ * @return a type view of the given bean.
+ */
public static Object getInstanceOf(Object bean, Class<?> targetType) {
return bean;
}
+ /**
+ * Determine if the the specified bean object can be viewed as the specified
+ * type.
+ *
+ * @param bean
+ * the specified bean object.
+ * @param type
+ * the specifed view type.
+ * @return true if the specified bean object can be viewed as the specified
+ * type; otherwise, return false;
+ */
public static boolean isInstanceOf(Object bean, Class<?> targetType) {
if (bean == null) {
throw new NullPointerException(Messages.getString("beans.1D")); //$NON-NLS-1$
@@ -110,12 +241,31 @@
return targetType == null ? false : targetType.isInstance(bean);
}
+ /**
+ * Set whether or not a GUI is available in the bean's current environment.
+ *
+ * @param value
+ * should be <code>true</code> to signify that a GUI is
+ * available, <code>false</code> otherwise.
+ * @throws SecurityException
+ * if the caller does not have the required permission to access
+ * or modify system properties.
+ */
public static synchronized void setGuiAvailable(boolean isGuiAvailable)
throws SecurityException {
checkPropertiesAccess();
guiAvailable = isGuiAvailable;
}
-
+
+ /**
+ * Used to indicate whether of not it's in an application construction
+ * environment.
+ *
+ * @param value
+ * true to indicate that it's in application construction
+ * environment.
+ * @throws SecurityException
+ */
public static void setDesignTime(boolean isDesignTime)
throws SecurityException {
checkPropertiesAccess();
@@ -124,10 +274,22 @@
}
}
+ /**
+ * Returns a boolean indication of whether or not a GUI is available for
+ * beans.
+ *
+ * @return <code>true</code> if a GUI is available, otherwise
+ * <code>false</code>.
+ */
public static synchronized boolean isGuiAvailable() {
return guiAvailable;
}
+ /**
+ * Determine if it's in design-mode.
+ *
+ * @return true if it's in an application construction environment.
+ */
public static synchronized boolean isDesignTime() {
return designTime;
}
@@ -143,5 +305,152 @@
private static String getBeanResourceName(String beanName) {
return beanName.replace('.', '/') + ".ser"; //$NON-NLS-1$
}
+
+
+ private static void appletLoaded(Applet applet, ClassLoader loader,
+ String name, BeanContext context, AppletInitializer initializer,
+ boolean deserialized) throws ClassNotFoundException {
+
+ // If there is an initializer
+ if (initializer != null) {
+ initializer.initialize(applet, context);
+ } else {
+ setStub(applet, loader, deserialized, name);
+ }
+
+ if (!deserialized) {
+ applet.init();
+ }
+
+ if (initializer != null) {
+ initializer.activate(applet);
+ }
+ }
+
+ private static void setStub(Applet applet, final ClassLoader loader,
+ boolean serialized, String beanName) throws ClassNotFoundException {
+ // Get path to the resource representing the applet.
+ String pathName = beanName.replace('.', '/');
+ final String resourceName = serialized ? pathName.concat(".ser") : pathName.concat(".class"); //$NON-NLS-1$ //$NON-NLS-2$
+ URL objectUrl = AccessController
+ .doPrivileged(new PrivilegedAction<URL>() {
+ public URL run() {
+ if (loader == null)
+ return ClassLoader.getSystemResource(resourceName);
+ return loader.getResource(resourceName);
+ }
+ });
+
+ // If we can't get to the applet itself, the codebase and doc base are
+ // left as null.
+ if (objectUrl == null) {
+ applet.setStub(getAppletStub(applet, getStubAppletContext(applet),
+ null, null));
+ return;
+ }
+
+ // Try to decompose the resource URL to get to the doc/code URL
+ String urlString = objectUrl.toExternalForm();
+
+ // This is the URL of the directory that contains the applet.
+ int codeURLlength = urlString.length() - resourceName.length();
+ URL codeBase = safeURL(urlString.substring(0, codeURLlength));
+
+ // URL of the document containing the applet.
+ int docURLlength = urlString.lastIndexOf('/');
+ URL docBase = safeURL(urlString.substring(0, docURLlength + 1));
+
+ applet.setStub(getAppletStub(applet, getStubAppletContext(applet),
+ codeBase, docBase));
+ }
+
+
+ private static AppletStub getAppletStub(final Applet target,
+ final AppletContext context, final URL codeBase, final URL docBase) {
+
+ return new AppletStub() {
+ public boolean isActive() {
+ return true;
+ }
+
+ public URL getDocumentBase() {
+ return docBase;
+ }
+
+ public URL getCodeBase() {
+ return codeBase;
+ }
+
+ public String getParameter(String name) {
+ // Applet beans have no params.
+ return null;
+ }
+
+ public AppletContext getAppletContext() {
+ return context;
+ }
+
+ public void appletResize(int width, int height) {
+ // Do nothing.
+ }
+ };
+ }
+
+ private static AppletContext getStubAppletContext(final Applet target) {
+ return new AppletContext() {
+ public AudioClip getAudioClip(URL url) {
+ return null;
+ }
+
+ public synchronized Image getImage(URL url) {
+ return null;
+ }
+
+ public Applet getApplet(String name) {
+ return null;
+ }
+
+ public Enumeration<Applet> getApplets() {
+ Vector<Applet> applets = new Vector<Applet>();
+ applets.addElement(target);
+ return applets.elements();
+ }
+
+ public void showDocument(URL url) {
+ // Do nothing.
+ }
+
+ public void showDocument(URL url, String aTarget) {
+ // Do nothing.
+ }
+
+ public void showStatus(String status) {
+ // Do nothing.
+ }
+
+ public void setStream(String key, InputStream stream)
+ throws IOException {
+ // Do nothing.
+ }
+
+ public InputStream getStream(String key) {
+ return null;
+ }
+
+ public Iterator<String> getStreamKeys() {
+ return null;
+ }
+ };
+ }
+
+
+ // Maps malformed URL exception to ClassNotFoundException
+ private static URL safeURL(String urlString) throws ClassNotFoundException {
+ try {
+ return new URL(urlString);
+ } catch (MalformedURLException exception) {
+ throw new ClassNotFoundException(exception.getMessage());
+ }
+ }
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/Encoder.java Tue Jul 17 21:05:08 2007
@@ -17,287 +17,364 @@
package java.beans;
-import java.util.HashMap;
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+import java.util.Collection;
+import java.util.Hashtable;
import java.util.IdentityHashMap;
-import java.util.Vector;
-import org.apache.harmony.beans.DefaultPersistenceDelegatesFactory;
-import org.apache.harmony.beans.NullPersistenceDelegate;
-import org.apache.harmony.beans.ObjectNode;
+import org.apache.harmony.beans.*;
+/**
+ * The <code>Encoder</code>, together with <code>PersistenceDelegate</code>
+ * s, can encode an object into a series of java statements. By executing these
+ * statements, a new object can be created and it will has the same state as the
+ * original object which has been passed to the encoder. Here "has the same
+ * state" means the two objects are indistinguishable from their public API.
+ * <p>
+ * The <code>Encoder</code> and <code>PersistenceDelegate</code> s do this
+ * by creating copies of the input object and all objects it references. The
+ * copy process continues recursively util every object in the object graph has
+ * its new copy and the new version has the same state as the old version. All
+ * statements used to create those new objects and executed on them during the
+ * process form the result of encoding.
+ * </p>
+ *
+ */
+@SuppressWarnings("unchecked")
public class Encoder {
- private ExceptionListener exceptionListener = defaultExListener;
+ private static final Hashtable delegates = new Hashtable();
- private static final ExceptionListener defaultExListener = new DefaultExceptionListener();
+ private static final DefaultPersistenceDelegate defaultPD = new DefaultPersistenceDelegate();
- private static class DefaultExceptionListener implements ExceptionListener {
+ private static final ArrayPersistenceDelegate arrayPD = new ArrayPersistenceDelegate();
- public void exceptionThrown(Exception exception) {
- System.err.println("Exception during encoding:" + exception); //$NON-NLS-1$
- System.err.println("Continue...");
- }
-
- }
-
- private static final HashMap<Class<?>, PersistenceDelegate> persistenceDelegates = new HashMap<Class<?>, PersistenceDelegate>();
-
- Vector<Object> roots = new Vector<Object>();
-
- IdentityHashMap<Object, ObjectNode> nodes = new IdentityHashMap<Object, ObjectNode>();
-
- private IdentityHashMap oldNewMap = new IdentityHashMap();
-
- public Encoder() {
- super();
- }
-
- public Object get(Object oldInstance) {
- if (oldInstance == null || oldInstance instanceof String
- || oldInstance == String.class) {
- return oldInstance;
- }
-
- return oldNewMap.get(oldInstance);
- }
-
- public Object remove(Object oldInstance) {
- // TODO - notify references on node deletion
- if (oldInstance == null) {
- return null;
- }
-
- getValue(nodes.remove(oldInstance));
- return oldNewMap.remove(oldInstance);
- }
-
- public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
- PersistenceDelegate result = persistenceDelegates.get(type);
-
- if (result == null) {
- result = DefaultPersistenceDelegatesFactory
- .getPersistenceDelegate(type);
- }
-
- return result;
- }
-
- public void setPersistenceDelegate(Class<?> type,
- PersistenceDelegate persistenceDelegate) {
- if (type == null || persistenceDelegate == null) {
- throw new NullPointerException();
- }
- persistenceDelegates.put(type, persistenceDelegate);
- }
-
- protected void writeObject(Object object) {
- roots.add(object);
- if (object == null) {
- return;
- }
- doWriteObject(object);
- }
-
- void doWriteObject(Object object) {
- PersistenceDelegate pd = (object != null) ? getPersistenceDelegate(object
- .getClass())
- : new NullPersistenceDelegate();
-
- if (pd == null) {
- pd = new DefaultPersistenceDelegate();
- }
-
- pd.writeObject(object, this);
- if (isString(object.getClass())) {
- nodes.put(object, new ObjectNode(pd.instantiate(object, this)));
- }
- }
-
- private Object forceNew(Object old) {
- if (old == null) {
- return null;
- }
- Object nu = get(old);
- if (nu != null) {
- return nu;
- }
- writeObject(old);
- return get(old);
- }
-
- private Object[] forceNewArray(Object oldArray[]) {
- if (oldArray == null) {
- return null;
- }
- Object newArray[] = new Object[oldArray.length];
- for (int i = 0; i < oldArray.length; i++) {
- newArray[i] = forceNew(oldArray[i]);
- }
- return newArray;
- }
-
- public void writeStatement(Statement oldStm) {
- if (oldStm == null) {
- throw new NullPointerException();
- }
- try {
- // FIXME add target processing here
- Object newTarget = forceNew(oldStm.getTarget());
- Object newArgs[] = forceNewArray(oldStm.getArguments());
- Statement statement = new Statement(newTarget, oldStm
- .getMethodName(), newArgs);
- statement.execute();
- } catch (Exception e) {
- getExceptionListener().exceptionThrown(e);
- }
- }
+ private static final java_lang_reflect_ProxyPersistenceDelegate proxyPD = new java_lang_reflect_ProxyPersistenceDelegate();
+
+ private static final NullPersistenceDelegate nullPD = new NullPersistenceDelegate();
+
+ private static final ExceptionListener defaultExListener = new DefaultExceptionListener();
+
+ private static class DefaultExceptionListener implements ExceptionListener {
+
+ public void exceptionThrown(Exception exception) {
+ System.err.println("Exception during encoding:" + exception); //$NON-NLS-1$
+ System.err.println("Continue...");
+ }
+
+ }
+
+ static {
+ PersistenceDelegate ppd = new PrimitiveWrapperPersistenceDelegate();
+ delegates.put(Boolean.class, ppd);
+ delegates.put(Byte.class, ppd);
+ delegates.put(Character.class, ppd);
+ delegates.put(Double.class, ppd);
+ delegates.put(Float.class, ppd);
+ delegates.put(Integer.class, ppd);
+ delegates.put(Long.class, ppd);
+ delegates.put(Short.class, ppd);
+
+ delegates.put(Class.class, new java_lang_ClassPersistenceDelegate());
+ delegates.put(Field.class, new java_lang_reflect_FieldPersistenceDelegate());
+ delegates.put(Method.class, new java_lang_reflect_MethodPersistenceDelegate());
+ delegates.put(String.class, new java_lang_StringPersistenceDelegate());
+ delegates.put(Proxy.class, new java_lang_reflect_ProxyPersistenceDelegate());
+ }
+
+ private ExceptionListener listener = defaultExListener;
+
+ private IdentityHashMap oldNewMap = new IdentityHashMap();
+
+ /**
+ * Construct a new encoder.
+ */
+ public Encoder() {
+ super();
+ }
+
+ /**
+ * Clear all the new objects have been created.
+ */
+ void clear() {
+ oldNewMap.clear();
+ }
+
+ /**
+ * Gets the new copy of the given old object.
+ * <p>
+ * Strings are special objects which have their new copy by default, so if
+ * the old object is a string, it is returned directly.
+ * </p>
+ *
+ * @param old
+ * an old object
+ * @return the new copy of the given old object, or null if there is not
+ * one.
+ */
+ public Object get(Object old) {
+ if (old == null || old instanceof String) {
+ return old;
+ }
+ return oldNewMap.get(old);
+ }
+
+ /**
+ * Returns the exception listener of this encoder.
+ * <p>
+ * An encoder always have a non-null exception listener. A default exception
+ * listener is used when the encoder is created.
+ * </p>
+ *
+ * @return the exception listener of this encoder
+ */
+ public ExceptionListener getExceptionListener() {
+ return listener;
+ }
+
+ /**
+ * Returns a <code>PersistenceDelegate</code> for the given class type.
+ * <p>
+ * The <code>PersistenceDelegate</code> is determined as following:
+ * <ol>
+ * <li>If a <code>PersistenceDelegate</code> has been registered by
+ * calling <code>setPersistenceDelegate</code> for the given type, it is
+ * returned.</li>
+ * <li>If the given type is an array class, a special
+ * <code>PersistenceDelegate</code> for array types is returned.</li>
+ * <li>If the given type is a proxy class, a special
+ * <code>PersistenceDelegate</code> for proxy classes is returned.</li>
+ * <li><code>Introspector</code> is used to check the bean descriptor
+ * value "persistenceDelegate". If one is set, it is returned.</li>
+ * <li>If none of the above applies, the
+ * <code>DefaultPersistenceDelegate</code> is returned.</li>
+ * </ol>
+ * </p>
+ *
+ * @param type
+ * a class type
+ * @return a <code>PersistenceDelegate</code> for the given class type
+ */
+ public PersistenceDelegate getPersistenceDelegate(Class<?> type) {
+ if (type == null) {
+ return nullPD; // may be return a special PD?
+ }
+
+ // registered delegate
+ PersistenceDelegate registeredPD = (PersistenceDelegate) delegates
+ .get(type);
+ if (registeredPD != null) {
+ return registeredPD;
+ }
+
+ if (Collection.class.isAssignableFrom(type)) {
+ return new UtilCollectionPersistenceDelegate();
+ }
+
+ if (type.isArray()) {
+ return arrayPD;
+ }
+ if (Proxy.isProxyClass(type)) {
+ return proxyPD;
+ }
+
+ // check "persistenceDelegate" property
+ try {
+ BeanInfo binfo = Introspector.getBeanInfo(type);
+ if (binfo != null) {
+ PersistenceDelegate pd = (PersistenceDelegate) binfo
+ .getBeanDescriptor().getValue("persistenceDelegate"); //$NON-NLS-1$
+ if (pd != null) {
+ return pd;
+ }
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+
+ // default persistence delegate
+ return defaultPD;
+ }
+
+ private void put(Object old, Object nu) {
+ oldNewMap.put(old, nu);
+ }
+
+ /**
+ * Remvoe the existing new copy of the given old object.
+ *
+ * @param old
+ * an old object
+ * @return the removed new version of the old object, or null if there is
+ * not one
+ */
+ public Object remove(Object old) {
+ return oldNewMap.remove(old);
+ }
+
+ /**
+ * Sets the exception listener of this encoder.
+ *
+ * @param listener
+ * the exception listener to set
+ */
+ public void setExceptionListener(ExceptionListener listener) {
+ if (listener == null) {
+ listener = defaultExListener;
+ }
+ this.listener = listener;
+ }
+
+ /**
+ * Register the <code>PersistenceDelegate</code> of the specified type.
+ *
+ * @param type
+ * @param delegate
+ */
+ public void setPersistenceDelegate(Class<?> type, PersistenceDelegate delegate) {
+ if (type == null || delegate == null) {
+ throw new NullPointerException();
+ }
+ delegates.put(type, delegate);
+ }
+
+ private Object forceNew(Object old) {
+ if (old == null) {
+ return null;
+ }
+ Object nu = get(old);
+ if (nu != null) {
+ return nu;
+ }
+ writeObject(old);
+ return get(old);
+ }
+
+ private Object[] forceNewArray(Object oldArray[]) {
+ if (oldArray == null) {
+ return null;
+ }
+ Object newArray[] = new Object[oldArray.length];
+ for (int i = 0; i < oldArray.length; i++) {
+ newArray[i] = forceNew(oldArray[i]);
+ }
+ return newArray;
+ }
+
+ /**
+ * Write an expression of old objects.
+ * <p>
+ * The implementation first check the return value of the expression. If
+ * there exists a new version of the object, simply return.
+ * </p>
+ * <p>
+ * A new expression is created using the new versions of the target and the
+ * arguments. If any of the old objects do not have its new version yet,
+ * <code>writeObject()</code> is called to create the new version.
+ * </p>
+ * <p>
+ * The new expression is then executed to obtained a new copy of the old
+ * return value.
+ * </p>
+ * <p>
+ * Call <code>writeObject()</code> with the old return value, so that more
+ * statements will be executed on its new version to change it into the same
+ * state as the old value.
+ * </p>
+ *
+ * @param oldExp
+ * the expression to write. The target, arguments, and return
+ * value of the expression are all old objects.
+ */
+ public void writeExpression(Expression oldExp) {
+ if (oldExp == null) {
+ throw new NullPointerException();
+ }
+ try {
+ // if oldValue exists, noop
+ Object oldValue = oldExp.getValue();
+ if (oldValue == null || get(oldValue) != null) {
+ return;
+ }
+
+ // copy to newExp
+ Object newTarget = forceNew(oldExp.getTarget());
+ Object newArgs[] = forceNewArray(oldExp.getArguments());
+ Expression newExp = new Expression(newTarget, oldExp
+ .getMethodName(), newArgs);
+
+ // execute newExp
+ Object newValue = null;
+ try {
+ newValue = newExp.getValue();
+ } catch (IndexOutOfBoundsException ex) {
+ // Current Container does not have any component, newVal set
+ // to null
+ }
+
+ // relate oldValue to newValue
+ put(oldValue, newValue);
+
+ // force same state
+ writeObject(oldValue);
+ } catch (Exception e) {
+ listener.exceptionThrown(new Exception(
+ "failed to write expression: " + oldExp, e)); //$NON-NLS-1$
+ }
+ }
+
+ /**
+ * Encode the given object into a series of statements and expressions.
+ * <p>
+ * The implementation simply finds the <code>PersistenceDelegate</code>
+ * responsible for the object's class, and delegate the call to it.
+ * </p>
+ *
+ * @param o
+ * the object to encode
+ */
+ protected void writeObject(Object o) {
+ if (o == null) {
+ return;
+ }
+ Class type = o.getClass();
+ getPersistenceDelegate(type).writeObject(o, this);
+ }
+
+ /**
+ * Write a statement of old objects.
+ * <p>
+ * A new statement is created by using the new versions of the target and
+ * arguments. If any of the objects do not have its new copy yet,
+ * <code>writeObject()</code> is called to create one.
+ * </p>
+ * <p>
+ * The new statement is then executed to change the state of the new object.
+ * </p>
+ *
+ * @param oldStat
+ * a statement of old objects
+ */
+ public void writeStatement(Statement oldStat) {
+ if (oldStat == null) {
+ throw new NullPointerException();
+ }
+ try {
+ // copy to newStat
+ Object newTarget = forceNew(oldStat.getTarget());
+ Object newArgs[] = forceNewArray(oldStat.getArguments());
+ Statement newStat = new Statement(newTarget, oldStat
+ .getMethodName(), newArgs);
+
+ // execute newStat
+ newStat.execute();
+ } catch (Exception e) {
+ listener.exceptionThrown(new Exception(
+ "failed to write statement: " + oldStat, e)); //$NON-NLS-1$
+ }
+ }
- private void put(Object old, Object nu) {
- oldNewMap.put(old, nu);
- }
-
- public void writeExpression(Expression oldExp) {
- if (oldExp == null) {
- throw new NullPointerException();
- }
- try {
- Object oldValue = oldExp.getValue();
- if (oldValue == null || get(oldValue) != null) {
- return;
- }
-
- // copy to newExp
- Object newTarget = forceNew(oldExp.getTarget());
- Object newArgs[] = forceNewArray(oldExp.getArguments());
- Expression newExp = new Expression(newTarget, oldExp
- .getMethodName(), newArgs);
-
- // execute newExp
- Object newValue = null;
- try {
- newValue = newExp.getValue();
- } catch (IndexOutOfBoundsException ex) {
- // Current Container does not have any component, newVal set
- // to null
- }
-
- // relate oldValue to newValue
- put(oldValue, newValue);
-
- // force same state
- writeObject(oldValue);
- } catch (Exception e) {
- // TODO - remove written args
- getExceptionListener().exceptionThrown(e);
- }
- }
-
- public void setExceptionListener(ExceptionListener exceptionListener) {
- if (exceptionListener == null) {
- exceptionListener = defaultExListener;
- }
- this.exceptionListener = exceptionListener;
- }
-
- public ExceptionListener getExceptionListener() {
- return exceptionListener;
- }
-
- private Object write(Object oldInstance) throws Exception {
- if (oldInstance == null) {
- return null;
- }
-
- ObjectNode node = nodes.get(oldInstance);
-
- if (node == null) {
- doWriteObject(oldInstance);
- node = nodes.get(oldInstance);
- } else {
- node.addReference();
- }
-
- return node.getObjectValue();
- }
-
- Object[] write(Object[] oldInstances) throws Exception {
- if (oldInstances != null) {
- Object[] newInstances = new Object[oldInstances.length];
-
- for (int i = 0; i < oldInstances.length; ++i) {
- newInstances[i] = write(oldInstances[i]);
- }
- return newInstances;
- }
- return null;
- }
-
- /*
- * @param node node to return the value for @return tentative object value
- * for given node
- */
- private Object getValue(ObjectNode node) {
- if (node != null) {
- try {
- Object result = node.getObjectValue();
-
- return result;
- } catch (Exception e) {
- getExceptionListener().exceptionThrown(e);
- }
- }
- return null;
- }
-
- static boolean isNull(Class<?> type) {
- return type == null;
- }
-
- static boolean isPrimitive(Class<?> type) {
- return type == Boolean.class || type == Byte.class
- || type == Character.class || type == Double.class
- || type == Float.class || type == Integer.class
- || type == Long.class || type == Short.class;
- }
-
- static boolean isString(Class<?> type) {
- return type == String.class;
-
- }
-
- static boolean isClass(Class<?> type) {
- return type == Class.class;
- }
-
- static boolean isArray(Class<?> type) {
- return type.isArray();
- }
-
- static String getPrimitiveName(Class<?> type) {
- String result = null;
-
- if (type == Boolean.class) {
- result = "boolean"; //$NON-NLS-1$
- } else if (type == Byte.class) {
- result = "byte"; //$NON-NLS-1$
- } else if (type == Character.class) {
- result = "char"; //$NON-NLS-1$
- } else if (type == Double.class) {
- result = "double"; //$NON-NLS-1$
- } else if (type == Float.class) {
- result = "float"; //$NON-NLS-1$
- } else if (type == Integer.class) {
- result = "int"; //$NON-NLS-1$
- } else if (type == Long.class) {
- result = "long"; //$NON-NLS-1$
- } else if (type == Short.class) {
- result = "short"; //$NON-NLS-1$
- } else if (type == String.class) {
- result = "string"; //$NON-NLS-1$
- } else if (type == Class.class) {
- result = "class"; //$NON-NLS-1$
- }
-
- return result;
- }
}
+
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/IndexedPropertyDescriptor.java Tue Jul 17 21:05:08 2007
@@ -18,210 +18,365 @@
package java.beans;
import java.lang.reflect.Method;
-import java.lang.reflect.Modifier;
+
+import org.apache.harmony.beans.BeansUtils;
import org.apache.harmony.beans.internal.nls.Messages;
public class IndexedPropertyDescriptor extends PropertyDescriptor {
+
+ private Class indexedPropertyType;
+
private Method indexedGetter;
private Method indexedSetter;
+ /**
+ * Constructs a new instance of <code>IndexedPropertyDescriptor</code>.
+ *
+ * @param propertyName
+ * the specified indexed property's name.
+ * @param beanClass
+ * the bean class
+ * @param getterName
+ * the name of the array getter
+ * @param setterName
+ * the name of the array setter
+ * @param indexedGetterName
+ * the name of the indexed getter.
+ * @param indexedSetterName
+ * the name of the indexed setter.
+ * @throws IntrospectionException
+ */
public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass,
String getterName, String setterName, String indexedGetterName,
String indexedSetterName) throws IntrospectionException {
super(propertyName, beanClass, getterName, setterName);
+ setIndexedByName(beanClass, indexedGetterName, indexedSetterName);
+ }
- // RI behaves like this
- if (indexedGetterName == null && indexedSetterName == null &&
- (getterName != null || setterName != null)) {
- throw new IntrospectionException(Messages.getString("beans.50"));
+ private void setIndexedByName(Class beanClass, String indexedGetterName,
+ String indexedSetterName) throws IntrospectionException {
+
+ if (indexedGetterName == null) {
+ if (indexedSetterName != null) {
+ setIndexedWriteMethod(beanClass, indexedSetterName);
+ }
+ } else {
+ if (indexedGetterName.length() == 0) {
+ indexedGetterName = "get" + name;
+ }
+ setIndexedReadMethod(beanClass, indexedGetterName);
+ if (indexedSetterName != null) {
+ setIndexedWriteMethod(beanClass, indexedSetterName,
+ indexedPropertyType);
+ }
}
- setIndexedReadMethod(beanClass, indexedGetterName);
- setIndexedWriteMethod(beanClass, indexedSetterName);
- }
- public IndexedPropertyDescriptor(String propertyName, Method getter, Method setter,
- Method indexedGetter, Method indexedSetter) throws IntrospectionException {
- super(propertyName, getter, setter);
-
- // we need this in order to be compatible with RI
- if (indexedGetter == null && indexedSetter == null &&
- (getter != null || setter != null)) {
- throw new IntrospectionException(Messages.getString("beans.50"));
+ if (!isCompatible()) {
+ // beans.57=Property type is incompatible with the indexed property type
+ throw new IntrospectionException(Messages.getString("beans.57")); //$NON-NLS-1$
}
- setIndexedReadMethod(indexedGetter);
- setIndexedWriteMethod(indexedSetter);
}
- public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
- throws IntrospectionException {
- super(propertyName, beanClass, null, null);
- String getterName;
- String setterName;
- String indexedGetterName;
- String indexedSetterName;
-
- // array getter
- getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
- if (hasMethod(beanClass, getterName)) {
- setReadMethod(beanClass, getterName);
- }
- // array setter
- setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
- if (hasMethod(beanClass, setterName)) {
- setWriteMethod(beanClass, setterName);
- }
- // indexed getter
- indexedGetterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
- if (hasMethod(beanClass, indexedGetterName)) {
- setIndexedReadMethod(beanClass, indexedGetterName);
- }
- // indexed setter
- indexedSetterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
- if (hasMethod(beanClass, indexedSetterName)) {
- setIndexedWriteMethod(beanClass, indexedSetterName);
+ private boolean isCompatible() {
+ Class propertyType = getPropertyType();
+
+ if (propertyType == null) {
+ return true;
}
- // RI seems to behave a bit differently
- if (indexedGetter == null && indexedSetter == null &&
- getReadMethod() == null && getWriteMethod() == null) {
- throw new IntrospectionException(
- Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
+ Class componentTypeOfProperty = propertyType.getComponentType();
+ if (componentTypeOfProperty == null) {
+ return false;
}
- if (indexedGetter == null && indexedSetter == null) {
- // not an indexed property indeed
- throw new IntrospectionException(Messages.getString("beans.50"));
+ if (indexedPropertyType == null) {
+ return false;
}
+
+ return componentTypeOfProperty.getName().equals(
+ indexedPropertyType.getName());
}
- public void setIndexedReadMethod(Method indexedGetter) throws IntrospectionException {
+ /**
+ * Constructs a new instance of <code>IndexedPropertyDescriptor</code>.
+ *
+ * @param propertyName
+ * the specified indexed property's name.
+ * @param getter
+ * the array getter
+ * @param setter
+ * the array setter
+ * @param indexedGetter
+ * the indexed getter
+ * @param indexedSetter
+ * the indexed setter
+ * @throws IntrospectionException
+ */
+ public IndexedPropertyDescriptor(String propertyName, Method getter,
+ Method setter, Method indexedGetter, Method indexedSetter)
+ throws IntrospectionException {
+ super(propertyName, getter, setter);
if (indexedGetter != null) {
- int modifiers = indexedGetter.getModifiers();
- Class<?>[] parameterTypes;
- Class<?> returnType;
- Class<?> indexedPropertyType;
-
- if (!Modifier.isPublic(modifiers)) {
- throw new IntrospectionException(Messages.getString("beans.21")); //$NON-NLS-1$
- }
- parameterTypes = indexedGetter.getParameterTypes();
- if (parameterTypes.length != 1) {
- throw new IntrospectionException(Messages.getString("beans.22")); //$NON-NLS-1$
- }
- if (!parameterTypes[0].equals(int.class)) {
- throw new IntrospectionException(Messages.getString("beans.23")); //$NON-NLS-1$
- }
- returnType = indexedGetter.getReturnType();
- indexedPropertyType = getIndexedPropertyType();
- if ((indexedPropertyType != null) && !returnType.equals(indexedPropertyType)) {
- throw new IntrospectionException(Messages.getString("beans.24")); //$NON-NLS-1$
- }
+ internalSetIndexedReadMethod(indexedGetter);
+ internalSetIndexedWriteMethod(indexedSetter, true);
+ } else {
+ internalSetIndexedWriteMethod(indexedSetter, true);
+ internalSetIndexedReadMethod(indexedGetter);
}
- this.indexedGetter = indexedGetter;
- }
- public void setIndexedWriteMethod(Method indexedSetter) throws IntrospectionException {
- if (indexedSetter != null) {
- int modifiers = indexedSetter.getModifiers();
- Class<?>[] parameterTypes;
- Class<?> firstParameterType;
- Class<?> secondParameterType;
- Class<?> propType;
-
- if (!Modifier.isPublic(modifiers)) {
- throw new IntrospectionException(Messages.getString("beans.25")); //$NON-NLS-1$
- }
- parameterTypes = indexedSetter.getParameterTypes();
- if (parameterTypes.length != 2) {
- throw new IntrospectionException(Messages.getString("beans.26")); //$NON-NLS-1$
- }
- firstParameterType = parameterTypes[0];
- if (!firstParameterType.equals(int.class)) {
- throw new IntrospectionException(Messages.getString("beans.27")); //$NON-NLS-1$
- }
- secondParameterType = parameterTypes[1];
- propType = getIndexedPropertyType();
- if (propType != null && !secondParameterType.equals(propType)) {
- throw new IntrospectionException(Messages.getString("beans.28")); //$NON-NLS-1$
- }
+ if (!isCompatible()) {
+ // beans.57=Property type is incompatible with the indexed property type
+ throw new IntrospectionException(Messages.getString("beans.57")); //$NON-NLS-1$
}
- this.indexedSetter = indexedSetter;
}
+ /**
+ * Constructs a new instance of <code>IndexedPropertyDescriptor</code>.
+ *
+ * @param propertyName
+ * the specified indexed property's name.
+ * @param beanClass
+ * the bean class.
+ * @throws IntrospectionException
+ */
+ public IndexedPropertyDescriptor(String propertyName, Class<?> beanClass)
+ throws IntrospectionException {
+ super(propertyName, beanClass);
+ setIndexedByName(beanClass, "get" //$NON-NLS-1$
+ .concat(initialUpperCase(propertyName)), "set" //$NON-NLS-1$
+ .concat(initialUpperCase(propertyName)));
+ }
+
+ /**
+ * Sets the indexed getter as the specified method.
+ *
+ * @param indexedGetter
+ * the specified indexed getter.
+ * @throws IntrospectionException
+ */
+ public void setIndexedReadMethod(Method indexedGetter)
+ throws IntrospectionException {
+ this.internalSetIndexedReadMethod(indexedGetter);
+ }
+
+ /**
+ * Sets the indexed setter as the specified method.
+ *
+ * @param indexedSetter
+ * the specified indexed setter.
+ * @throws IntrospectionException
+ */
+ public void setIndexedWriteMethod(Method indexedSetter)
+ throws IntrospectionException {
+ this.internalSetIndexedWriteMethod(indexedSetter, false);
+ }
+
+ /**
+ * Obtains the indexed setter.
+ *
+ * @return the indexed setter.
+ */
public Method getIndexedWriteMethod() {
return indexedSetter;
}
+ /**
+ * Obtains the indexed getter.
+ *
+ * @return the indexed getter.
+ */
public Method getIndexedReadMethod() {
return indexedGetter;
}
+ /**
+ * Determines if this <code>IndexedPropertyDescriptor</code> is equal to
+ * the specified object. Two <code>IndexedPropertyDescriptor</code> s are
+ * equal if the reader, indexed reader, writer, indexed writer, property
+ * types, indexed property type, property editor and flags are equal.
+ *
+ * @param obj
+ * @return true if this indexed property descriptor is equal to the
+ * specified object.
+ */
@Override
public boolean equals(Object obj) {
- boolean result = super.equals(obj);
-
- if (result) {
- IndexedPropertyDescriptor pd = (IndexedPropertyDescriptor) obj;
-
- if (indexedGetter != null) {
- result = indexedGetter.equals(pd.getIndexedReadMethod());
- } else if (result && indexedGetter == null) {
- result = pd.getIndexedReadMethod() == null;
- }
-
- if (result) {
- if (indexedSetter != null) {
- result = indexedSetter.equals(pd.getIndexedWriteMethod());
- } else if (indexedSetter == null) {
- result = pd.getIndexedWriteMethod() == null;
- }
- }
+ if (!(obj instanceof IndexedPropertyDescriptor)) {
+ return false;
}
-
- return result;
+
+ IndexedPropertyDescriptor other = (IndexedPropertyDescriptor) obj;
+
+ return (super.equals(other)
+ && (indexedPropertyType == null ? other.indexedPropertyType == null
+ : indexedPropertyType.equals(other.indexedPropertyType))
+ && (indexedGetter == null ? other.indexedGetter == null
+ : indexedGetter.equals(other.indexedGetter)) && (indexedSetter == null ? other.indexedSetter == null
+ : indexedSetter.equals(other.indexedSetter)));
}
- public Class<?> getIndexedPropertyType() {
- Class<?> result = null;
+ /**
+ * HashCode of the IndexedPropertyDescriptor
+ */
+ @Override
+ public int hashCode() {
+ return super.hashCode() + BeansUtils.getHashCode(indexedPropertyType)
+ + BeansUtils.getHashCode(indexedGetter)
+ + BeansUtils.getHashCode(indexedSetter);
+ }
- if (indexedGetter != null) {
- result = indexedGetter.getReturnType();
- } else if (indexedSetter != null) {
- Class<?>[] parameterTypes = indexedSetter.getParameterTypes();
+ /**
+ * Obtains the Class object of the indexed property type.
+ *
+ * @return the Class object of the indexed property type.
+ */
+ public Class<?> getIndexedPropertyType() {
+ return indexedPropertyType;
+ }
- result = parameterTypes[1];
+ private void setIndexedReadMethod(Class beanClass, String indexedGetterName)
+ throws IntrospectionException {
+ Method getter;
+ try {
+ getter = beanClass.getMethod(indexedGetterName,
+ new Class[] { Integer.TYPE });
+ } catch (NoSuchMethodException exception) {
+ // beans.58=No such indexed read method
+ throw new IntrospectionException(Messages.getString("beans.58")); //$NON-NLS-1$
+ } catch (SecurityException exception) {
+ // beans.59=Security violation accessing indexed read method
+ throw new IntrospectionException(Messages.getString("beans.59")); //$NON-NLS-1$
}
- return result;
+ internalSetIndexedReadMethod(getter);
}
- private void setIndexedReadMethod(Class<?> beanClass, String indexedGetterName) {
- Method[] getters = findMethods(beanClass, indexedGetterName);
- boolean result = false;
+ private void internalSetIndexedReadMethod(Method indexedGetter)
+ throws IntrospectionException {
+ // Clearing the indexed read method.
+ if (indexedGetter == null) {
+ if (indexedSetter == null) {
+ if (getPropertyType() != null) {
+ // beans.5A=Indexed method is not compatible with non indexed method
+ throw new IntrospectionException(Messages
+ .getString("beans.5A"));
+ }
+ indexedPropertyType = null;
+ }
+ this.indexedGetter = null;
+ return;
+ }
+ // Validate the indexed getter.
+ if ((indexedGetter.getParameterTypes().length != 1)
+ || (indexedGetter.getParameterTypes()[0] != Integer.TYPE)) {
+ // beans.5B=Indexed read method must take a single int argument
+ throw new IntrospectionException(Messages.getString("beans.5B")); //$NON-NLS-1$
+ }
+ Class indexedReadType = indexedGetter.getReturnType();
+ if (indexedReadType == Void.TYPE) {
+ // beans.5B=Indexed read method must take a single int argument
+ throw new IntrospectionException(Messages.getString("beans.5B")); //$NON-NLS-1$
+ } else if (indexedSetter != null
+ && indexedGetter.getReturnType() != indexedSetter
+ .getParameterTypes()[1]) {
+ // beans.5A=Indexed read method is not compatible with indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5A")); //$NON-NLS-1$
+ }
+
+ // Set the indexed property type if not already set, confirm validity if
+ // it is.
+ if (this.indexedGetter == null) {
+ indexedPropertyType = indexedReadType;
+ } else {
+ if (indexedPropertyType != indexedReadType) {
+ // beans.5A=Indexed read method is not compatible with indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5A")); //$NON-NLS-1$
+ }
+ }
- for (Method element : getters) {
- try {
- setIndexedReadMethod(element);
- result = true;
- } catch (IntrospectionException ie) {}
+ // Set the indexed getter
+ this.indexedGetter = indexedGetter;
+ }
- if (result) {
- break;
- }
+ private void setIndexedWriteMethod(Class beanClass, String indexedSetterName)
+ throws IntrospectionException {
+ Method setter = null;
+ try {
+ setter = beanClass.getMethod(indexedSetterName, new Class[] {
+ Integer.TYPE, getPropertyType().getComponentType() });
+ } catch (SecurityException e) {
+ // beans.5C=Security violation accessing indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5C")); //$NON-NLS-1$
+ } catch (NoSuchMethodException e) {
+ // beans.5D=No such indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5D")); //$NON-NLS-1$
}
+ internalSetIndexedWriteMethod(setter, true);
}
- private void setIndexedWriteMethod(Class<?> beanClass, String indexedSetterName) {
- Method[] setters = findMethods(beanClass, indexedSetterName);
- boolean result = false;
+ private void setIndexedWriteMethod(Class beanClass,
+ String indexedSetterName, Class argType)
+ throws IntrospectionException {
+ try {
+ Method setter = beanClass.getMethod(indexedSetterName, new Class[] {
+ Integer.TYPE, argType });
+ internalSetIndexedWriteMethod(setter, true);
+ } catch (NoSuchMethodException exception) {
+ // beans.5D=No such indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5D")); //$NON-NLS-1$
+ } catch (SecurityException exception) {
+ // beans.5C=Security violation accessing indexed write method
+ throw new IntrospectionException(Messages.getString("beans.5C")); //$NON-NLS-1$
+ }
+ }
- for (Method element : setters) {
- try {
- setIndexedWriteMethod(element);
- result = true;
- } catch (IntrospectionException ie) {}
+ private void internalSetIndexedWriteMethod(Method indexedSetter,
+ boolean initialize) throws IntrospectionException {
+ // Clearing the indexed write method.
+ if (indexedSetter == null) {
+ if (indexedGetter == null) {
+ if (getPropertyType() != null) {
+ // beans.5E=Indexed method is not compatible with non indexed method
+ throw new IntrospectionException(Messages
+ .getString("beans.5E"));
+ }
+ indexedPropertyType = null;
+ }
+ this.indexedSetter = null;
+ return;
+ }
- if (result) {
- break;
+ // Validate the indexed write method.
+ Class[] indexedSetterArgs = indexedSetter.getParameterTypes();
+ if (indexedSetterArgs.length != 2) {
+ // beans.5F=Indexed write method must take two arguments
+ throw new IntrospectionException(Messages.getString("beans.5F")); //$NON-NLS-1$
+ }
+ if (indexedSetterArgs[0] != Integer.TYPE) {
+ // beans.60=Indexed write method must take an int as its first argument
+ throw new IntrospectionException(Messages.getString("beans.60")); //$NON-NLS-1$
+ }
+
+ // Set the indexed property type if not already set, confirm validity if
+ // it is.
+ Class indexedWriteType = indexedSetterArgs[1];
+ if (initialize && indexedGetter == null) {
+ indexedPropertyType = indexedWriteType;
+ } else {
+ if (indexedPropertyType != indexedWriteType) {
+ // beans.61=Indexed write method is not compatible with indexed read method
+ throw new IntrospectionException(Messages.getString("beans.61")); //$NON-NLS-1$
}
}
+
+ // Set the indexed write method.
+ this.indexedSetter = indexedSetter;
+ }
+
+ private static String initialUpperCase(String string) {
+ if (Character.isUpperCase(string.charAt(0))) {
+ return string;
+ }
+
+ String initial = string.substring(0, 1).toUpperCase();
+ return initial.concat(string.substring(1));
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java?view=diff&rev=557139&r1=557138&r2=557139
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyDescriptor.java Tue Jul 17 21:05:08 2007
@@ -20,7 +20,6 @@
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
-import java.util.Vector;
import org.apache.harmony.beans.BeansUtils;
import org.apache.harmony.beans.internal.nls.Messages;
@@ -47,20 +46,22 @@
}
this.setName(propertyName);
this.setDisplayName(propertyName);
- if (setterName != null) {
- if (hasMethod(beanClass, setterName)) {
- setWriteMethod(beanClass, setterName);
- } else {
- throw new IntrospectionException(Messages.getString("beans.20")); //$NON-NLS-1$
- }
- }
if (getterName != null) {
- if (hasMethod(beanClass, getterName)) {
+ if(getterName.length() == 0){
+ throw new IntrospectionException("read or write method cannot be empty."); //$NON-NLS-1$
+ }
+ try{
setReadMethod(beanClass, getterName);
- } else {
- throw new IntrospectionException(Messages.getString("beans.1F")); //$NON-NLS-1$
+ }catch(IntrospectionException e){
+ setReadMethod(beanClass, createDefaultMethodName(propertyName, "get")); //$NON-NLS-1$
}
}
+ if (setterName != null) {
+ if(setterName.length() == 0){
+ throw new IntrospectionException("read or write method cannot be empty."); //$NON-NLS-1$
+ }
+ setWriteMethod(beanClass, setterName);
+ }
}
public PropertyDescriptor(String propertyName, Method getter, Method setter)
@@ -71,14 +72,12 @@
}
this.setName(propertyName);
this.setDisplayName(propertyName);
- setWriteMethod(setter);
setReadMethod(getter);
+ setWriteMethod(setter);
}
public PropertyDescriptor(String propertyName, Class<?> beanClass)
throws IntrospectionException {
- String getterName;
- String setterName;
if (beanClass == null) {
throw new IntrospectionException(Messages.getString("beans.03")); //$NON-NLS-1$
}
@@ -87,22 +86,13 @@
}
this.setName(propertyName);
this.setDisplayName(propertyName);
- getterName = createDefaultMethodName(propertyName, "is"); //$NON-NLS-1$
- if (hasMethod(beanClass, getterName)) {
- setReadMethod(beanClass, getterName);
- } else {
- getterName = createDefaultMethodName(propertyName, "get"); //$NON-NLS-1$
- if (hasMethod(beanClass, getterName)) {
- setReadMethod(beanClass, getterName);
- }
- }
- setterName = createDefaultMethodName(propertyName, "set"); //$NON-NLS-1$
- if (hasMethod(beanClass, setterName)) {
- setWriteMethod(beanClass, setterName);
- }
- if (getter == null && setter == null) {
- throw new IntrospectionException(Messages.getString("beans.01", propertyName)); //$NON-NLS-1$
+ try {
+ setReadMethod(beanClass, createDefaultMethodName(propertyName, "is")); //$NON-NLS-1$
+ } catch (Exception e) {
+ setReadMethod(beanClass, createDefaultMethodName(propertyName, "get")); //$NON-NLS-1$
}
+
+ setWriteMethod(beanClass, createDefaultMethodName(propertyName, "set")); //$NON-NLS-1$
}
public void setWriteMethod(Method setter) throws IntrospectionException {
@@ -156,7 +146,7 @@
@Override
public boolean equals(Object object) {
- boolean result = (object != null && object instanceof PropertyDescriptor);
+ boolean result = object instanceof PropertyDescriptor;
if (result) {
PropertyDescriptor pd = (PropertyDescriptor) object;
boolean gettersAreEqual = (this.getter == null) && (pd.getReadMethod() == null)
@@ -219,11 +209,6 @@
return bound;
}
- boolean hasMethod(Class<?> beanClass, String methodName) {
- Method[] methods = findMethods(beanClass, methodName);
- return (methods.length > 0);
- }
-
String createDefaultMethodName(String propertyName, String prefix) {
String result = null;
if (propertyName != null) {
@@ -234,50 +219,33 @@
return result;
}
- Method[] findMethods(Class<?> aClass, String methodName) {
- Method[] allMethods = aClass.getMethods();
- Vector<Method> matchedMethods = new Vector<Method>();
- Method[] result;
- for (Method method : allMethods) {
- if (method.getName().equals(methodName)) {
- matchedMethods.add(method);
- }
- }
- result = new Method[matchedMethods.size()];
- for (int j = 0; j < matchedMethods.size(); ++j) {
- result[j] = matchedMethods.elementAt(j);
- }
- return result;
- }
-
- void setReadMethod(Class<?> beanClass, String getterName) {
- boolean result = false;
- Method[] getters = findMethods(beanClass, getterName);
- for (Method element : getters) {
- try {
- setReadMethod(element);
- result = true;
- } catch (IntrospectionException ie) {
- }
- if (result) {
- break;
- }
+ void setReadMethod(Class<?> beanClass, String getterName) throws IntrospectionException {
+ try {
+ Method readMethod = beanClass.getMethod(getterName, new Class[]{});
+ setReadMethod(readMethod);
+ } catch (Exception e) {
+ throw new IntrospectionException(e.getLocalizedMessage());
}
}
void setWriteMethod(Class<?> beanClass, String setterName) throws IntrospectionException {
- boolean result = false;
- Method[] setters = findMethods(beanClass, setterName);
- for (Method element : setters) {
- try {
- setWriteMethod(element);
- result = true;
- } catch (IntrospectionException ie) {
- }
- if (result) {
- break;
+ Method writeMethod = null;
+ try {
+ if(getter != null){
+ writeMethod = beanClass.getMethod(setterName, new Class[]{getter.getReturnType()});
+ }else{
+ Method[] methods = beanClass.getMethods();
+ for (Method method : methods) {
+ if(method.getName().equals(setterName)){
+ writeMethod = method;
+ break;
+ }
+ }
}
+ } catch (Exception e) {
+ throw new IntrospectionException(e.getLocalizedMessage());
}
+ setWriteMethod(writeMethod);
}
public PropertyEditor createPropertyEditor(Object bean) {